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

📄 students.java

📁 基于RMI的学生成绩管理程序,实现了线程,事件模型.
💻 JAVA
字号:
/*
 * Students.java
 *
 * Created on 2005年11月23日, 下午1:35
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */



/**
 *
 * @author 和尚
 */
import javax.swing.JFrame;
import java.awt.FlowLayout;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.rmi.*;

public class Students extends JFrame implements ActionListener{
    
    /** Creates a new instance of StudentinfoClient */
        FlowLayout flowLayout = new FlowLayout();
	JLabel     jLabel1 = new JLabel("UserName:");
	JTextField jTextField1 = new JTextField(8);
	JLabel     jLabel2 = new JLabel("PassWord:");
	JTextField jTextField2 = new JTextField(8);
	JButton    jButton1 = new JButton("OK");
        JButton    jButton2 = new JButton("Exit");
	
	public Students()
	{		
		super(" Logon:");
		setSize(200,150);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.getContentPane().setLayout(flowLayout);
		this.getContentPane().add(jLabel1);
		this.getContentPane().add(jTextField1); 		 
		this.getContentPane().add(jLabel2); 
		this.getContentPane().add(jTextField2); 
                this.getContentPane().add(jButton1); 
		jButton1.addActionListener(this);
                this.getContentPane().add(jButton1); 
		jButton1.addActionListener(this);
		show();
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==jButton1)
		{
			try{
                             String studentinfoURL;
	                     studentinfoURL="rmi://127.0.0.1/Studentinfo";
	                     Studentinfo studentinfo;
	                     studentinfo=(Studentinfo)Naming.lookup(studentinfoURL);
	                     String input1="",username="",password="",input2="";  
	                     int flag,i,score;
	                     for(i=0;i<3;i++) {
	                          username=jTextField1.getText();   
	                          password=jTextField2.getText();
	                          flag=studentinfo.logon(username,password);
	                          if(flag==1) {	
      	                              jTextField1.setText("");
	            	              jTextField2.setText("");
	            	              jTextField1.requestFocus();
                                      input1=JOptionPane.showInputDialog("Enter a student's name");
                                      String studentname=String.valueOf(input1);
                                      System.out.println("111");
                                      input2=JOptionPane.showInputDialog("Enter a course");
	                              String course=String.valueOf(input2);
                                      System.out.println("222");
	                              score=studentinfo.lookup(studentname,course);
                                      if(score==0){
                                      System.out.println("333");
                                      break;
                                      }
                                      //if(score!=0){System.out.println(score);}
	                          } 
	                          if(flag==0) {
                                      break;
                                 }	                                   
	                      }
                           }
                          catch(Exception ex)
                               {
	                          ex.printStackTrace();
                                }
                           finally {System.exit(0);}
		}
                else if(e.getSource()==jButton2){
                      System.exit(0);                            
                }
        }
	public static void main(String[] args)
	{
		Students test = new Students();
	}
}

⌨️ 快捷键说明

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