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

📄 personnel.java

📁 java写得用户管理小程序
💻 JAVA
字号:
/**
 *   一个完整的学生管理系统,可以进行学号,姓名,年龄,学校,专业,电子邮件的输入,并可进行删除和查找
 *    十分方便
 *
 *   author:Teddy  Nov.18 2004
 *   @All Rights Reserved
 *
 *   version 1.0
 *
 *
 *
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Personnel{
	public static void main(String[] args){
	
	PersonFrame frame =new PersonFrame();
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.show();
	}
}

class PersonFrame extends JFrame{
	public PersonFrame(){
		this.setTitle("学生信息管理系统");
		Container contentpane =this.getContentPane();
		PersonPanel panel = new PersonPanel();
		contentpane.add(panel);
		pack();
	}
}

class PersonPanel extends JPanel{
	public PersonPanel(){
	
		setLayout(new BorderLayout());
	    
	    /*num=new String[20];
	    name=new String[20];
	    age=new String[20];
	    mail=new String[20];
	    major=new String[20];
	    school=new String[20];
	    */
		JLabel l0=new JLabel("                                                                     学生管理系统");
		add(l0,BorderLayout.NORTH);
		
		exitbutton=new JButton("退出");
		ActionListener quit=new quitAction();
		exitbutton.addActionListener(quit);
		add(exitbutton,BorderLayout.SOUTH);	
	    
	    panel2=new JPanel();
	    panel2.setLayout(new GridLayout(0,2));
	    
	    l1=new JLabel("学号");
	    t1=new JTextField(7);
	    panel2.add(l1);
	    panel2.add(t1);
	    
	    l2=new JLabel("姓名");
	    t2=new JTextField(20);
	    panel2.add(l2);
	    panel2.add(t2);
	    
	    l3=new JLabel("年龄");
	    t3=new JTextField(2);
	    panel2.add(l3);
	    panel2.add(t3);
	    
	    l4=new JLabel("学校");
	    t4=new JTextField(30);
	    panel2.add(l4);
	    panel2.add(t4);
	    
	    l5=new JLabel("专业");
	    t5=new JTextField(30);
	    panel2.add(l5);
	    panel2.add(t5);
	    
	    l6=new JLabel("E-MAIL");
	    t6=new JTextField(20);
	    panel2.add(l6);
	    panel2.add(t6);
	    
	    l7=new JLabel("地址");
	    t7=new JTextField(20);
	    panel2.add(l7);
	    panel2.add(t7);
	    
	    okbutton=new JButton("添加");       //添加按钮,执行添加动作
	    ActionListener ok=new okAction();
	    okbutton.addActionListener(ok);
	    eraser=new JButton("删除");        //删除按钮执行删除动作
	    ActionListener erase=new delAction();
	    eraser.addActionListener(erase);
	    panel2.add(okbutton);
	    panel2.add(eraser);
	    
	    seebutton=new JButton("查找");    //查找按钮执行查找动作
	    ActionListener see=new seeAction();
	    seebutton.addActionListener(see);
	    clearer=new JButton("清除");      //清除按钮执行清除动作
	    ActionListener clear=new clearAction();
	    eraser.addActionListener(clear);
	    panel2.add(seebutton);
	    panel2.add(clearer);
	    
	    
	    
	    
	    add(panel2,BorderLayout.CENTER);
	} 
	
	
    
    private class okAction implements ActionListener{        //点击添加按钮后执行的语句
    	public void actionPerformed(ActionEvent event){
    		if(i<totalcount){                                //若数组还够用
	    		num[i]=t1.getText().trim();
	    		name[i]=t2.getText().trim();
	    		age[i]=t3.getText().trim();
	    		school[i]=t4.getText().trim();
	    		major[i]=t5.getText().trim();
	    		mail[i]=t6.getText().trim();
	    		home[i]=t7.getText().trim();
	    		i++;
	    		count++;
	    		System.out.println("the insert process completed!");
	    		
	    		//System.out.println(num[i-1]+"   "+name[i-1]);
	    	}
	    	else{                                            //若数组不够用
	    		String[] num1=new String[totalcount+in];
	    		String[] name1=new String[totalcount+in];
	    		String[] age1=new String[totalcount+in];
	    		String[] major1=new String[totalcount+in];
	    		String[] school1=new String[totalcount+in];
	    		String[] mail1=new String[totalcount+in];
	    		String[] home1=new String[totalcount+in];
	    		for(int j=0;j<totalcount;j++){
	    			num1[j]=num[j];
	    			name1[j]=name[j];
	    			major1[j]=major[j];
	    			school1[j]=school[j];
	    			age1[j]=age[j];
	    			mail1[j]=mail[j];
	    			home1[j]=home[j];
	    		}
	    		name=new String[totalcount+in];
	    		num=new String[totalcount+in];
	    		major=new String[totalcount+in];
	    		age=new String[totalcount+in];
	    		mail=new String[totalcount+in];
	    		school=new String[totalcount+in];
	    		home=new String[totalcount+in];
	    		for(int j=0;j<totalcount;j++){
	    			num[j]=num1[j];
	    			name[j]=name1[j];
	    			major[j]=major1[j];
	    			school[j]=school1[j];
	    			age[j]=age1[j];
	    			mail[j]=mail1[j];
	    			home[j]=home1[j];
	    		}
	    		num[i]=t1.getText().trim();
	    		name[i]=t2.getText().trim();
	    		age[i]=t3.getText().trim();
	    		school[i]=t4.getText().trim();
	    		major[i]=t5.getText().trim();
	    		mail[i]=t6.getText().trim();
	    		home[i]=t7.getText().trim();
	    		i++;
	    		count++;
	    		System.out.println("the insert process completed!");
	    		totalcount+=in;
	    	}
	    			
    	}
    }
    
    private class seeAction implements ActionListener{    //点击查找按钮后执行的语句
		public void actionPerformed(ActionEvent event){
			int j;
			String s=JOptionPane.showInputDialog(" 请选择您要执行的查找方式:0--按照学号查找;1--按照姓名查找");
		    if(s.equals("0")){
		    	String s1=JOptionPane.showInputDialog(" 请输入您要查找的学号");
		    	for(j=0;j<totalcount;j++)
		    		if(num[j].equals(s1)){
		    			t1.setText(num[j]);
						t2.setText(name[j]);
						t3.setText(age[j]);
						t4.setText(school[j]);
		    	        t5.setText(major[j]);
		    	        t6.setText(mail[j]);
		    	        t7.setText(home[j]);
		    	        System.out.println("the display process completed!");
		    	       // break;
		  	        }
		  	    if(j>=totalcount)
		  	    	System.out.println("failed");    
		    
		    }
		    
		  	else if(s.equals("1")){
		  		String s2=JOptionPane.showInputDialog(" 请输入您要查找的姓名");
				for( j=0;j<totalcount;j++)
		    		if(name[j].equals(s2)){
		    			t1.setText(num[j]);
						t2.setText(name[j]);
						t3.setText(age[j]);
						t4.setText(school[j]);
		    	        t5.setText(major[j]);
		    	        t6.setText(mail[j]);
		    	        t7.setText(home[j]);
		    	        
		    	        System.out.println("the display process completed!");
		    	        //break;
		    	    }
		    	if(j>=totalcount)
		    		System.out.println("failed");    
		    
		  	}
			
			
		}
	}   
    
   
    
    
    private class delAction implements ActionListener{      //点击删除按钮后执行的语句
    	public void actionPerformed(ActionEvent event){
    			int j;
    			String s=JOptionPane.showInputDialog(" 请选择您要执行的删除方式:0--按照学号删除;1--按照姓名删除");
    			if(s.equals("0")){
			    	String s1=JOptionPane.showInputDialog(" 请输入您要查找的学号");
			    	for( j=0;j<totalcount;j++)
			    		if(num[j].equals(s1)){
			    			int t=j;
			    			for(int l=t+1;l<totalcount;l++){
			    				num[l-1]=num[l];
			    				name[l-1]=name[l];
			    				age[l-1]=age[l];
			    				school[l-1]=school[l];
			    				mail[l-1]=mail[l];
			    				major[l-1]=major[l];
			    				home[l-1]=home[l];
			    				count--;
			    				System.out.println("deletion sucessful!");
			    			}
			    		}
			    	if(j>=totalcount)
			    		System.out.println("failed");
		    	}
		    	if(s.equals("1")){
			    	String s2=JOptionPane.showInputDialog(" 请输入您要查找的姓名");
			    	for( j=0;j<totalcount;j++)
			    		if(name[j].equals(s2)){
			    			int t=j;
			    			for(int l=t+1;l<totalcount;l++){
			    				num[l-1]=num[l];
			    				name[l-1]=name[l];
			    				age[l-1]=age[l];
			    				school[l-1]=school[l];
			    				mail[l-1]=mail[l];
			    				major[l-1]=major[l];
			    				home[l-1]=home[l];
			    				count--;
			    			}
			    		}
			    	if(j>=totalcount)
			    		System.out.println("failed");
			   }
		    	
		    			
		    			
		  	}
    }
    
    private class clearAction implements ActionListener{   //点击清除按钮后执行的语句
    	public void actionPerformed(ActionEvent event){
    		t1.setText("");
    		t2.setText("");
    		t3.setText("");
    		t4.setText("");
    		t5.setText("");
    		t6.setText("");
    		t7.setText("");
    		
    		
    	}
    }
     private class quitAction implements ActionListener{   //点击退出按钮后执行的语句
    	public void actionPerformed(ActionEvent event){
    		
    		System.out.println("the quit process completed!");
    		System.exit(0);
    	}
    }
    
    
    private JTextField t1;
    private JTextField t2;
    private JTextField t3;
    private JTextField t4;
    private JTextField t5;
    private JTextField t6;
    private JTextField t7;
    
    private JLabel l1;
    private JLabel l2;
    private JLabel l3;
	private JLabel l4;
	private JLabel l5;
	private JLabel l6;
	private JLabel l7;
	
	private String[] name=new String[20];   //用来存储学生的姓名
	private String[] age=new String[20];    //用来存储学生的年龄
	private String[] school=new String[20];  //用来存储学生的学校
	private String[] mail=new String[20];   //用来存储学生的E-MAIL
	private String[] num=new String[20];   //用来存储学生的学号
	private String[] major=new String[20];  //用来存储学生的专业
	private String[] home=new String[10];  //用来存储学生的地址
	
	private JButton okbutton;
	private JButton seebutton;
	private JButton exitbutton;
	private JButton eraser;
	private JButton clearer;
	
	private static int i=0;            //当前数组存储位置
	private JPanel panel2;   
	private static int totalcount=20;  //数组容量
	private final static int in=20;   // 数组增量
	private  static int count=0;     //数组元素个数
	
}

⌨️ 快捷键说明

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