import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class JavaTest extends JFrame {
int i = 0, x = 10, y = 10;
JButton jb = new JButton("Test");
JButton jb2 = new JButton("Text ändern");
JLabel lbl = new JLabel("TEST" + i);
public JavaTest() {
super("test");
setSize(1024,768);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(null);
jb.setLocation(800, 600);
jb.setSize(80,20);
jb2.setLocation(800, 650);
jb2.setSize(80,20);
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
lbl = new JLabel("TEST" + i);
lbl.setSize(80,20);
lbl.setLocation(x,x);
getContentPane().add(lbl);
repaint();
x = x + 50;
i++;
}
});
jb2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
lbl.setText("geändert");
}
});
getContentPane().add(jb);
getContentPane().add(jb2);
setVisible(true);
}
public static void main(String[] args){
JavaTest jt = new JavaTest();
}
}