Java是單一繼承設計,也就是只能繼承extends一個物件,以此減少複雜度;但可以透過界面implements功能來擴充增加變化

Frame是視窗功能的類別、ActionListener是真側滑鼠行為的型別

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class mm extends Frame implements ActionListener{
    Button bt = null;
    Button bt2 = null;
    mm(){
        /*--Frame--*/
        this.setSize(600,500);
        this.setLocation(200,50);
        this.setVisible(true);
        this.setLayout(null);
/*Frame會將顯示於視窗的內容自動排列整理,但是不是很好使用,所已先關閉*/
        
        /*--Button"OK", Button Method--*/
        bt = new Button("click");
        bt.setSize(80,40);
        bt.setLocation(200,50);
        bt.setVisible(true);
        bt.addActionListener(this);/*interface*/
        
        /*--Button"OKK", Button Method--*/
        bt2 = new Button("click02");
        bt2.setSize(80,40);
        bt2.setLocation(400,50);
        bt2.setVisible(true);
        bt2.addActionListener(this);/*interface*/
        
        this.add(bt);
        this.add(bt2);
    }
    
    /*--main--*/
    public static void main(String[] arg){
        mm p = new mm();
    }

    
    /*ActionListen, Mouse Event*/
    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==bt){
            bt.setLabel("No.1");
        }else if(e.getSource()==bt2){
            bt2.setLabel("No.2");
        }    
    }

    
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Kuihao 的頭像
    Kuihao

    溫暖午後的金針田__孕育有趣的創新

    Kuihao 發表在 痞客邦 留言(0) 人氣()