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

📄 servergui.java

📁 在线考试系统设计
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		startSer.addActionListener(this);
		leftBox.add(startSer);
		leftBox.add(Box.createVerticalStrut(50));

		serButton = new JButton("显示服务器信息");
		serButton.setFont(font);
		serButton.setToolTipText("click and show server infomation ^-^");
		serButton.setVisible(true);
		serButton.addActionListener(this);
		leftBox.add(serButton);
		leftBox.add(Box.createVerticalStrut(50));

		userButton = new JButton("显示用户信息");
		userButton.setFont(font);
		userButton.setToolTipText("click and show user infomation ^-^");
		userButton.addActionListener(this);
		leftBox.add(userButton);
		leftBox.add(Box.createVerticalStrut(50));

		linkButton = new JButton("显示网络信息");
		linkButton.setFont(font);
		linkButton.setToolTipText("click and show link infomation ^-^");
		linkButton.addActionListener(this);
		leftBox.add(linkButton);
		leftBox.add(Box.createVerticalStrut(50));

		serStop = new JButton("关闭服务器");
		serStop.setFont(font);
		serStop.addActionListener(this);
		serStop.setToolTipText("shut the server ^-^");
		leftBox.add(serStop);
		leftBox.add(Box.createVerticalStrut(50));

		leftBox.add(Box.createVerticalGlue());

		mainBox = Box.createVerticalBox();

		Border border = BorderFactory.createTitledBorder(BorderFactory
				.createLineBorder(Color.BLACK, 2), "服务器端信息显示",
				TitledBorder.CENTER, TitledBorder.ABOVE_TOP, new Font(
						"GB_2312", Font.BOLD, 28), Color.RED);
		mainBox.setBorder(border);

		serLabel = new JLabel("服务器信息");
		serLabel.setToolTipText("show the server infomation ^-^");
		serArea = new JTextArea(5, 20);
    	serArea.setEditable(false);
    	sinfoshow=new JScrollPane(serArea);

		Box serBox = Box.createVerticalBox();
		serBox.add(serLabel);
		serBox.add(Box.createVerticalStrut(10));
		serBox.add(sinfoshow);
		mainBox.add(serBox, BorderLayout.NORTH);
		mainBox.add(Box.createVerticalStrut(20));

		userLabel = new JLabel("用户信息");
		userLabel.setToolTipText("show the user's infomation ^-^");
		userArea = new JTextArea(10, 20);
		userArea.setEditable(false);
		uinfoshow=new JScrollPane(userArea);
		Box userBox = Box.createVerticalBox();
		
		userBox.add(userLabel);
		userBox.add(uinfoshow);

		mainBox.add(userBox, BorderLayout.CENTER);
		mainBox.add(Box.createVerticalStrut(20));

		linkLabel = new JLabel("网络信息");
		linkLabel.setToolTipText("show the link's infomation ^-^");
		linkArea = new JTextArea(5, 20);
		linkArea.setEditable(false);
		linfoshow=new JScrollPane(linkArea);

		Box linkBox = Box.createVerticalBox();
		linkBox.add(linkLabel);
		linkBox.add(Box.createVerticalStrut(20));
		linkBox.add(linfoshow);

		mainBox.add(linkBox, BorderLayout.SOUTH);
		mainBox.add(Box.createVerticalStrut(20));
		jsp = new JScrollPane(mainBox);

		split_one = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, leftBox,
				jsp);
		split_one.setSize(100, 50);
		split_one.setVisible(false);

	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == log) {
			// boolean b=login();
			String username = JOptionPane.showInputDialog(this, "请输入用户名",
					"输入用户名", JOptionPane.QUESTION_MESSAGE).trim();
			String password = JOptionPane.showInputDialog(this, "请输入密码",
					"输入密码", JOptionPane.QUESTION_MESSAGE).trim();
			if (username == null || password == null) {

				username = "temp";
				password = "temp";
				return;
			}

			adminCheck(username, password);// 验证管理员

			if (tf == true) {
				JOptionPane.showMessageDialog(this, "登陆成功!", "成功",
						JOptionPane.INFORMATION_MESSAGE);
				toolBar1.setVisible(true);
				split_one.setVisible(true);
			} else {
				JOptionPane.showMessageDialog(this, "登陆失败!", "失败",
						JOptionPane.ERROR_MESSAGE);
				return;
			}
		} else if (e.getSource() == setCount) {
			userCount = JOptionPane.showInputDialog(this, "请输入本次考试的人数");
			if (userCount == null || userCount.length() == 0) {
				return;
			}

			ServerManager.setMaxcount(Integer.parseInt(userCount));
			setcount = true;
		} else if (e.getSource() == setTime) {
			String temp = JOptionPane.showInputDialog(this,
					"请输入本次考试的时间(以分钟为单位)");
			if (temp == null || temp.length() == 0) {
				return;
			}
			timeCount = Integer.parseInt(temp);
			Server_readTest.setTimecount(timeCount);
			settime = true;
		} else if (e.getSource() == viewdb) {

			new DBshow();

			// new ShowAllStu().setLocation(100, 100);

		} else if (e.getSource() == viewuser) {

			new UserShow();

		} else if (e.getSource() == updatexam) {

			new EditExam();

		} else if (e.getSource() == inittest) {

			inittest(); // 数据库信息初始化

		} else if (e.getSource() == startSer) {
			if (settime == true && setcount == true) {
				new ServerManager();
				serArea.append("服务器已启动\n预设考试人数为:" + userCount + "\n考试时间为:"
						+ timeCount + "\n");
				start = true;

			} else {
				JOptionPane.showMessageDialog(this, "你还没有设置考试信息", "警告信息",
						JOptionPane.INFORMATION_MESSAGE);
			}

		} else if (e.getSource() == serStop) {
			dispose();

		} else if (e.getSource() == serButton) {
			if (start == true)

			{

				serArea.append(ServerManager.serShow(ServerManager.serstatus)
						+ "\n");

			} else {
				JOptionPane.showMessageDialog(this, "服务器还没有启动不能进行操作", "警告信息",
						JOptionPane.INFORMATION_MESSAGE);
			}

		} else if (e.getSource() == linkButton) {

			if (start == true)

			{
				linkArea.append(ServerManager
						.linkShow(ServerManager.linkstatus)
						+ "\n");

			} else {
				JOptionPane.showMessageDialog(this, "服务器还没有启动不能进行操作", "警告信息",
						JOptionPane.INFORMATION_MESSAGE);
			}

		} else if (e.getSource() == userButton) {

			if (start == true)

			{
				userArea.append(ServerManager
						.userShow(ServerManager.userstatus)
						+ "\n");
				userArea.append(ServerManager.countShow(ServerManager.ucount));

			} else {
				JOptionPane.showMessageDialog(this, "服务器还没有启动不能进行操作", "警告信息",
						JOptionPane.INFORMATION_MESSAGE);
			}

		} else if (e.getSource() == version) {
			JOptionPane.showMessageDialog(this, "ctj_2制作    &^-^& ",
					"version 1.0", JOptionPane.INFORMATION_MESSAGE);

		} else if (e.getSource() == exit) {
			int temp = JOptionPane.showConfirmDialog(this, "您确认要关闭吗?", "确认对话框",
					JOptionPane.YES_NO_OPTION);
			if (temp == JOptionPane.YES_OPTION) {
				System.exit(0);

			} else if (temp == JOptionPane.NO_OPTION) {
				return;
			}
		}

	}

	public void adminCheck(String s1, String s2)

	{
		try {


			
		ConnectBean cb=new ConnectBean();
		
		if (!cb.openConnection()) {
			System.out.println("连接数据失败");
			System.exit(1);
			return;
		}
		
		cb.createPreparedStatement("select * from administrator where adname="
							+ "'" + s1 + "'");
		ResultSet rs =cb.executeQuery();
		
			while (rs.next()) {
				if (rs.getString("adpass").equals(s2)) {
					tf = true;
					break;
				} else
					tf = false;
			}
		} catch (Exception e) {
			System.out.println(e);
		}
	}

	public void inittest() {
		ConnectBean cb = new ConnectBean();
		if (!cb.openConnection()) {
			System.out.println("连接数据失败");
			System.exit(1);
			return;
		}
		try {
			cb.createPreparedStatement("update stuinfo set flag=0");

			int temp = cb.executeUpdate();

			cb.close();
			if (!(temp == 1)) {
				JOptionPane.showMessageDialog(this, "学生登录信息初始化成功", "成功",
						JOptionPane.INFORMATION_MESSAGE);
			} else {
				JOptionPane.showMessageDialog(this, "学生登录信息初始化失败", "失败",
						JOptionPane.INFORMATION_MESSAGE);
			}

		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

//	public static void main(String a[]) {
//		JFrame.setDefaultLookAndFeelDecorated(true);
//		new ServerGui();
//
//	}

}

⌨️ 快捷键说明

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