/*
import java.awt.*;
public class cs extends Frame
{
Button myButton1,myButton2,myButton3,myButton4,myButton5;
public cs(String str)
{
super(str);
this.setLayout(null);
myButton2=new Button("Button2");
myButton1=new Button("Button1");
myButton3=new Button("Button3");
myButton4=new Button("Button4");
myButton5=new Button("Button5");
this.add(myButton1);
myButton1.setBounds(50,50,50,50);
this.add(myButton2);
myButton2.setBounds(50,100,50,50);
this.add(myButton3);
myButton3.setBounds(50,150,50,50);
this.add(myButton4);
myButton4.setBounds(50,200,50,50);
this.add(myButton5);
myButton5.setBounds(50,250,50,50);
this.setSize(500,500);
this.setVisible(true);
}
public static void main(String args[])
{
cs f=new cs("Button");
}
}
*/
import java.awt.Button;
import java.awt.Frame;
import java.awt.TextField;
import java.awt.Toolkit;
public class cs
{
public static void main(String[] args)
{
new MyFrame();
}
}
class MyFrame
{
private Frame fe;
private Button bn1;
private Button bn2;
private TextField td1;
private TextField td2;
public MyFrame()
{
init();
}
private void init()
{
//获得屏幕的宽和高
int screenwidth = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
int screenheight = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
//创建一个默认不可见的窗体,设置其属性
int width = 300;
int height = 200;
fe = new Frame("我的Java");
fe.setBounds((screenwidth-width)/2, (screenheight-height)/2, width, height);
fe.setLayout(null);
//创建两个按钮
bn1 = new Button();
bn2 = new Button();
fe.add(bn1);
fe.add(bn2);
bn1.setBounds(10, 10, 10, 10);
bn2.setBounds(10, 20, 10, 10);
//创建两个文本框
td1 = new TextField(10);
td2 = new TextField(10);
fe.add(td1);
fe.add(td2);
//使窗体显现出来
fe.setVisible(true);
}
}
|