📄 serverframe.java~1~
字号:
package serverframe;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.borland.jbcl.layout.*;import java.sql.*;import com.borland.dx.sql.dataset.*;import com.borland.dbswing.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2006</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class ServerFrame extends JFrame //implements ActionListener{ JPanel contentPane; Button CloseServer; ServerThread sThread; XYLayout xYLayout1 = new XYLayout(); JScrollPane jScrollPane1 = new JScrollPane(); JTextArea ServerStatus = new JTextArea(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); String[] name1=new String[6]; String[] score1=new String[6]; Connection conn=null; Statement sttm=null; String sql=""; ResultSet rs=null; //Database database1 = new Database(); // QueryDataSet queryDataSet1 = new QueryDataSet(); JButton jButton3 = new JButton(); ClientThread clithr; JScrollPane jScrollPane2 = new JScrollPane(); JTextArea jTextArea1 = new JTextArea();//客户端处理线程 //Construct the frame public ServerFrame() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); //this.accessinput(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(xYLayout1); this.setSize(new Dimension(400, 366)); this.setTitle("服务器!"); ServerStatus.setToolTipText(""); ServerStatus.setText(""); jButton1.setText("关闭服务器"); jButton1.addActionListener(new ServerFrame_jButton1_actionAdapter(this)); jButton2.setText("打开服务器"); jButton2.addActionListener(new ServerFrame_jButton2_actionAdapter(this)); jButton3.setText("查看数据库"); jButton3.addActionListener(new ServerFrame_jButton3_actionAdapter(this)); contentPane.add(jScrollPane1, new XYConstraints(4, 5, 389, 91)); contentPane.add(jScrollPane2, new XYConstraints(4, 102, 385, 108)); contentPane.add(jButton1, new XYConstraints(4, 222, 119, 34)); contentPane.add(jButton2, new XYConstraints(134, 223, 112, 32)); contentPane.add(jButton3, new XYConstraints(259, 222, 123, 32)); jScrollPane2.getViewport().add(jTextArea1, null); jScrollPane1.getViewport().add(ServerStatus, null); } public void init() { sThread = new ServerThread(this); sThread.start();//开启服务器线程 this.ServerStatus.setText("等待连接.........."+"\n"); }public void accessinput()//显示数据库 { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); try { conn=DriverManager.getConnection("jdbc:odbc:game"); sttm=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); } catch(SQLException eu) { System.out.println(eu.getMessage()); } } catch(ClassNotFoundException ey) { System.out.println(ey.getMessage()); } sql="select top 10 * from paihangbang order by score desc"; try{ rs=sttm.executeQuery(sql); rs.absolute(1); } catch(SQLException e){e.printStackTrace();} } //Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void jButton1_actionPerformed(ActionEvent e) { this.dispose(); System.exit(0); } void jButton2_actionPerformed(ActionEvent e) { this.init(); jButton2.setEnabled(false); } void jButton3_actionPerformed(ActionEvent e) {this.accessinput(); this.jTextArea1.setText("");// database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:odbc:game", "", "", false, "sun.jdbc.odbc.JdbcOdbcDriver"));// queryDataSet1.setQuery(new QueryDescriptor(database1,sql,null,true,Load.ALL)); for(int i=0;i<6;i++) { try{ name1[i]=rs.getString("name"); score1[i]=rs.getString("score"); rs.next(); this.jTextArea1.append("............"+name1[i]+"===================="+score1[i]+"\n");//显示数据库内容 }catch(Exception e1){e1.printStackTrace();} } }}class ServerFrame_jButton1_actionAdapter implements java.awt.event.ActionListener { ServerFrame adaptee; ServerFrame_jButton1_actionAdapter(ServerFrame adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); }}class ServerFrame_jButton2_actionAdapter implements java.awt.event.ActionListener { ServerFrame adaptee; ServerFrame_jButton2_actionAdapter(ServerFrame adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton2_actionPerformed(e); }}class ServerFrame_jButton3_actionAdapter implements java.awt.event.ActionListener { ServerFrame adaptee; ServerFrame_jButton3_actionAdapter(ServerFrame adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton3_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -