Initial Commit
This commit is contained in:
commit
3902f7929e
9
CustomJFrame/Main.java
Normal file
9
CustomJFrame/Main.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
29
CustomJFrame/MyJFrame.java
Normal file
29
CustomJFrame/MyJFrame.java
Normal 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
15
CustomJPanel/Main.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
29
CustomJPanel/MyJPanel.java
Normal file
29
CustomJPanel/MyJPanel.java
Normal 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
29
SingleFile/Main.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user