2012年3月1日 星期四

101/03/01


101/3/1
物件 object
實例 來自於類別
類別 class
屬性 property
事件 EVENT
行為 behavior
方法 method
上帝依照形象造人



import javax.swing.*;

import java.awt.event.*;  // 要處理事件必須 import 此套件
public class Exe extends JFrame
implements ActionListener {
    /**
     * @param args
     */
    //int act = 0;     // 用來記錄按鈕被次數的變數
    int SizeW = 500;
    int SizeH = 500;
      public static void main(String[] args) {
          Exe test = new Exe();
      }
      // 用建構方法來建立元件、將元件加入視窗、顯示視窗
      public Exe() {
        setTitle("許峻榮");    // 設定視窗標題
        //新增物件
        JButton mybutton = new JButton("變胖了");
        JButton mybutton1 = new JButton("變瘦了");
        JCheckBox abc_box = new JCheckBox("aaa");
        JRadioButton aaa = new JRadioButton("bbb");
//----         
        mybutton.setSize(100, 100);
        mybutton1.setSize(150, 150);
        abc_box.setSize(350, 350);
        aaa.setSize(150, 150);
        // 通知按鈕物件:本物件要當傾聽者
        mybutton.addActionListener(this);  
        getContentPane().add(mybutton);
        getContentPane().add(mybutton1);
        getContentPane().add(abc_box);
        getContentPane().add(aaa);         
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(SizeW,SizeH);
        setVisible(true);
      }
      public void actionPerformed(ActionEvent e) {
          SizeW = SizeW *2;
          SizeH = SizeH *2; 
          setSize(SizeW,SizeH);
      }
}

沒有留言:

張貼留言