📄 guiexample2.java
字号:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class guiexample2 extends Applet{
Button b1,b2,db;
TextField txt1;
Checkbox c1,c2,c3,c4,c5;
TextArea txt2;
List list1;
Choice choice1;
Label fl1=new Label("");
Label fl2=new Label("");
Label fl3=new Label("");
Label fl4=new Label("");
Label fl5=new Label("");
Label fl6=new Label("");
private Frame d=new Frame("注册结果");
public void init()
{ Label l1=new Label("姓名:");
add(l1);
txt1=new TextField(8);
add(txt1);
Label l2=new Label("性别 :");
add(l2);
CheckboxGroup group1= new CheckboxGroup();
c1=new Checkbox("男",group1, true);
add(c1);
c2=new Checkbox("女",group1, false);
add(c2);
Label l3=new Label("爱好 :");
add(l3);
c3=new Checkbox("文学");
add(c3);
c4=new Checkbox("音乐");
add(c4);
c5=new Checkbox("体育");
add(c5);
Label l4=new Label("简历 :");
add(l4);
txt2=new TextArea("");
txt2.setRows(10);
add(txt2);
Label l5=new Label("民族:");
add(l5);
list1=new List(3);
list1.add("汉");
list1.add("回");
list1.add("其他");
add(list1);
Label l6=new Label("政治面貌:");
add(l6);
choice1=new Choice();
choice1.addItem("团员");
choice1.addItem("党员");
choice1.addItem("其他");
add(choice1);
b1=new Button("确定");
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
processAction(e);}
} );
add(b1);
b2=new Button("取消");
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
processAction(e);}
} );
add(b2);
d.setLayout(new FlowLayout());
d.add(fl1);
d.add(fl2);
d.add(fl3);
d.add(fl4);
d.add(fl5);
d.add(fl6);
d.setSize(300,300);
db=new Button("确定");
db.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
d.dispose();}
} );
d.add(db);
}
public void processAction(ActionEvent e){
Object obj=e.getSource();
if(obj==b2)
{txt1.setText("");
txt2.setText("");}
if(obj==b1) {
String xingming=txt1.getText();
fl1.setText("姓名:"+xingming);
String jianli=txt2.getText();
fl4.setText("简历:"+jianli);
if(c1.getState()==true)
fl2.setText("性别:男");
else
fl2.setText("性别:女");
String aihao="爱好:";
if(c3.getState()==true)
aihao=aihao+"文学";
if(c4.getState()==true)
aihao=aihao+"音乐";
if(c5.getState()==true)
aihao=aihao+"体育";
fl3.setText(aihao);
String minzu="民族:";
if(list1.getSelectedIndex()==0)
minzu=minzu+"汉";
if(list1.getSelectedIndex()==1)
minzu=minzu+"回";
if(list1.getSelectedIndex()==2)
minzu=minzu+"其他";
fl5.setText(minzu);
String mianmao="政治面貌:";
if(choice1.getSelectedIndex()==0)
mianmao=mianmao+"团员";
if(choice1.getSelectedIndex()==1)
mianmao=mianmao+"党员";
if(choice1.getSelectedIndex()==2)
mianmao=mianmao+"其他";
fl6.setText(mianmao);
d.show();}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -