commit 3902f7929e274caa7b97ceb9068da1a73b5043c1 Author: Bradley Bickford Date: Sat Nov 16 11:12:12 2024 -0500 Initial Commit diff --git a/CustomJFrame/Main.java b/CustomJFrame/Main.java new file mode 100644 index 0000000..2e53035 --- /dev/null +++ b/CustomJFrame/Main.java @@ -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); + } +} diff --git a/CustomJFrame/MyJFrame.java b/CustomJFrame/MyJFrame.java new file mode 100644 index 0000000..459e507 --- /dev/null +++ b/CustomJFrame/MyJFrame.java @@ -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); + } +} diff --git a/CustomJPanel/Main.java b/CustomJPanel/Main.java new file mode 100644 index 0000000..6df9607 --- /dev/null +++ b/CustomJPanel/Main.java @@ -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); + } +} diff --git a/CustomJPanel/MyJPanel.java b/CustomJPanel/MyJPanel.java new file mode 100644 index 0000000..544d107 --- /dev/null +++ b/CustomJPanel/MyJPanel.java @@ -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); + } +} diff --git a/SingleFile/Main.java b/SingleFile/Main.java new file mode 100644 index 0000000..9f22ed7 --- /dev/null +++ b/SingleFile/Main.java @@ -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); + } +} \ No newline at end of file