|
書き直してみました。 import java.awt.Dimension; import java.awt.Frame; import java.awt.Button; import java.awt.TextField;
public class SampleFrame extends Frame { int x=0; private Button button = null; private Button button1 = null; private Button button2 = null; private Button button3 = null; private Button button4 = null; private Button button5 = null; private Button button6 = null; private Button button7 = null; private Button button8 = null; private TextField textField = null; public SampleFrame() { super(); initialize(); } private void initialize() { this.setLayout(null); this.setSize(500, 300); this.setTitle("Frame"); this.add(getButton(), null); this.add(getButton1(), null); this.add(getButton2(), null); this.add(getButton3(), null); this.add(getButton4(), null); this.add(getButton5(), null); this.add(getButton6(), null); this.add(getButton7(), null); this.add(getButton8(), null); this.add(getTextField(), null); this.add(button2, null); this.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.out.println("windowClosing()"); // TODO Auto-generated Event stub windowClosing() System.exit(0); } }); } /** * This method initializes button * * @return java.awt.Button */ private Button getButton() { if (button == null) { button = new Button(); button.setLocation(53, 49); button.setSize(50, 50); button.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() Dimension dim = button.getSize(); int dimW = dim.width; int dimH=dim.height; if(dimW==50 && dimH==50){ button.setSize(0,0); x++; } Dimension dim1 = button1.getSize(); if(dimW==50 && dimH==50){ button1.setSize(0,0); x++; } Dimension dim2 = button3.getSize(); if(dimW==50 && dimH==50){ button3.setSize(0,0); x++; } } }); } return button; } /** * This method initializes button1 * * @return java.awt.Button */ private Button getButton1() { if (button1 == null) { button1 = new Button(); button1.setLocation(102, 51); button1.setSize(50, 50); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() Dimension dim = button2.getSize(); int dimW = dim.width; int dimH=dim.height; if(dimW==50 && dimH==50){ button2.setSize(0,0); x++; } Dimension dim1 = button4.getSize(); if(dimW==50 && dimH==50){ button4.setSize(0,0); x++; } } }); } return button1; } /** * This method initializes button2 * * @return java.awt.Button */ private Button getButton2() { if (button2 == null) { button2 = new Button(); button2.setBounds(152, 51, 50, 50); button2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() Dimension dim = button2.getSize(); int dimW = dim.width; int dimH=dim.height; if(dimW==50 && dimH==50){ button2.setSize(0,0); x++; } Dimension dim1 = button4.getSize(); if(dimW==50 && dimH==50){ button4.setSize(0,0); x++; } } }); } return button1; } /** * This method initializes button3 * * @return java.awt.Button */ private Button getButton3() { if (button3 == null) { button3 = new Button(); button3.setLocation(53, 100); button3.setSize(50, 50); button3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() Dimension dim = button6.getSize(); int dimW = dim.width; int dimH=dim.height; if(dimW==50 && dimH==50){ button6.setSize(0,0); x++; } Dimension dim1 = button8.getSize(); if(dimW==50 && dimH==50){ button8.setSize(0,0); x++; } Dimension dim2 = button2.getSize(); if(dimW==50 && dimH==50){ button2.setSize(0,0); x++; } } }); } return button3; } /** * This method initializes button4 * * @return java.awt.Button */ private Button getButton4() { if (button4 == null) { button4 = new Button(); button4.setLocation(104, 100); button4.setSize(50, 50); button4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() Dimension dim = button2.getSize(); int dimW = dim.width; int dimH=dim.height; if(dimW==50 && dimH==50){ button2.setSize(0,0); x++; } Dimension dim1 = button3.getSize(); if(dimW==50 && dimH==50){ button3.setSize(0,0); x++; } Dimension dim2 = button2.getSize(); if(dimW==0 && dimH==0){ button2.setSize(50,50); x--; } } }); } return button4; } /** * This method initializes button5 * * @return java.awt.Button */
|