diff --git a/src/FirstGUI.java b/src/FirstGUI.java index 5461c24..3f27dd3 100644 --- a/src/FirstGUI.java +++ b/src/FirstGUI.java @@ -1,6 +1,4 @@ import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; - import javax.swing.JButton; import javax.swing.JFrame; @@ -30,6 +28,7 @@ System.out.println("Button [" + e.getActionCommand() + "] was pressed."); // new MyThread().start(); new Thread(this).start(); + FirstGUI.rootjf.setTitle("Button was pressed"); } public SelfActionJButton(String label){ super(label); @@ -51,6 +50,7 @@ public class FirstGUI /*implements ActionListener*/ { + public static JFrame rootjf; //アプリケーションのメインのウィンドウ public static void main(String[] args) { SelfActionJButton jb = new SelfActionJButton("ボタン"); // ActionListener( ); @@ -67,7 +67,7 @@ System.exit(0); } }); + rootjf = jf; } - } diff --git a/src/SecondGUI.java b/src/SecondGUI.java new file mode 100644 index 0000000..ab97bcb --- /dev/null +++ b/src/SecondGUI.java @@ -0,0 +1,53 @@ +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.BorderLayout; +import java.awt.Dimension; +public class SecondGUI extends JFrame { + public static JFrame rootjf; + public static void main(String[] args){ + new SecondGUI(); + } + public SecondGUI(){ + super("SecondGUI"); + setSize(300,200); + setVisible(true); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + JPanel northP = new JPanel(); + getContentPane().add(northP, BorderLayout.NORTH); + getContentPane().add(new JButton("CENTER") ); + northP.add(new ResizeButton("label", 200, 100)); + northP.add(new ResizeButton("label", 200, 100)); + pack(); + SecondGUI.rootjf = this; + } +} + +// interface ActionListener { +// public void actionPerformed(ActionEvent e); +// } + +class ResizeButton extends JButton implements ActionListener { + private int width, height; + ResizeButton(String label, int w, int h){ + super(label); + width = w; + height = h; + addActionListener(this); + } + public Dimension getPreferredSize(){ + return new Dimension(width, height); + } + + @Override + public void actionPerformed(ActionEvent e) { + width += 30; + height += 10; + SecondGUI.rootjf.pack(); + + } + +} \ No newline at end of file