frame_zy.java
来自「用JAVA平台做简单的资料出入面版」· Java 代码 · 共 86 行
JAVA
86 行
import java.awt.*;
class MyFrame extends Frame
{
Label lb1,lb2,lb3,lb4,lb5,lb6;
TextField tf1,tf2,tf3,tf4,tf5;
CheckboxGroup cbg;
Checkbox cb1,cb2;
GridBagLayout gb;
GridBagConstraints gbc;
public MyFrame(String s)
{
super(s);
gb=new GridBagLayout();
setLayout(gb);
gbc=new GridBagConstraints();
//实例化各组件
lb1=new Label("姓名:");
lb2=new Label("专业:");
lb3=new Label(" 毕业院校:");
lb4=new Label("电话:");
lb5=new Label("Email:");
lb6=new Label(" 性别:");
tf1=new TextField("",6);
tf2=new TextField("",6);
tf3=new TextField("");
tf4=new TextField("");
tf5=new TextField("");
cbg=new CheckboxGroup();
cb1=new Checkbox("男",cbg,false);
cb2=new Checkbox("女",cbg,true);
//添加文本框
gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(lb1,0,0,1,1);
gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(lb2,1,0,1,1);
gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(lb3,1,11,1,1);
gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(lb4,2,0,1,1);
gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(lb5,3,0,1,1);
gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(lb6,0,11,1,1);
gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(tf1,0,1,1,10);
gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(tf2,1,1,1,10);
gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(tf3,1,8,1,10);
gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(tf4,2,1,1,13);
gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(tf5,3,1,1,13);
//添加单选按钮
gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(cb1,0,12,1,1);
gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(cb2,0,13,1,1);
}
public void addComponent(Component c,int row,int col,int nrow,int ncol)
{
gbc.gridx=col;
gbc.gridy=row;
gbc.gridwidth=ncol;
gbc.gridheight=nrow;
gb.setConstraints(c,gbc);
add(c);
}
}
class Frame_zy
{
public static void main(String args[])
{
MyFrame myfr=new MyFrame("Frame");
myfr.setSize(400,300);
myfr.setBackground(Color.pink);
myfr.show();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?