设计一个JFrame窗口,输入学生的基本信息,包括学号,姓名,学院,专业(下拉列表),班级,籍贯,
设计一个JFrame窗口,输入学生的基本信息,包括学号,姓名,学院,专业(下拉列表),班级,籍贯,性别(单选按钮),爱好(多选)等,在界面中包括提交和重填按钮,提交后弹出...
设计一个JFrame窗口,输入学生的基本信息,包括学号,姓名,学院,专业(下拉列表),班级,籍贯,性别(单选按钮),爱好(多选)等,在界面中包括提交和重填按钮,提交后弹出窗口显示学生信息,要求尽可能使用不同的swing组建
展开
3个回答
展开全部
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.*;
public class StudentInfomation extends JFrame {
JLabel xuehao=new JLabel("学号:");JTextField xue=new JTextField();
JLabel xingming=new JLabel("姓名:");JTextField xing=new JTextField();
JLabel xueyuan=new JLabel("学院:");JTextField yuan=new JTextField();
JLabel banji=new JLabel("班级:");JTextField ban=new JTextField();
JLabel jiguan=new JLabel("籍贯:"); JTextField ji=new JTextField();
JLabel zhuan=new JLabel("专业:");
String zy[]={"专业一","专业二","专业三"};
JComboBox<String> zhuanye=new JComboBox<String>(zy);
JLabel xin=new JLabel("性别:");
String[] xinbie={"男生","女生"};
JRadioButton nan=new JRadioButton(xinbie[0]);
JRadioButton nv=new JRadioButton(xinbie[1]);
ButtonGroup bg=new ButtonGroup();
JLabel ai=new JLabel("爱好:");
String[] aihao={"爱好一","爱好二","爱好三"};
JCheckBox aihao1=new JCheckBox(aihao[0]);
JCheckBox aihao2=new JCheckBox(aihao[1]);
JCheckBox aihao3=new JCheckBox(aihao[2]);
JButton tijiao=new JButton("提交");
JButton cong=new JButton("重填");
JPanel pan[]=new JPanel[9];
StudentInfomation(){
this.setTitle("学生基本信息");
this.setSize(400,450);
this.setVisible(true);
this.setLocation(200,100);
this.setResizable(false);
this.setLayout(new GridLayout(10,1));
Container con=this.getContentPane();
for(int i=0;i<9;i++){
pan[i]=new JPanel();
pan[i].setLayout(null);
con.add(pan[i]);
}
pan[0].add(xuehao);xuehao.setBounds(15,15,50,20);
pan[0].add(xue);xue.setBounds(80,15,120,20);
pan[1].add(xingming);xingming.setBounds(15,15,50,20);
pan[1].add(xing);xing.setBounds(80,15,120,20);
pan[2].add(xueyuan);xueyuan.setBounds(15,15,50,20);
pan[2].add(yuan);yuan.setBounds(80,15,120,20);
pan[3].add(banji);banji.setBounds(15,15,50,20);
pan[3].add(ban);ban.setBounds(80,15,120,20);
pan[4].add(jiguan);jiguan.setBounds(15,15,50,20);
pan[4].add(ji);ji.setBounds(80,15,120,20);
pan[5].add(zhuan);zhuan.setBounds(15,15,50,20);
pan[5].add(zhuanye);zhuanye.setBounds(80,15,120,20);
pan[6].add(xin);xin.setBounds(15,15,50,20);
pan[6].add(nan);nan.setBounds(80,15,80,20);
pan[6].add(nv);nv.setBounds(175,15,80,20);
bg.add(nan);bg.add(nv);
pan[7].add(ai);ai.setBounds(15,15,50,20);
pan[7].add(aihao1);aihao1.setBounds(80,15,80,20);
pan[7].add(aihao2);aihao2.setBounds(175,15,80,20);
pan[7].add(aihao3);aihao3.setBounds(270,15,80,20);
pan[8].add(tijiao);tijiao.setBounds(85,15,80,20);
pan[8].add(cong);cong.setBounds(215,15,80,20);
tijiao.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new ShowStudentInfomation();
}
});
cong.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
xue.setText("");
xing.setText("");
yuan.setText("");
ban.setText("");
ji.setText("");
zhuanye.setSelectedIndex(0);
bg.clearSelection();
aihao1.setSelected(false);
aihao2.setSelected(false);
aihao3.setSelected(false);
}
});
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(1);
}
});
}
class ShowStudentInfomation extends JFrame {
JTextArea info=new JTextArea();
ShowStudentInfomation(){
this.setTitle("学生基本信息");
this.setSize(250,200);
this.setVisible(true);
this.setLocation(200,100);
this.setResizable(false);
this.getContentPane().add(info,BorderLayout.CENTER);
info.setEditable(false);
info.setText("学号:"+xue.getText()+"\n姓名:"+xing.getText()+"\n学院:"+yuan.getText()+"\n班级:"+ban.getText()+"\n籍贯:"+ji.getText()
+"\n专业:" + zy[zhuanye.getSelectedIndex()]
+"\n性别:" + ( (nan.isSelected())?xinbie[0]:"" )
+ ( (nv.isSelected())?xinbie[1]:"" )
+"\n爱好:" + ( (aihao1.isSelected())?(aihao[0]+"\n"):"" )
+ ( (aihao2.isSelected())?(aihao[1]+"\n"):"" )
+ ( (aihao3.isSelected())?aihao[2]:"" ));
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
}
public static void main(String[] args) {
new StudentInfomation();
}
}
基本功能都实现了的
一些变量名和名词可以自己改一下
展开全部
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
class Test extends JFrame{
JPanel panel=new JPanel();
JTextField number;
JTextField name;
public static void main(String args[]) {
new Test();
}
public Test() {
setLayout(new FlowLayout(FlowLayout.LEFT));
JLabel label=new JLabel("学号");
label.setFont(new Font("宋体",Font.BOLD,18));
add(label);
number=new JTextField(10);
number.setText("2014214321");
add(number);
JLabel label2=new JLabel("姓名");
label2.setFont(new Font("宋体",Font.BOLD,18));
add(label2);
name=new JTextField(10);
name.setText("张三");
add(name);
JLabel label3=new JLabel("学院");
label3.setFont(new Font("宋体",Font.BOLD,18));
add(label3);
String college[]={"电子信息工程学院","机电学院","理学院","法学院"};
JList list=new JList(college);
list.setVisibleRowCount(1);
JScrollPane scroll=new JScrollPane(list);//列表添加到滚动条
add(scroll);
JLabel label4=new JLabel("专业");
label4.setFont(new Font("宋体",Font.BOLD,18));
add(label4);
String major[]={"计算机科学与技术","软件工程","计算机网络","光信息科学与技术"};
JComboBox combox=new JComboBox(major);
add(combox);
JLabel label5=new JLabel("性别");
label5.setFont(new Font("宋体",Font.BOLD,20));
add(label5);
JRadioButton man=new JRadioButton("男");
man.setFont(new Font("宋体",Font.BOLD,20));
JRadioButton woman=new JRadioButton("女");
woman.setFont(new Font("宋体",Font.BOLD,20));
ButtonGroup buttonGroup=new ButtonGroup();
buttonGroup.add(man); buttonGroup.add(woman);
add(man);add(woman);
JLabel label6=new JLabel("爱好");
label6.setFont(new Font("宋体",Font.BOLD,20));
add(label6);
String ball[]={"篮球","足球","羽毛球","乒乓球"};
JCheckBox checkBox[]=new JCheckBox[ball.length];
for(int i=0;i<checkBox.length;i++){
checkBox[i]=new JCheckBox(ball[i]);
checkBox[i].setFont(new Font("宋体",Font.BOLD,20));
checkBox[i].setForeground(Color.CYAN);
add(checkBox[i]);
}
JButton submits=new JButton("提交");
add(submits);
submits.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println(name.getText()+number.getText());
System.err.println("其它自己补充吧");
}
});
JButton reset=new JButton("重填");
add(reset);
setBounds(100, 100, 200, 300);
setTitle("学生信息管理");
setVisible(true);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询