您的位置:首页 > 产品设计 > UI/UE

GUI Frame(一)

2015-11-26 22:44 399 查看
package TestFrame;

import java.awt.*;

import java.awt.event.*;

public class TestFrame {

public static void main(String[] args) {

// TODO Auto-generated method stub

boolean flag = false;

if(flag == true) {

MyFrame f1 = new MyFrame(100,100,200,200,Color.BLUE);

MyFrame f2 = new MyFrame(300,100,200,200,Color.BLUE);

MyFrame f3 = new MyFrame(100,300,200,200,Color.BLUE);

MyFrame f4 = new MyFrame(300,300,200,200,Color.BLUE);

Frame f = new Frame("Java Frame with Panel");

Panel p = new Panel(null);

f.setLayout(null);

f.setBounds(300,300,500,500); //相对于屏幕坐标

f.setBackground(new Color(0,0,102));

p.setBounds(50,50,400,400);//相对于frame坐标

p.setBackground(new Color(204,204,255));

f.add(p);

f.setVisible(true);

}

new MyFrame2("MyFrameWithPanel",300,300,400,300);

}

}

class MyFrame extends Frame {

static int id = 0;

MyFrame(int x,int y,int w,int h,Color color) {

super("MyFrame" + (++id));

setBackground(color);

setLayout(null);

setBounds(x,y,w,h);

setVisible(true);

}

}

class MyFrame2 extends Frame {

private Panel p1,p2,p3,p4;

MyFrame2(String s,int x,int y,int w,int h) {

super(s);

setLayout(null);

p1 = new Panel(null);

p2 = new Panel(null);

p3 = new Panel(null);

p4 = new Panel(null);

p1.setBounds(0,0,w/2,h/2);

p2.setBounds(0,h/2,w/2,h/2);

p3.setBounds(w/2,0,w/2,h/2);

p4.setBounds(w/2,h/2,w/2,h/2);

p1.setBackground(Color.BLUE);

p2.setBackground(Color.GREEN);

p3.setBackground(Color.YELLOW);

p4.setBackground(Color.MAGENTA);

add(p1);

add(p2);

add(p3);

add(p4);

setBounds(x,y,w,h);

setVisible(true);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: