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

📄 cho.java

📁 java制作学生查询系统
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
public class cho
{
	public static void main(String args[])
	{
		MyDialogFrame df=new MyDialogFrame();		
	}
}
class MyDialogFrame extends Frame implements ActionListener,FocusListener
{
	Label u=new Label("");
	Label m=new Label("");
	Label s=new Label("");
	Label n=new Label("                                                                                                                                                                         ");
	Label o=new Label("                                                                                                                                                                         ");	
	Label prompt1=new Label("班级");
	TextField input1=new TextField(6);
	Label prompt2=new Label("姓名");
	TextField input2=new TextField(6);
	Label prompt3=new Label("学号");
	TextField input3=new TextField(6);
	Label prompt4=new Label("成绩");
	TextField input4=new TextField(6);
	Button display=new Button("显示记录");
	Button addrecord=new Button("增加记录");
	Button delete=new Button("删除记录");
	Button search=new Button("查找记录");	
	Dialog InOutDlg;
	Button btn,btnR,btnT;
	Label password=new Label("密码(输入前、后都要回车)");
	TextField in=new TextField(10);
	Label user=new Label("用户名(输入后回车)");
	TextField input=new TextField(10); 
	String pw="";
	String name="";
	String dy="";
        String ad="";
        String de="";
        String sh="";
        String msg="";
        Student [] message=new Student [100];
        int ComparePt[]=new int[100];//保存对分法的中间点
        int i;
        int j=0;
        int k;
	Panel p1;	
MyDialogFrame()
{
	super("国际学院学生管理系统");
	btn=new Button("请先登录");
	btnR=new Button("登录");
	btnT=new Button("密码提示");
	setLayout(new FlowLayout());		
	p1=new Panel();
	p1.setBackground(Color.cyan);
	p1.add(n);
	p1.add(btn);	
	p1.add(o);
	add(p1);
	add(prompt1);
		add(input1);
		add(prompt2);
		add(input2);
		add(prompt3);
		add(input3);
		add(prompt4);
		add(input4);
		add(display);		
		add(addrecord);
		add(delete);
		add(search);
		for(i=0;i<100;i++)
              {
               message[i]=new Student("","","","");
              }
		display.addActionListener(this);
		addrecord.addActionListener(this);
		delete.addActionListener(this);
		search.addActionListener(this);
	this.addWindowListener(new WinAdpt());
	in.addActionListener(this);
	input.addActionListener(this);
	btn.addActionListener(this);
	btnR.addActionListener(this);
	btnT.addActionListener(this);
	setSize(1000,600);
	show();
}
public void actionPerformed(ActionEvent e)
{	
	if(e.getActionCommand()=="请先登录")
	{
		InOutDlg=new Dialog(this,"请输入用户名,密码");
		InOutDlg.setLayout(new GridLayout(5,2));
		InOutDlg.add(user);
		InOutDlg.add(s);
		InOutDlg.add(in);
		//InOutDlg.add(u);
		InOutDlg.add(password);
		InOutDlg.add(new Label());
		InOutDlg.add(input);
		InOutDlg.add(m);
		InOutDlg.add(btnR);
		InOutDlg.add(btnT);		
		InOutDlg.setSize(500,200);
		InOutDlg.addFocusListener(this);
		InOutDlg.show();
		}	
	else if(e.getActionCommand()=="登录")
	{
		if(pw.equals("01201423"))
		{
		  InOutDlg.dispose();
		  remove(p1);
		  }		  
		else s.setText("用户名、密码输入不正确,请点击密码提示");
		{
			in.setText("");
			input.setText("");}
		}
	else if(e.getActionCommand()=="密码提示")
	{		
//		u.setText("张克勤");
		m.setText("01201423");
		}
	else if(e.getSource()==input)
		{
		input.setEchoChar('*');
		pw=input.getText();
		repaint();
	        }
	else if(e.getSource()==in)
		{		
		name=in.getText();		
	        }
	     if(e.getActionCommand()=="显示记录")
		{
			dy="显示";
			repaint();
		}  
		if(e.getActionCommand()=="增加记录")
		{
			message[j].cn=input1.getText();
			message[j].n=input2.getText();
			message[j].sn=input3.getText();
			message[j].s=input4.getText();
			j++;
			dy="显示";
			repaint();
		}
		if(e.getActionCommand()=="删除记录")
		{
			if(j>=1)
			{
			j=--j;
			message[j].cn="";
			message[j].n="";
			message[j].sn="";
			message[j].s="";
			dy="显示";
			repaint();
		        }
		        else de="删除失败";	repaint();	
		}
		if(e.getActionCommand()=="查找记录")
		{
			sh="查找";
			int k=BiSearch(input3.getText(),j);//按学号查找
			if(k==-1)
			msg="序列中没有匹配的数据";
			else
			msg="匹配的数据在序列的第"+k+"个记录中";
			dy="显示";
			repaint();
		}			
}
public void paint(Graphics g)
{
	if(pw.equals("01201423"))
	        {
	        g.drawString("密码正确,登录成功",10,50);
	        if(dy.equals("显示"))
	        {
	        g.drawString("班级",100,140);
	        g.drawString("姓名",300,140);
	        g.drawString("学号",500,140);
	        g.drawString("成绩",700,140);
	        g.drawString("当前记录数:"+j,400,120);
	        for(k=0;k<j;k++)
	        {
	        g.drawString(message[k].cn,100,160+k*20);
	        g.drawString(message[k].n,300,160+k*20);
	        g.drawString(message[k].sn,500,160+k*20);
	        g.drawString(message[k].s,700,160+k*20);
	        }
	        if(de.equals("删除失败"))
	        {
	        	g.drawString("已经没有记录了,删除失败",300,70);
	        }
	        if(sh.equals("查找"))
	        {
	        	g.drawString(msg,50,70);
	        }
	        }
	        }
	}
public void focusGained(FocusEvent e){}
public void focusLost(FocusEvent e){}
int BiSearch(String Key,int high)
{
	int low=0;
	int mid;
	int i=0;
	while(low<=high)
	{
		mid=(high+low)/2;
		ComparePt[i++]=Integer.parseInt(message[mid].sn);
		if((message[mid].sn).equals(Key))
		return mid+1;
		else if((message[mid].sn).compareTo(Key)==-1)
		low=mid+1;
		else
		high=mid-1;
	}
	return -1;
}
} 
class WinAdpt extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
	((Frame)e.getWindow()).dispose();
	System.exit(0);
	}
}
 class Student
{
 public String cn;//班级
 public String n;//姓名
 public String sn;//学号 
 public String s;//成绩
 public Student(String classnumber,String name,String studentnumber,String score)
 {
 	cn=classnumber;
 	n=name;
 	sn=studentnumber;
 	s=score;
 }
 public String getcn()
 {
 	return cn;	
 }
}

⌨️ 快捷键说明

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