2018年11月16日 星期五

[Java]_ch15.2_繼承並改寫視窗元件





[Java]_ch15.2_繼承並改寫視窗元件

package YPU;



import java.awt.Button;

import java.awt.Color;

import java.awt.Frame;

import java.awt.Label;



public class MyFrame extends Frame{

Label lb=new Label();

Button btn1=new Button("送出");

Button btn2=new Button("清除");



public MyFrame(String name){

super(name);

setLayout(null);

setBackground(Color.PINK);

setSize(300,300);

setLocation(800,300);

setVisible(true);



lb.setText("視窗元件設計");

lb.setBackground(Color.YELLOW);

lb.setSize(200, 50);

lb.setLocation(50, 50);



btn1.setSize(100, 50);

btn1.setLocation(50, 110);



btn2.setSize(100, 50);

btn2.setLocation(150, 110);



add(btn1);

add(btn2);

add(lb);

}

public MyFrame(String name,int w,int h,Color color){

super(name);

setLayout(null);

setBackground(color);

setSize(w,h);

setLocation(800,300);

setVisible(true);



lb.setText("視窗元件設計");

lb.setBackground(Color.YELLOW);

lb.setSize(200, 50);

lb.setLocation(50, 50);



btn1.setSize(100, 50);

btn1.setLocation(50, 110);



btn2.setSize(100, 50);

btn2.setLocation(150, 110);



add(btn1);

add(btn2);

add(lb);

}

}



沒有留言:

張貼留言

Ether.fi Cash Card 一張所有人必備的加密貨幣信用卡   [Ether.fi Cash Card] : https://www.ether.fi/app/cash/sign-up?ref_code=d27f8523 ------國際交易所------ [Bitg...