30 lines
619 B
Java
30 lines
619 B
Java
package CustomJFrame;
|
|
|
|
import java.awt.FlowLayout;
|
|
|
|
import javax.swing.JButton;
|
|
import javax.swing.JFrame;
|
|
|
|
public class MyJFrame extends JFrame {
|
|
private int counter;
|
|
|
|
public MyJFrame(String title) {
|
|
super(title);
|
|
|
|
counter = 0;
|
|
|
|
this.setLayout(new FlowLayout(FlowLayout.CENTER));
|
|
this.setSize(300, 200);
|
|
|
|
JButton button = new JButton();
|
|
button.setText("Click Me!");
|
|
button.addActionListener((v) -> {
|
|
counter += 1;
|
|
|
|
button.setText("You've clicked the button " + counter + " times!");
|
|
});
|
|
|
|
this.add(button);
|
|
}
|
|
}
|