import java.awt.*;
public class TestCom
{
public static void main(String[] args)
{
Frame f = new Frame();
f.setSize(400,400);
f.setBackground(Color.GREEN);
f.setVisible(true);
}
}
------------------------------------------------------------------------------------------------
import java.awt.*;
public class TestFrame{
public static void main(String[] args)
{
Frame f = new Frame("哈哈");
Button bn = new Button("戴地");//要显示按钮必须把按钮放在容器里
f.add(bn);
//f.setSize(200,200);//框大小
//f.setLocation(300,300);//位置
f.setBounds(50,300,200,200);//综合以上两种功能
f.setBackground(Color.RED);//背景颜色
f.setVisible(true);//显示窗口true
}
}
----------------------------------------------------------------------------------------------------
import java.awt.Frame;
public class TestFrame2
{
public static void main(String[] args)
{
Frame f = new Frame("侃侃");
f.setSize(200,200);
f.setVisible(true);//在距离显示器(0,0)的位置显示窗口
try
{
Thread.sleep(2000);
}
catch(InterruptedException e)
{
System.out.println(e.getMessage());
}
f.setLocation(200,200);//2秒后窗口在(200,200)的位置显示
try
{
Thread.sleep(2000);
}
catch(InterruptedException e)
{
System.out.println(e.getMessage());
}
f.setVisible(false);//窗口消失
}
}
-----------------------------------------------------------------------------------------------------------------------
import java.awt.*;
public class TestFrame3
{
public static void main(String[] args)
{
MyFrame f1 = new MyFrame(100,100,200,200,Color.BLUE);
MyFrame f2 = new MyFrame(300,100,200,200,Color.YELLOW);
MyFrame f3 = new MyFrame(100,300,200,200,Color.GREEN);
MyFrame f4 = new MyFrame(300,300,200,200,Color.MAGENTA);
}
}
class MyFrame extends Frame
{
public 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);
}
}
-------------------------------------------------------------------------------------------
import java.awt.*;
public class TestPanel
{
public static void main(String[] args)
{
Frame f = new Frame("java Frame with Panel");
Panel p = new Panel();//Panel类似于Frame,但Panel不能单独存在,必须放在一个容器中,即使Panel本身是一个容器
f.setLayout(null);
f.setBounds(300,300,500,500);
f.setBackground(new Color(100,100,102));
p.setBounds(300/2,300/2,500/2,500/2);
p.setBackground(new Color(204,204,255));
f.add(p);
f.setVisible(true);
}
}