l1=new JLabel(\学号\l2=new JLabel(\姓名\l3=new JLabel(\性别\l4=new JLabel(\系别\t1=new JTextField(10); t2=new JTextField(10); r1=new JRadioButton(\男\r2=new JRadioButton(\女\
ButtonGroup sex=new ButtonGroup(); Object s[]={\英语系\水产系\com=new JComboBox(s); b1=new JButton(\添加\b2=new JButton(\显示\p11.add(l1); p11.add(t1); p12.add(l2); p12.add(t2); p13.add(l3); p13.add(r1); p13.add(r2); p14.add(l4);
9 / 14
p14.add(com); p15.add(b1); p15.add(b2);
p1.setLayout(new GridLayout(5,1)); p1.add(p11); p1.add(p12); p1.add(p13); p1.add(p14); p1.add(p15);
p11.setBackground(Color.yellow ); p12.setBackground(Color.yellow ); p13.setBackground(Color.yellow ); p14.setBackground(Color.yellow ); p15.setBackground(Color.yellow ); f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); r1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { sex1=r1.getText(); }});
r2.addActionListener(new ActionListener(){
10 / 14
public void actionPerformed(ActionEvent arg0) { // TODO自动生成方法存根 sex1=r2.getText(); }});
com.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { }});
b1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { // TODO自动生成方法存根
if(t1.getText().equals(\{a.setText(\姓名和学号不能为空\else {
String str=\学号\姓名\性别\系别\
sums+=str+\System.out.println(str); try {
fw = new (\fw.write(sums); fw.close();
11 / 14
} catch (IOException e) { // TODO自动生成catch 块 e.printStackTrace(); }
//两个写入都可以 /* ; try {
fos = new (\
PrintStream ps=new PrintStream(fos); ps.print(str); } catch ( e) {
// TODO自动生成catch 块 e.printStackTrace(); } */
a.setText(\} } });
b2.addActionListener(new ActionListener(){
12 / 14
相关推荐: