📄 netscorereportframe.java~5~
字号:
package ct;import javax.swing.*;import java.awt.*;import com.borland.jbcl.layout.*;import java.awt.event.*;import com.borland.dbswing.*;import com.borland.dx.sql.dataset.*;import java.sql.*;//public class netScoreReportFrame extends JFrame { JLabel username = new JLabel(); XYLayout xYLayout1 = new XYLayout(); JLabel score = new JLabel(); JLabel o_username = new JLabel(); JLabel o_score = new JLabel(); JButton jButton1 = new JButton(); /////////////////////////////////////////////////////////////// Connection conn=null;// Statement sttm=null; String sql=""; ResultSet rs=null; QueryDataSet queryDataSet1 = new QueryDataSet(); Database database1 = new Database(); public netScoreReportFrame() { try { //jLabel1.setText(name); // jLabel2.setText(String.valueOf(m_score)); // jLabel3.setText(enemyname); // jLabel4.setText(String.valueOf(m_enemyscore)); jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { username.setFont(new java.awt.Font("Dialog", 0, 14)); username.setForeground(Color.magenta); username.setText("你的分数为:"); this.getContentPane().setLayout(xYLayout1); o_username.setFont(new java.awt.Font("Dialog", 0, 14)); o_username.setForeground(Color.red); o_username.setText("对手的分数为:"); score.setFont(new java.awt.Font("Dialog", 0, 14)); score.setForeground(Color.magenta); score.setText(""); o_score.setFont(new java.awt.Font("Dialog", 0, 14)); o_score.setForeground(Color.red); o_score.setText(""); xYLayout1.setWidth(308); xYLayout1.setHeight(172); jButton1.setText("确定"); jButton1.addActionListener(new netScoreReportFrame_jButton1_actionAdapter(this)); this.getContentPane().add(username, new XYConstraints(10, 10, 90, 30)); this.getContentPane().add(score, new XYConstraints(120, 10, 100, 30)); this.getContentPane().add(o_username, new XYConstraints(10, 50, 90, 30)); this.getContentPane().add(o_score, new XYConstraints(120, 50, 100, 30)); this.getContentPane().add(jButton1, new XYConstraints(70, 100, 100, 30)); } void jButton1_actionPerformed(ActionEvent e) { /////////////////////////////////////// try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); try { conn=DriverManager.getConnection("jdbc:odbc:xqy"); 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()); }///////////////////////////////////////////////////// try { sql="select * from paihangbang where name='"+username.getText().trim()+"'";//判断此用户是否已经存在于本数据库中 rs=sttm.executeQuery(sql); rs.absolute(1); if(!rs.isFirst())//如果不存在此用户,则插入数据 { sql="insert into paihangbang values ('"+username.getText().trim()+"','"+score.getText().trim()+"')"; int i=sttm.executeUpdate(sql); if(i==1) { JOptionPane.showConfirmDialog(null,"成功进入排行榜","恭喜",JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE); dispose(); } else { JOptionPane.showConfirmDialog(null,"进入成功排行榜","提示",JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE); } } else//如果此用户已经存在,则更新用户的成绩 { int newscore=Integer.parseInt(score.getText().toString()); int oldscore=rs.getInt(2); System.out.println(score); if(oldscore<newscore)//当用户已经存在是,我们要判断此次分数是否比原来的分数高 { sql = "update paihangbang set score='" + newscore + "'where name='" + username.getText().trim() + "'"; int i = sttm.executeUpdate(sql); if (i == 1) { JOptionPane.showConfirmDialog(null, "成功进入排行榜", "恭喜", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE); dispose(); } else { JOptionPane.showConfirmDialog(null, "进入成功排行榜", "提示", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE); } } else { JOptionPane.showConfirmDialog(null, "还要继续加油哦", "加油", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE); } } } catch(SQLException ee) { System.out.println(ee.getMessage()); }///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////// try { sql="select * from paihangbang where name='"+o_username.getText().trim()+"'";//判断此用户是否已经存在于本数据库中 rs=sttm.executeQuery(sql); rs.absolute(1); if(!rs.isFirst())//如果不存在此用户,则插入数据 { sql="insert into paihangbang values ('"+o_username.getText().trim()+"','"+o_score.getText().trim()+"')"; int i=sttm.executeUpdate(sql); if(i==1) { JOptionPane.showConfirmDialog(null,"成功进入排行榜","恭喜",JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE); dispose(); } else { JOptionPane.showConfirmDialog(null,"进入成功排行榜","提示",JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE); } } else//如果此用户已经存在,则更新用户的成绩 { int newscore=Integer.parseInt(o_score.getText().toString()); int oldscore=rs.getInt(2); System.out.println(o_score); if(oldscore<newscore)//当用户已经存在是,我们要判断此次分数是否比原来的分数高 { sql = "update paihangbang set score='" + newscore + "'where name='" + o_username.getText().trim() + "'"; int i = sttm.executeUpdate(sql); if (i == 1) { JOptionPane.showConfirmDialog(null, "成功进入排行榜", "恭喜", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE); dispose(); } else { JOptionPane.showConfirmDialog(null, "进入成功排行榜", "提示", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE); } } else { JOptionPane.showConfirmDialog(null, "还要继续加油哦", "加油", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE); } } } catch(SQLException ee) { System.out.println(ee.getMessage()); } try { conn.close(); sttm.close(); rs.close(); } catch(SQLException er) { System.out.println(er.getMessage()); } this.dispose(); } public void showQrryList(){ try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); try { conn=DriverManager.getConnection("jdbc:odbc:xqy"); 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"; dataBase1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:odbc:xqy", "", "", false, "sun.jdbc.odbc.JdbcOdbcDriver")); queryDataSet1.setQuery(new QueryDescriptor(dataBase1,sql,null,true,Load.ALL)); QuerryList qlist=new QuerryList(); qlist.jdbTable1.setDataSet(queryDataSet1); qlist.setLocation(330,180); qlist.setSize(320,380); qlist.show(); try { conn.close(); sttm.close(); } catch(SQLException er) { System.out.println(er.getMessage()); } }}class netScoreReportFrame_jButton1_actionAdapter implements java.awt.event.ActionListener { netScoreReportFrame adaptee; netScoreReportFrame_jButton1_actionAdapter(netScoreReportFrame adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -