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

📄 romulusclient.java

📁 《Java案例开发》源代码( 考勤系统的完整实现!) 包括数据库 网络通讯&uml
💻 JAVA
字号:
/* * RomulusClient.java * * Created on 2004年1月14日, 上午10:21 */package romulus.UI;import java.io.*;import java.sql.*;/** * * @author  Administrator */public class RomulusClient extends javax.swing.JFrame implements java.beans.PropertyChangeListener{        /** Creates new form RomulusClient */    public RomulusClient() {        initComponents();        startWork();    }        /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    private void initComponents() {//GEN-BEGIN:initComponents        topLabel = new javax.swing.JLabel();        bottomLabel = new javax.swing.JLabel();                setTitle("RomulusClient");        setFont(new java.awt.Font("Arial", 0, 12));        setResizable(false);        addWindowListener(new java.awt.event.WindowAdapter() {            public void windowClosing(java.awt.event.WindowEvent evt) {                exitForm(evt);            }        });                topLabel.setFont(getFont());        topLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);        topLabel.setText("Romulus Test Application Client For Test");        getContentPane().add(topLabel, java.awt.BorderLayout.NORTH);                bottomLabel.setFont(getFont());        bottomLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);        bottomLabel.setText("Copyright 1998-2004");        getContentPane().add(bottomLabel, java.awt.BorderLayout.SOUTH);                pack();        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();        setSize(new java.awt.Dimension(320, 240));        setLocation((screenSize.width-320)/2,(screenSize.height-240)/2);    }//GEN-END:initComponents        /** Exit the Application */    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm        System.exit(0);    }//GEN-LAST:event_exitForm        /**     *Start the client work.     */    public void startWork(){        //add the LoginPanel        login = new LoginPanel();        getContentPane().add(login, java.awt.BorderLayout.CENTER);        login.addPropertyChangeListener(this);    }        //property change    public void propertyChange(java.beans.PropertyChangeEvent PCEvent) {        try{            //login            if(PCEvent.getSource() == login){                String prop = PCEvent.getPropertyName();                if(prop.equals(LoginPanel.PropName)){                    this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));                    LoginProcess(PCEvent);                    this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));                }//else name            }            //question            else if(PCEvent.getSource() == question){                String prop = PCEvent.getPropertyName();                if(prop.equals(QuestionPanel.PropName_Exit)){                    System.exit(0);                }                else if(prop.equals(QuestionPanel.PropName_Commit)){                    this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));                    QuestionProcess(PCEvent);                    this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));                }            }            //grade            else if(PCEvent.getSource() == grade){                String prop = PCEvent.getPropertyName();                if(prop.equals(GradePanel.PropName)){                    this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));                    GradeProcess();                    this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));                }            }                    }        catch(java.io.IOException e){            ErrorMSG(e.toString(), true);        }    }        //login property process    private void LoginProcess(java.beans.PropertyChangeEvent PCEvent) throws java.io.IOException{        String value = PCEvent.getNewValue().toString();        if(value.equals(LoginPanel.Prop_Exit)){            System.exit(0);        }        else{            //set the RomulusTestClient            romulus.NET.RomulusTestClient client = new romulus.NET.RomulusTestClient();            System.out.println(PCEvent.getNewValue().toString());            if(client.UserCheck(PCEvent.getNewValue().toString())){                                getContentPane().remove(login);                                //get Test to test                client = new romulus.NET.RomulusTestClient();                String testid = getTestIdent(PCEvent.getNewValue().toString());                romulus.Test t = client.GetTest(testid);                                String username = getUserName(PCEvent.getNewValue().toString());                this.testinfo = new romulus.Manager.TestInfo(username, t, 0.0, java.util.Calendar.getInstance().getTime().toString());                                question = new QuestionPanel(t, false);                getContentPane().add(question, java.awt.BorderLayout.CENTER);                question.addPropertyChangeListener(this);                                java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();                this.setSize(new java.awt.Dimension(600, 400));                this.setLocation((screenSize.width-600)/2,(screenSize.height-400)/2);                this.repaint();                this.getContentPane().repaint();                this.validate();            }            else{                ErrorMSG("Incorrect Login Information", false);            }        }    }        //question event process    private void QuestionProcess(java.beans.PropertyChangeEvent PCEvent)  throws java.io.IOException{        getContentPane().remove(question);        grade = new GradePanel();        getContentPane().add(grade);        grade.setLabel("Now grading the test...");        this.repaint();        this.getContentPane().repaint();        this.validate();                System.out.println(testinfo.getName());        this.testinfo.setTest((romulus.Test)(PCEvent.getNewValue()));        romulus.NET.RomulusTestClient client = new romulus.NET.RomulusTestClient();        this.testinfo = client.GradeTest(testinfo);        System.out.println(testinfo.getName());                int i_score = (int)(testinfo.getScore()*10000);        double d_score = (double)i_score/100.00;        grade.setLabel("Your score is "+d_score+"(%)");        grade.setProcess(false);        grade.setButton(true);        grade.addPropertyChangeListener(this);        this.repaint();        this.getContentPane().repaint();        this.validate();            }        //grade event process    private void GradeProcess()  throws java.io.IOException{        getContentPane().remove(grade);        question = new QuestionPanel(testinfo.getTest(), true);        getContentPane().add(question, java.awt.BorderLayout.CENTER);        question.addPropertyChangeListener(this);        this.repaint();        this.getContentPane().repaint();        this.validate();            }        //get testnum    //Std1|std1|1 to 1    private static String getTestIdent(String info){        int begin = info.lastIndexOf('|');       return info.substring(begin+1);    }    //Std1|std1|1 to Std1    private static String getUserName(String info){        int begin = info.indexOf('|');        String name = info.substring(0, begin);        return name;    }        //show msg    private void ErrorMSG(String msg, boolean exit){        //for JOptionPane can not set the font        String msgout = "<html><font face=\"Comic Sans MS\" size=3>"+msg+"</font></html>";        String[] Buttons  = {"<html><font face=\"Comic Sans MS\" size=3>OK</font></html>"};                javax.swing.JOptionPane.showOptionDialog(this, msgout, "Message",        javax.swing.JOptionPane.DEFAULT_OPTION, javax.swing.JOptionPane.ERROR_MESSAGE,        null, Buttons, Buttons[0]);                if(exit){            System.exit(0);        }    }        /**     * @param args the command line arguments     */    public static void main(String args[]) {        RomulusClient rc = new RomulusClient();        rc.show();    }        // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JLabel topLabel;    private javax.swing.JLabel bottomLabel;    // End of variables declaration//GEN-END:variables        //The panels used in the client    private LoginPanel login;    private QuestionPanel question;    private GradePanel grade;    private romulus.Manager.TestInfo testinfo;    //End of panels}

⌨️ 快捷键说明

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