62,623
社区成员
发帖
与我相关
我的任务
分享import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class PersonInfoRecorder extends JFrame implements ActionListener{
JLabel l1=new JLabel("姓名");
JLabel l2=new JLabel("性别");
JLabel l3=new JLabel("年龄");
JLabel l4=new JLabel("");
JTextField tf1=new JTextField(7);
JTextField tf2=new JTextField(7);
JTextArea ta=new JTextArea(80,30);
JButton b=new JButton("确定");
JComboBox cb=new JComboBox();
JPanel p=new JPanel();
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
PersonInfoRecorder(){
cb.addItem("男");
cb.addItem("女");
ta.setBackground(Color.cyan);
ta.setEditable(false);
p.setLayout(new BorderLayout());
p.add(p1,BorderLayout.NORTH);
p.add(p2,BorderLayout.CENTER);
p.add(p3,BorderLayout.SOUTH);
p1.add(l1);
p1.add(tf1);
p1.add(l2);
p1.add(cb);
p1.add(l3);
p1.add(tf2);
p1.add(b);
p2.add(ta);
p3.add(l4);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setContentPane(p);
this.setTitle("个人信息录入器");
this.setSize(400,200);
this.setVisible(true);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals(b))
{
if(tf1.getText().length()==0)
{
l4.setText("姓名不能为空!");
ta.setText("");
}
else
{
ta.setText(tf1.getText()+","+ cb.getSelectedItem() +","+tf2.getText());
l4.setText("");
}
}
}
public static void main(String[] args){
new PersonInfoRecorder();
}
}