当前位置: 代码迷 >> Java相关 >> java图形界面设计,错哪了,求指教
  详细解决方案

java图形界面设计,错哪了,求指教

热度:7918   发布时间:2013-02-25 21:46:22.0
java图形界面设计,哪里错了,求指教
我分别用了三个class,最后一个是作为处理图形用户界面的,调用界面设置的信息总是提示错误,这是为什么呢

球高手指教谢谢


package unit10;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;



public class frame {

public static void main(String[] args) {
people w=new people();

}
}

class people extends JFrame{

public Object text1;

people(){
setSize(400,350);
setLocation(100,100);
setResizable(false);

PoliceStation police;
JLabel label=new JLabel("用户信息填写",JLabel.CENTER);
label.setFont(new Font(null, Font.BOLD,35));
label.setForeground(Color.blue);
add(label,BorderLayout.NORTH);

JPanel pane1=new JPanel();
JPanel pane2=new JPanel();
JPanel pane3=new JPanel();
JPanel pane4=new JPanel();
JPanel pane5=new JPanel();
JPanel pane6=new JPanel();
JPanel pane7=new JPanel();
JPanel pane8=new JPanel();
JPanel pane9=new JPanel();

JLabel label1=new JLabel("姓名:");
JTextField text1=new JTextField(18);

JLabel label2=new JLabel("学号:");
JTextField text2=new JTextField(18);

JLabel label3=new JLabel("性别:");
JRadioButton button1=new JRadioButton("男");
JRadioButton button2=new JRadioButton("女");

JLabel label4=new JLabel("省份:");
JComboBox bobox=new JComboBox();
bobox.addItem("湖北");
bobox.addItem("河南");
bobox.addItem("重庆");
bobox.addItem("四川");
bobox.addItem("山东");

JLabel label5=new JLabel("爱好:");
JCheckBox box1=new JCheckBox("计算机");
JCheckBox box2=new JCheckBox("数学");
JCheckBox box3=new JCheckBox("英语");

JLabel label6=new JLabel("备注:");
JTextField text3=new JTextField(18);

pane1.add(label1);
pane1.add(text1);
pane2.add(label2);
pane2.add(text2);
pane3.add(label3);
pane3.add(button1);
pane3.add(button2);
pane4.add(label4);
pane4.add(bobox);
pane5.add(label5);
pane5.add(box1);
pane5.add(box2);
pane5.add(box3);
pane6.add(label6);
pane6.add(text3);

pane1.add(pane2);
pane1.add(pane3);
pane1.add(pane4);
pane1.add(pane5);
pane1.add(pane6);
add(pane1,BorderLayout.CENTER);

JButton button11=new JButton("保存");
JButton button12=new JButton("取消");
JButton button13=new JButton("退出");
pane7.add(button11);
pane8.add(button12);
pane9.add(button13);
pane7.add(pane8);
pane8.add(pane9);
add(pane7,BorderLayout.SOUTH);

police=new PoliceStation();
button11.addActionListener(police);
button12.addActionListener(police);
button13.addActionListener(police);
text1.addActionListener(police);

setVisible(true);
}
}



class PoliceStation implements ActionListener {

people p=new people();

public void actionPerformed(ActionEvent e){
String s=e.getActionCommand();

if(s.equals("保存")){

File file=new File("sudentmessage.txt");
String s1=p.label1.toString();
String s2=p.label2.toString();
  相关解决方案