eclipseで
Java
1import java.awt.*; 2import java.awt.event.*; 3class Main { 4 public static void main(String[]args) { 5 6 } 7 8} 9class MyWindow2 extends Frame implements ActionListener { 10 Button btn1,btn2; 11 MyWindow2() { 12 setTitle("push button"); 13 setSize(600,400); 14 setLayout( new FlowLayout()); 15 btn1 = new Button("<<< button >>>"); 16 btn1.addActionListener(this); 17 add(btn1); 18 btn2 = new Button("<<< button2 >>>"); 19 btn2.addActionListener(this); 20 add(btn2); 21 setVisible(true); 22 addWindowListener( new WinListener()); 23 } 24 25 public void actionPerformed(ActionEvent e) { 26 27 if(e.getSource() == btn1) btn1.setLabel("ckick Button1"); 28 if(e.getSource() == btn2) btn2.setLabel("click Button2"); 29 } 30 31} 32 33class WinListener extends WindowAdapter { 34 public void windowClosing(WindowEvent e) {System.exit(0);} 35}
あなたの回答
tips
プレビュー