import javax.swing.*;
import java.awt.event.*; // 要處理事件必須 import 此套件
public class Exe extends JFrame
implements ActionListener {
/**
* @param args
*/
//int act = 0; // 用來記錄按鈕被次數的變數
int SizeW = 210;
int SizeH = 300;
public static void main(String[] args) {
Exe test = new Exe();
}
// 用建構方法來建立元件、將元件加入視窗、顯示視窗
public Exe() {
setTitle("guo shang ming"); // 設定視窗標題
JButton mybutton = new JButton("郭尚銘");
JButton mybutton1 = new JButton("1111");
JCheckBox mybutton2 = new JCheckBox("2222");
JRadioButton mybutton3 = new JRadioButton("3333");
mybutton.setSize(50, 50);
mybutton1.setSize(150, 150);
mybutton2.setSize(350, 350);
mybutton3.setSize(550, 550);
// 通知按鈕物件:本物件要當傾聽者
mybutton.addActionListener(this);
getContentPane().add(mybutton);
getContentPane().add(mybutton1);
getContentPane().add(mybutton2);
getContentPane().add(mybutton3);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(SizeW,SizeH);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
SizeW = SizeW * 2;
SizeH = SizeH * 2;
setSize(SizeW,SizeH);
}
}
沒有留言:
張貼留言