Initial Commit

This commit is contained in:
2024-11-16 11:12:12 -05:00
commit 3902f7929e
5 changed files with 111 additions and 0 deletions

15
CustomJPanel/Main.java Normal file
View File

@@ -0,0 +1,15 @@
package CustomJPanel;
import javax.swing.JFrame;
public class Main {
public static void main(String[] args) {
JFrame jframe = new JFrame("My Custom JPanel Counter GUI");
jframe.setSize(300, 200);
jframe.add(new MyJPanel());
jframe.setVisible(true);
}
}

View File

@@ -0,0 +1,29 @@
package CustomJPanel;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
public class MyJPanel extends JPanel {
private int counter;
public MyJPanel() {
super();
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);
}
}