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){ // JFrameを継承したクラスのインスタンスをつくる。 // つくっただけで、変数に入れていない。でも画面は表示される。 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(); } }