diff --git a/.vscode/launch.json b/.vscode/launch.json index ac0aa3c..45336c5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,6 +6,13 @@ "configurations": [ { "type": "java", + "name": "FirstGUI2026", + "request": "launch", + "mainClass": "FirstGUI2026", + "projectName": "ASD2024_84d436a2" + }, + { + "type": "java", "name": "Current File", "request": "launch", "mainClass": "${file}" diff --git a/FirstGUI.java b/FirstGUI.java index b643ae2..7db8b08 100644 --- a/FirstGUI.java +++ b/FirstGUI.java @@ -17,7 +17,7 @@ return new Dimension((int)(size.getWidth()*2), (int)(size.getHeight()*2) ); } public void paintComponent(java.awt.Graphics g) { - super.paintComponent(g); + // super.paintComponent(g); g.drawString("MyButton", 10, 10); g.drawLine(10, 10, 100, 100); } diff --git a/FirstGUI2026.java b/FirstGUI2026.java new file mode 100644 index 0000000..10bc380 --- /dev/null +++ b/FirstGUI2026.java @@ -0,0 +1,40 @@ +import java.awt.FlowLayout; + +import javax.swing.JButton; +import javax.swing.JFrame; + +public class FirstGUI2026 implements java.awt.event.ActionListener, Runnable { + JFrame frame; + JButton button2; + public FirstGUI2026() { + frame = new JFrame("First GUI 2026"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(400, 300); + frame.setVisible(true); + frame.setLayout(new FlowLayout()); + JButton button = new JButton("Click Me"); + button.addActionListener(this); + frame.getContentPane().add(button); + button2 = new MyButton("Java"); + button2.addActionListener(this); + frame.getContentPane().add(button2); + } + public void actionPerformed(java.awt.event.ActionEvent e) { + System.out.println(e.getActionCommand()+" button clicked!"); + frame.pack(); + // button2.setPreferredSize(new Dimension(200,100)); + } + + public static void main(String[] args) { + new FirstGUI2026(); + } +} + +// class MyButton extends JButton { +// public MyButton(String text) { +// super(text); +// } +// public Dimension getPreferredSize() { +// return new Dimension(200, 100); +// } +// }