2012年3月1日 星期四

重點整理

物件  object
類別  class
屬性  property
名詞  caption
事件  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 = 800;
int SizeH = 800;

 public static void main(String[] args) {
 Exe test = new Exe();
 }

 // 用建構方法來建立元件、將元件加入視窗、顯示視窗
 public Exe() {
   setTitle("9730053");    // 設定視窗標題
   JButton mybutton = new JButton("變大");
   JButton mybutton1 = new JButton("22");
   JCheckBox mycheckbox = new JCheckBox("多選");
   JRadioButton myradiobutton = new JRadioButton("單選");
 
   mybutton.setSize(100,100);
   mybutton1.setSize(200,200);
   mycheckbox.setSize(500,500);
   myradiobutton.setSize(800,800);
 
   // 通知按鈕物件:本物件要當傾聽者
   mybutton.addActionListener(this);
 
   getContentPane().add(mybutton);
   getContentPane().add(mybutton1);
   getContentPane().add(mycheckbox);
   getContentPane().add(myradiobutton);
 
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   setSize(SizeW,SizeH);
   setVisible(true);
 }

 public void actionPerformed(ActionEvent e) {
 SizeW = SizeW * 2;
 SizeH = SizeH * 2;
 setSize(SizeW,SizeH);
 }

}





沒有留言:

張貼留言