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

📄 techgui.java

📁 在线考试系统设计
💻 JAVA
字号:
/*
 * 创建日期 2006-4-16
 * 作者: 褚廷军
 * 项目名称:学生考试系统;
 * 项目要求:毕业设计;
 * 模块名称:客户端教师查询模块
 * 模块功能:考试系统的客户端教师查询界面
 *          教师登录,查询所有学生信息,查询某个学生信息
 
 */

package client;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.Socket;

import javax.swing.*;
import javax.swing.border.*;

public class TechGui extends JFrame implements ActionListener {
	private String user, pass;

	private JLabel tuserLabel;

	private TextField techName;

	private JLabel tpassLabel;

	private JPasswordField techPass;

	private JButton techButton;

	private JMenuBar jmb;

	private JMenu fmenu;

	private JMenu hmenu;

	private JMenuItem exit;

	private JMenuItem version;

	private JLabel stateLabel;

	private TextField stateField;

	private Box bottomBox;

	private JLabel dispTime;

	private JLabel bottom;

	private Box mainBox;

	private JLabel TQLabel;

	private JButton TQButton;

	private TextField TQField;

	private JLabel ipLabel;

	private TextField ipField;

	private JScrollPane jsp;

	private Box tqueryBox;

	private Box stateBox;

	private JToolBar toolbar1;

	private JDialog searchStu;

	public TechGui() {
		// 教师登录

		super("学生考试系统(教师版)");
		JFrame.setDefaultLookAndFeelDecorated(true);
		Toolkit tool = getToolkit();
		Image ima = tool.getImage("tubiao.jpg");
		setIconImage(ima);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.runFinalization();

			}
		});

		setMenubar();
		setJMenuBar(jmb);
		topbarSetting();
		setBottomBox();
		setMainBox();

		Container con1 = getContentPane();

		con1.add(stateBox, BorderLayout.NORTH);
		con1.add(mainBox, BorderLayout.CENTER);
		con1.add(bottomBox, BorderLayout.SOUTH);
		setSize(800, 600);
		setLocation(100, 100);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		System.out.println("************欢迎进入教师查询系统***************");
		setVisible(true);

	}

	public void setMenubar() {
		jmb = new JMenuBar();
		fmenu = new JMenu("管理");

		exit = new JMenuItem("退出", 'x');
		exit.addActionListener(this);
		exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
				InputEvent.ALT_MASK));

		fmenu.add(exit);

		hmenu = new JMenu("帮助");
		version = new JMenuItem("版本");
		version.addActionListener(this);
		hmenu.add(version);

		jmb.add(fmenu);

		jmb.add(hmenu);
	}

	private void topbarSetting() {

		toolbar1 = new JToolBar("two");

		stateBox = Box.createHorizontalBox();

		stateLabel = new JLabel("状 态:");
		stateLabel.setFont(new Font("楷体_GB2312", Font.BOLD, 16));
		stateLabel.setForeground(Color.RED);
		stateField = new TextField("欢迎你进入考试系统,请先登陆,然后选择服务", 20);
		stateField.setFont(new Font("宋体", Font.BOLD, 16));
		stateField.setForeground(Color.RED);
		stateField.setEditable(false);

		stateBox.add(Box.createHorizontalStrut(150));
		stateBox.add(stateLabel);
		stateBox.add(stateField);
		stateBox.add(Box.createHorizontalGlue());

		toolbar1.add(stateBox);
	}

	public void setMainBox() {

		Box ipBox = Box.createHorizontalBox();
		ipLabel = new JLabel("呼叫IP");
		ipField = new TextField(20);
		ipField.setText("127.0.0.1");
		ipBox.add(ipLabel);
		ipBox.add(ipField);

		Box tuserBox = Box.createHorizontalBox();

		tuserLabel = new JLabel("用户名");
		techName = new TextField(20);
		tpassLabel = new JLabel("密码");
		techPass = new JPasswordField(20);
		techButton = new JButton("呼叫");
		techButton.setEnabled(true);
		techButton.addActionListener(this);

		tuserBox.add(tuserLabel);
		tuserBox.add(techName);
		tuserBox.add(tpassLabel);
		tuserBox.add(techPass);
		tuserBox.add(techButton);

		JPanel jp1 = new JPanel();
		jp1.add(ipBox);
		jp1.add(tuserBox);

		// 教师查询

		TQLabel = new JLabel("请输入查询条件果全选则输入:“all”");// 信息查询区
		TQLabel.setFont(new Font("楷体_GB2312", Font.LAYOUT_RIGHT_TO_LEFT, 16));
		TQLabel.setForeground(Color.BLUE);
		TQLabel.setVisible(false);
		TQField = new TextField();
		TQField.setVisible(false);
		TQButton = new JButton("查询");
		TQButton.setVisible(false);
		TQButton.addActionListener(this);
		tqueryBox = Box.createVerticalBox();
		// tqueryBox.setVisible(false);
		tqueryBox.add(TQLabel);
		tqueryBox.add(Box.createVerticalStrut(10));
		tqueryBox.add(TQField);
		tqueryBox.add(Box.createVerticalStrut(10));
		tqueryBox.add(TQButton);
		JPanel jp2 = new JPanel();
		jp2.add(tqueryBox);

		mainBox = Box.createVerticalBox();

		Border border = BorderFactory.createTitledBorder(BorderFactory
				.createLineBorder(Color.BLACK, 1), "学生考试系统",
				TitledBorder.CENTER, TitledBorder.ABOVE_TOP, new Font(
						"楷体_GB2312", Font.BOLD, 28), Color.BLACK);
		mainBox.setBorder(border);

		mainBox.add(jp1);
		mainBox.add(jp2);

	}

	public void setBottomBox() {

		bottomBox = Box.createHorizontalBox();
		dispTime = new JLabel();
		dispTime.setHorizontalAlignment(JLabel.LEFT);
		dispTime.setForeground(Color.BLACK);

		bottom = new JLabel();
		bottom.setHorizontalAlignment(JLabel.RIGHT);
		bottom.setText("ctj_2制作   济南大学   计算0207    2002091048    &^-^&   ");

		bottomBox.add(bottom);
		bottomBox.add(dispTime);
		ActionListener time = new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				dispTime.setText(new java.util.Date().toString());
			}
		};
		new Timer(1000, time).start();

	}

	public void actionPerformed(ActionEvent e) {
		String ip = ipField.getText().trim();

		user = techName.getText().trim();

		pass = techPass.getText().trim();

		Socket socket = null;
		DataInputStream in = null;
		DataOutputStream out = null;
		if (e.getSource() == techButton) {

			if (socket != null && in != null && out != null) // 消除以往的连接信息
			{
				try {
					socket.close();
					in.close();
					out.close();

				} catch (Exception ee) {

				}
			}

			String login = user + "," + pass;
			String queryS = TQField.getText().trim();
			int port5 = 8005;
			try {
				socket = new Socket(ip, port5);
				in = new DataInputStream(socket.getInputStream());
				out = new DataOutputStream(socket.getOutputStream());

				out.writeUTF(login);
				out.writeUTF(queryS);
			} catch (IOException ee) // 如果连接失败
			{
				ipField.setText("呼叫失败");
				stateField.setText("你呼叫没有成功");
			}
			if (socket != null) // 如果连接成功
			{

				try {

					String loginInfo = in.readUTF().trim();
					if (!loginInfo.equals("密码错误")) {

						stateField.setText(loginInfo);
						TQLabel.setVisible(true);
						TQField.setVisible(true);
						TQButton.setVisible(true);

					}

					else {
						stateField.setText(loginInfo);
						techPass.setText("");
						techName.setText("请重新输入用户名和密码!");

					}
				} catch (IOException e1) {

				}
			}
		}

		if (e.getSource() == TQButton) {
			if (socket != null && in != null && out != null) // 消除以往的连接信息
			{
				try {
					socket.close();
					in.close();
					out.close();

				} catch (Exception ee) {

				}
			}

			String queryS = TQField.getText().trim();
			int port6 = 8006;
			try {
				socket = new Socket(ip, port6);
				in = new DataInputStream(socket.getInputStream());
				out = new DataOutputStream(socket.getOutputStream());
				out.writeUTF(queryS);
				String readIn;
				readIn = in.readUTF() + "\n";

				System.out.println(readIn);
				searchStu = new JDialog(this, "查询学生信息", true);
				Container con2 = searchStu.getContentPane();

				JTextArea taver = new JTextArea();
				taver.append(readIn);
				jsp = new JScrollPane(taver);
				con2.add(jsp);
				searchStu.setLocation(400, 400);
				searchStu.setSize(600, 200);
				searchStu.addWindowListener(new WindowAdapter() {
					public void windowClosing(WindowEvent e) {
						searchStu.dispose();
					}
				});
				searchStu.show();

			} catch (IOException ee) // 如果连接失败
			{
				ee.printStackTrace();
				ipField.setText("呼叫失败");
				stateField.setText("你呼叫没有成功");
			}
		}
		if (e.getSource() == version) {
			JOptionPane.showMessageDialog(null, "ctj_2制作    &^-^& ",
					"version1.0", JOptionPane.INFORMATION_MESSAGE);

		}
		if (e.getSource() == exit) {

			int temp = JOptionPane.showConfirmDialog(null, "您确认要关闭吗?", "确认对话框",
					JOptionPane.YES_NO_OPTION);
			if (temp == JOptionPane.YES_OPTION) {
				dispose();
				} else if (temp == JOptionPane.NO_OPTION) {
				return;
			}

		}
	}

	public static void main(String s[]) {
		JFrame.setDefaultLookAndFeelDecorated(true);
		new TechGui();
	}
}

⌨️ 快捷键说明

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