⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example_2.java

📁 采用JAVA界面,实现对学生信息的简单录入,用JTABLE来模拟数据库的输出格式.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package je;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import java.io.File;
import java.io.*;
import java.util.StringTokenizer;

//包括,学号、姓名、性别、年龄、家庭住址、电话

public class Example_2 extends JFrame implements ActionListener,TextListener,Serializable{
	//显示已录取的学生信息
	JLabel jlb;
	JTable table;
	Object jname[]={"学号","姓名","性别","年龄","家庭住址","电话"};
    Object [][] a;
    //菜单
  	JFrame fam;
    JMenuBar Fmenubar,Dmenubar;
    JMenu fileMenu_1,fileMenu_2,editMenu_1,editMenu_2,helpMenu;
    JMenuItem item_receave,item_statist,Fitem_exit,Ditem_exit,item_save,item_open;
    JMenuItem item_setScore,item_find,item_about;
    FileDialog filedialog_save,filedialog_load;//声明2个文件对话框
   //JRadioButton button1,button2;
    CheckboxGroup sex;
    int t_Age[]=new int[20];
    Choice choice;
    Checkbox box1,box2;
    //Checkbox box1,box2;
   // CheckboxGroup sex;
    //界面输入区域
    TextField name,id,homeAddress,telNum;
    JButton btn_receave,btn_statist;
    
    //设置录取线
       	JFrame fam_luqu=new JFrame("设置录取线");
    	TextField tf_luqu;
    	JLabel lb_luqu;
    	JButton btn_luqu=new JButton("确定");
    	
    //查找
      	JFrame fam_cha=new JFrame("查找");
    	JTextField tf_chaname=new JTextField("",8);
    	JTextField tf_chaid=new JTextField("",8);
    	JButton btn_cha=new JButton("确定");
    	TextArea area=new TextArea("",200,40,TextArea.SCROLLBARS_VERTICAL_ONLY );
    	
    JPanel pnl,pnl_1,pnl_2;//pnl_1为设置录取线服务,pnl_2为查找服务
    JDialog dlg,dlg_1;//dlg为显示已录取的学生信息服务,dlg_1为查找服务

