2012年2月29日 星期三

2012/03/01(四)

物件Object
類別Class
屬性property

事件event
行為behavior
方法method


VB
.hide隱藏
.show 顯示另一個表單
.printfrom1 印表機
Name不要改
Caption 改顯示名稱

---JAVA----

set title 改外框名稱

JButton mybutton = new JButton("SS");    創造一個按鈕
 mybutton.setSize(100, 100);                    設定按鈕大小


上帝 依照 他的 形象 造人

---程式碼---

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("JAVA程式-按鈕");    // 設定視窗標題
        JButton mybutton = new JButton("SS");
        mybutton.setSize(100, 100);
        JButton mybutton1 = new JButton("SS2");
        mybutton1.setSize(150, 150);
        JCheckBox mycheakbox = new JCheckBox("ss3");
        mycheakbox.setSize(200, 200);
        JRadioButton myJRadioButton = new JRadioButton("SS4");
        myJRadioButton.setSize(150, 150);
        // 通知按鈕物件:本物件要當傾聽者

        mybutton.addActionListener(this);
        //把按鈕加入到表單內
        getContentPane().add(mybutton);  
        getContentPane().add(mybutton1);
        getContentPane().add(mycheakbox);
        getContentPane().add(myJRadioButton);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(SizeW,SizeH);
        setVisible(true);

      }

      public void actionPerformed(ActionEvent e) {

          //SizeW = SizeW * 2;
          //SizeH = SizeH * 2;
          //setSize(SizeW,SizeH);

      }



}