Initial Commit

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

9
CustomJFrame/Main.java Normal file
View File

@ -0,0 +1,9 @@
package CustomJFrame;
public class Main {
public static void main(String[] args) {
MyJFrame myJFrame = new MyJFrame("My Custom JFrame Counter GUI");
myJFrame.setVisible(true);
}
}

View File

@ -0,0 +1,29 @@
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);
}
}

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);
}
}

29
SingleFile/Main.java Normal file
View File

@ -0,0 +1,29 @@
package SingleFile;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.FlowLayout;
public class Main {
private static int counter;
public static void main(String[] args) {
counter = 0;
JFrame jFrame = new JFrame("My Single File Counter GUI");
jFrame.setLayout(new FlowLayout(FlowLayout.CENTER));
jFrame.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!");
});
jFrame.add(button);
jFrame.setVisible(true);
}
}