    double j_1=0.0,j_2=0.0;//用来保存综合成绩和体育成绩
	//添加快捷方式
	static Vector v=new Vector(); //保存录取学生的信息
    School one;//为本类服务的学校对象
    Student two;//为本类服务的学生对象
    
Example_2(){
		
     one=new School();   
     two=new Student("","",0.0,0.0);
	 a=new Object[200][6];//生成200X4的表格
	 
	 //查寻对话框
	 table=new JTable(a,jname);
     dlg=new JDialog(fam,"录取学生统计");
     dlg_1 = new JDialog(fam,"符合要求的名单");
     dlg_1.setSize(450,300);
     dlg_1.setLocation(350,240);
     dlg_1.add(area);
     dlg_1.addWindowListener(new WindowAdapter()
      {public void windowClosing(WindowEvent e)
       {
          dlg_1.setVisible(false);
       }});
        
     //生成FRAM
     fam=new JFrame("学生信息管理系统");
     fam.setSize(300,251); 
     fam.setLocation(350,240);    
     fam.addWindowListener(new WindowAdapter()
      {public void windowClosing(WindowEvent e)
       {
          System.exit(0);
       }});
       for(int i=10;i<30;i++)
       t_Age[i-10]=i;
       
       choice = new Choice();
       for(int i=0;i<20;i++)
         choice.addItem(String.valueOf(t_Age[i])); 
     name=new TextField("",8);
     id=new TextField("",8);
     homeAddress=new TextField("",8);
     telNum=new TextField("",8); 
     sex=new CheckboxGroup();
     box1=new Checkbox("男",true,sex);
     box2=new Checkbox("女",false,sex);
     
     //button1=new JRadioButton("男");
     //sex.add(button1);
     //button2=new JRadioButton("女");
     //sex.add(button2);    
     btn_receave=new JButton("添加");
     btn_statist=new JButton("统计"); 
     pnl=new JPanel(); 
     pnl_1=new JPanel();
     pnl_2=new JPanel();
     pnl.add(box1);
     pnl.add(box2);
     //生成菜单条,菜单项,菜单(包括FRAME和DIALOG) 
     Fmenubar=new JMenuBar();
     Dmenubar=new JMenuBar();
     fileMenu_1=new JMenu("文件");
     fileMenu_2=new JMenu("文件");
     editMenu_1=new JMenu("编辑");
     editMenu_2=new JMenu("编辑");
     helpMenu=new JMenu("帮助");     
     item_receave=new JMenuItem("添加"); 
     item_statist=new JMenuItem("统计");
     Fitem_exit=new JMenuItem("退出");
     Ditem_exit=new JMenuItem("退出");
     item_save=new JMenuItem("保存");
     item_open=new JMenuItem("打开");
     item_setScore=new JMenuItem("设置录取分数");
     item_find=new JMenuItem("查找学生信息");
     item_about=new JMenuItem("学生信息管理系统");
     fileMenu_1.add(item_receave);
     fileMenu_1.add(item_statist); 
     fileMenu_1.addSeparator();
     fileMenu_1.add(Fitem_exit);
     fileMenu_2.add(item_open);
     fileMenu_2.add(item_save);
     fileMenu_2.addSeparator();
     fileMenu_2.add(Ditem_exit);
     helpMenu.add(item_about);
     editMenu_2.add(item_setScore);
     editMenu_1.add(item_find);
     Fmenubar.add(fileMenu_1);
     Fmenubar.add(editMenu_2);
     Fmenubar.add(helpMenu);
     Dmenubar.add(fileMenu_2);
     Dmenubar.add(editMenu_1);
     fam.setJMenuBar(Fmenubar);
     dlg.setJMenuBar(Dmenubar);
     //下面创建1个依赖于该窗口的保存文件对话框:
    filedialog_save=new FileDialog(this,"保存文件话框",FileDialog.SAVE);
    filedialog_save.setVisible(false);
    //再创建1个依赖于该窗口的打开文件对话框:
    filedialog_load=new FileDialog(this,"打开文件话框",FileDialog.LOAD);
    filedialog_load.setVisible(false);
     item_receave.addActionListener(this);
     item_statist.addActionListener(this);
     Fitem_exit.addActionListener(this);
   
     
        //设置录取线
        tf_luqu =new TextField("",8);;
    	pnl_1.add(new JLabel("输入录取线"));
    	pnl_1.add(tf_luqu);   
    	lb_luqu=new JLabel("当前录取分数线为:"+one.GetScoreLine(),JLabel.CENTER);
    	tf_luqu.addTextListener(this);	
    	fam_luqu.add(pnl_1);
    	fam_luqu.add(lb_luqu);
    	fam_luqu.add(btn_luqu);
    	fam_luqu.setLayout(new GridLayout(3,1,2,5));
        fam_luqu.setSize(180,145); 
        fam_luqu.setResizable(false);
        fam_luqu.setLocation(400,300); 
        btn_luqu.addActionListener(this);
        fam_luqu.addWindowListener(new WindowAdapter()
         {public void windowClosing(WindowEvent e)
           {
              fam_luqu.setVisible(false);
           }});
           
        //查找       
        pnl_2.add(new JLabel("输入姓名",JLabel.CENTER));
    	pnl_2.add(tf_chaname);
    	pnl_2.add(new JLabel("输入学号",JLabel.CENTER));
    	pnl_2.add(tf_chaid);
    	pnl_2.add(new JLabel("\t\t"));
    	pnl_2.add(new JLabel("\t\t"));
      	pnl_2.setLayout(new GridLayout(3,2,5,10));
      	fam_cha.add(new JLabel("\t\t\t"),BorderLayout.NORTH);
      	fam_cha.add(pnl_2);
      	fam_cha.add(btn_cha,BorderLayout.SOUTH);
        fam_cha.setSize(230,187); 
        fam_cha.setResizable(false);
       
        fam_cha.setLocation(400,300); 
        btn_cha.addActionListener(this);
        fam_cha.addWindowListener(new WindowAdapter()
         {public void windowClosing(WindowEvent e)
           {
              fam_cha.setVisible(false);
           }});
           
     //各种监听   
     item_find.addActionListener(this);
     item_setScore.addActionListener(this);
     item_about.addActionListener(this);
     name.addTextListener(this);
     id.addTextListener(this);
     homeAddress.addTextListener(this);
     telNum.addTextListener(this);
   	 item_save.addActionListener(this);
   	 item_open.addActionListener(this);
     btn_receave.addActionListener(this);
     btn_statist.addActionListener(this);
     
     //继续完善FRAM
     fam.add(new JLabel("学号",JLabel.CENTER));
     fam.add(id);
     fam.add(new JLabel("姓名",JLabel.CENTER));
     fam.add(name);
     fam.add(new JLabel("姓别",JLabel.CENTER));
     fam.add(pnl);
     fam.add(new JLabel("年龄",JLabel.CENTER));
     fam.add(choice);
     fam.add(new JLabel("家庭住址",JLabel.CENTER));
     fam.add(homeAddress);
     fam.add(new JLabel("电话号码",JLabel.CENTER)); 
     fam.add(telNum);
     fam.add(btn_receave);
     fam.add(btn_statist);
     fam.setLayout(new GridLayout(7,2,20,9));
     fam.setVisible(true);
     fam.setResizable(false);
    

    //生成显示已录取的学生信息的框架
      jlb=new JLabel("共录取了学生 "+ v.size()+"名");
  
	  dlg.getContentPane().add(new JScrollPane(table),BorderLayout.CENTER);
	  dlg.getContentPane().add(jlb,BorderLayout.SOUTH);
	  dlg.setSize(350,300);
	  dlg.addWindowListener(new WindowAdapter()
      {public void windowClosing(WindowEvent e)
       {
          dlg.setVisible(false);
       }});
      dlg.setResizable(false);
	
		dlg.validate();	
	}
	
	//判断是否被录取函数
	void JudgeReceave(Student temp){
		School line=new School();
		
		for(int i=0;i<v.size();i++){
			if(temp.GetID()==((Student)v.get(i)).GetID()){
		      JOptionPane.showMessageDialog(fam, "该学生已被录取过了");	
		      name.setText("");
		      id.setText("");
		      return;
			}
		}
		
		if(temp.GethomeAddress()>line.GetScoreLine()||(temp.GettelNum()>=96.0&&temp.GethomeAddress()>=300.0)){
		JOptionPane.showMessageDialog(fam, "学号:"+two.GetID()+"   "+"姓名:"+two.GetName()+"   "+"已录取");
		v.addElement(new Student(two.GetName(),two.GetID(),two.GethomeAddress(),two.GettelNum()));
		name.setText("");
	    id.setText("");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -