?? servergui.java
字號:
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 + -