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

📄 studentframe.java

📁 连接测试系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.cnu.cie.olts.client.student;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.GridLayout;import java.awt.Rectangle;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowEvent;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintWriter;import java.net.Socket;import javax.swing.ComboBoxModel;import javax.swing.DefaultComboBoxModel;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFormattedTextField;import javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;import javax.swing.JTextPane;import javax.swing.JToolBar;import javax.swing.WindowConstants;import javax.swing.SwingUtilities;import javax.swing.text.AttributeSet;import javax.swing.text.BadLocationException;import javax.swing.text.PlainDocument;import com.cnu.cie.olts.client.AboutJPanel;import com.cnu.cie.olts.client.BriefAnswerJPanel;import com.cnu.cie.olts.client.FillBlankJPanel;import com.cnu.cie.olts.client.ItemInfo;import com.cnu.cie.olts.client.Login;import com.cnu.cie.olts.client.TrueFalseJPanel;import com.cnu.cie.olts.client.multipleChoiceJPanel;import com.cnu.cie.olts.client.singleChoiceJPanel;/*** This code was edited or generated using CloudGarden's Jigloo* SWT/Swing GUI Builder, which is free for non-commercial* use. If Jigloo is being used commercially (ie, by a corporation,* company or business for any purpose whatever) then you* should purchase a license for each developer using Jigloo.* Please visit www.cloudgarden.com for details.* Use of Jigloo implies acceptance of these licensing terms.* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.*/public class StudentFrame extends javax.swing.JFrame {	private JMenuBar studentMenuBar;	private JMenuItem reconnectMenuItem;	private JMenuItem helpMenuItem;	private JScrollPane jScrollPane1;	private static JPanel mainPanel;	private JPanel titlepanel;	private static JPanel centerpanel;	private JTextPane textpagepane;	private JTextField difficulttfone;	private JTextField difficulttftwo;	private JButton submitbt;	private JButton mybutton;	private JComboBox subjectcombobox;	private JButton reconnectButton;	private JButton scoreAccountButton;	private JButton starttestButton;	private JToolBar studentToolBar;	private JMenu aboutMenu;	private JMenuItem exitMenuItem;	private JMenuItem scoreAccountMenuItem;	private JMenuItem starttestMenuItem;	private JMenu jMenu1;			 Socket socket;		 BufferedReader bufreader=null;	 PrintWriter pswriter=null;	 static ItemInfo[] iteminfo;	 static int[] itemstate;	 static int unfinishitem=0;	 static int itemsnumber=0;	 public static int testscore=0;	/**	* Auto-generated main method to display this JFrame	*/	 /*	public static void main(String[] args) {		SwingUtilities.invokeLater(new Runnable() {			public void run() {		//		StudentFrame inst = new StudentFrame();		//		inst.setLocationRelativeTo(null);		//		inst.setVisible(true);			}		});	}	*/	public StudentFrame(Socket socket,BufferedReader bufreader,PrintWriter pswriter) {		super();		initGUI();	//	Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();    //  setLocation(((screen.width-this.WIDTH)/2),((screen.height-this.HEIGHT)/2));		this.socket=socket;		this.bufreader=bufreader;		this.pswriter=pswriter;	}		//实现关闭登录程序要进行的操作	  protected void processWindowEvent(WindowEvent e)          	 {	    super.processWindowEvent(e);	    if (e.getID() == WindowEvent.WINDOW_CLOSING) {	    				try {				if(socket!=null&&!socket.isClosed()){					socket.close();					socket=null;				}				if(bufreader!=null)					bufreader.close();				if(pswriter!=null)					pswriter.close();			} catch (IOException e1) {				// TODO Auto-generated catch block				e1.printStackTrace();			}			System.exit(0);	    }	  }	  private void starttestButtonActionPerformed(ActionEvent evt) {		  String info="SUBJECT:";		  info=new String(info.getBytes());		  pswriter.println(info);		  pswriter.flush();		  String returninfo = null;		  try {			returninfo=bufreader.readLine();		} catch (IOException e) {			// TODO Auto-generated catch block			e.printStackTrace();		}		if(returninfo==null){			JOptionPane.showMessageDialog(null,"与服务器的连接已经中断,请重新连接","连接中断",JOptionPane.ERROR_MESSAGE);			reconnectButton.setEnabled(true);			reconnectMenuItem.setEnabled(true);			return ;		}		  String[] subjects=returninfo.split("#_#");		  subjectcombobox.removeAllItems();		  subjectcombobox.addItem("全部");		  if(subjects.length>0)			  if("SUBJECT".equals(subjects[0]))				  for(int i=1;i<subjects.length;i++)					  subjectcombobox.addItem(subjects[i]);		  submitbt.setEnabled(true);		  mainPanel.removeAll();		  mainPanel.setLayout(new BorderLayout());		  mainPanel.add(titlepanel,BorderLayout.NORTH);		  centerpanel.removeAll();		  centerpanel.validate();		  mainPanel.add(centerpanel,BorderLayout.CENTER);		  mainPanel.validate();		  mainPanel.repaint();	  }	  private void scoreAccountButtonActionPerformed(ActionEvent evt) {		  JOptionPane.showMessageDialog(null,"你当前成绩:"+testscore,"联机测试系统",JOptionPane.INFORMATION_MESSAGE);		  System.out.println("你当前成绩:"+testscore);	  }	  private void reconnectButtonActionPerformed(ActionEvent evt) {		    String id=Login.id;	  	  	String ps=Login.ps;		  	String status=Login.status;		  	String serverip=Login.serverip;		  	int serverport=Login.serverport;		  	    		  	try {		  		if(socket!=null&&!socket.isClosed())		  			socket.close();		  		bufreader.close();		  		pswriter.close();		  		socket=new Socket(serverip,serverport);		  		bufreader=new BufferedReader(new InputStreamReader(socket.getInputStream()));				pswriter=new PrintWriter(socket.getOutputStream());								String st="LOGIN:"+id+":"+ps+":"+status;   				st=new String(st.getBytes());   				pswriter.println(st);				pswriter.flush();				reconnectButton.setEnabled(false);				reconnectMenuItem.setEnabled(false);				new Thread(){public void run(){					String loginfostring = "";					try {						loginfostring = bufreader.readLine();					} catch (IOException e) {						// TODO Auto-generated catch block						if(socket!=null&&!socket.isClosed())							System.out.println(e.getMessage());						reconnectButton.setEnabled(true);						reconnectMenuItem.setEnabled(true);					}					if(loginfostring==null){						JOptionPane.showMessageDialog(null,"网络不通或者服务器没开启服务","连接失败",JOptionPane.ERROR_MESSAGE);						reconnectButton.setEnabled(true);						reconnectMenuItem.setEnabled(true);					}					else if("LOGINSUCC".equals(loginfostring)){						JOptionPane.showMessageDialog(null,"重新连接成功","连接成功",JOptionPane.INFORMATION_MESSAGE);					}					else if("ALREADYONLINE".equals(loginfostring)){						JOptionPane.showMessageDialog(null,"你已经在线了,不能重复登录","登录失败",JOptionPane.ERROR_MESSAGE);						reconnectButton.setEnabled(true);						reconnectMenuItem.setEnabled(true);					}				}}.start();						  	 } catch (Exception e1) {					// TODO Auto-generated catch block		  		 	JOptionPane.showMessageDialog(null,"网络连接失败,请检查网络设置以及目标主机服务是否启动","登录失败",JOptionPane.ERROR_MESSAGE);		  		 	reconnectButton.setEnabled(true);					reconnectMenuItem.setEnabled(true);		  		 	if(socket!=null&&!socket.isClosed())						try {							socket.close();						} catch (IOException e) {							System.out.println(e.getMessage());						}		  		 	System.out.println(e1.getMessage());		  	 		}				        System.out.println("id--"+id);		        System.out.println("ps--"+ps);		        System.out.println("state--"+status);		        System.out.println("ip--"+serverip);		        System.out.println("port--"+serverport);		        System.out.println("reconnect");	  }	private void exitMenuItemActionPerformed(ActionEvent evt) {		try {			if(socket!=null&&!socket.isClosed()){				socket.close();				socket=null;			}			if(bufreader!=null)				bufreader.close();			if(pswriter!=null)				pswriter.close();		} catch (IOException e1) {			// TODO Auto-generated catch block			e1.printStackTrace();		}                                             		System.exit(0);	}	//随即生成下一道题	public static void NextItem()         	{	   if(unfinishitem>0){		   //随即抽取未回答过的题目		   int randomindex=0;		   while(true){			   randomindex=(int)(Math.random()*itemsnumber);			   if((randomindex>=0)&&(randomindex<itemsnumber)&&(itemstate[randomindex]==1)){				   itemstate[randomindex]=0;

⌨️ 快捷键说明

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