📄 frm.java~1~
字号:
package 数据库;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 javax.swing.border.*;import one_piece.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class Frm extends JFrame { JPanel contentPane; XYLayout xYLayout1 = new XYLayout(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JTextField username = new JTextField(); JTextField score = new JTextField(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); Connection conn=null; Statement sttm=null; String sql=""; ResultSet rs=null; int SCORE; String thescore; QueryDataSet queryDataSet1=new QueryDataSet(); Database dataBase1=new Database(); JButton jButton3 = new JButton(); Border border1; Border border2; Border border3; JLabel jLabel3 = new JLabel(); //Construct the frame public Frm(int l) { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { SCORE = l; thescore = String.valueOf(SCORE); score.setText(thescore); jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { contentPane = (JPanel) this.getContentPane(); border1 = BorderFactory.createMatteBorder(6,6,6,6,SystemColor.menuText); border2 = BorderFactory.createMatteBorder(6,6,6,6,SystemColor.textText); border3 = BorderFactory.createMatteBorder(6,6,6,6,SystemColor.controlText); jLabel1.setFont(new java.awt.Font("Dialog", 0, 15)); jLabel1.setText("玩家姓名:"); contentPane.setLayout(xYLayout1); this.setSize(new Dimension(400, 282)); this.setTitle("排行榜"); jLabel2.setFont(new java.awt.Font("Dialog", 0, 15)); jLabel2.setText("游戏得分:"); jButton1.setBackground(Color.blue); jButton1.setFont(new java.awt.Font("Dialog", 0, 15)); jButton1.setBorder(border1); jButton1.setText("进入排行榜"); jButton1.addActionListener(new Frm_jButton1_actionAdapter(this)); jButton2.setBackground(Color.blue); jButton2.setFont(new java.awt.Font("Dialog", 0, 15)); jButton2.setBorder(border2); jButton2.setText("查看排行榜"); jButton2.addActionListener(new Frm_jButton2_actionAdapter(this)); username.setText(""); score.setEnabled(true); score.setEditable(false); jButton3.setBackground(Color.blue); jButton3.setFont(new java.awt.Font("Dialog", 0, 15)); jButton3.setBorder(border3); jButton3.setText("退出"); jButton3.addActionListener(new Frm_jButton3_actionAdapter(this)); contentPane.setBackground(Color.blue); jLabel3.setIcon(new ImageIcon(new java.net.URL("file:///E:/Picture/shuju.gif"))); jLabel3.setText("jLabel3"); contentPane.add(jLabel1, new XYConstraints(52, 33, 80, 44)); contentPane.add(jLabel2, new XYConstraints(49, 94, 88, 39)); contentPane.add(username, new XYConstraints(156, 40, 136, 34)); contentPane.add(score, new XYConstraints(158, 95, 136, 36)); contentPane.add(jButton1, new XYConstraints(42, 156, 128, 37)); contentPane.add(jButton2, new XYConstraints(242, 154, 130, 37)); contentPane.add(jButton3, new XYConstraints(169, 207, 74, -1)); contentPane.add(jLabel3, new XYConstraints(0, 0, -1, -1)); } //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 jButton2_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()); }/////////////////////////////////// sql="select top 10 * from niao order by score desc"; // FrmPhb phb=new FrmPhb(); Frame2 phb=new Frame2(); phb.sql=sql; phb.setLocation(200,200); phb.setSize(250,400); phb.show(); try { conn.close(); sttm.close(); } catch(SQLException er) { System.out.println(er.getMessage()); } } 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 niao where name='"+username.getText().trim()+"'";//判断此用户是否已经存在于本数据库中 //sql="select * from paihangbang where name="+"'"+username.getText().trim()+"'"; rs=sttm.executeQuery(sql); rs.absolute(1); if(!rs.isFirst())//如果不存在此用户,则插入数据 { sql="insert into niao 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 niao 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 { conn.close(); sttm.close(); rs.close(); } catch(SQLException er) { System.out.println(er.getMessage()); } } void jButton3_actionPerformed(ActionEvent e) {this.dispose(); }}class Frm_jButton2_actionAdapter implements java.awt.event.ActionListener { Frm adaptee; Frm_jButton2_actionAdapter(Frm adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton2_actionPerformed(e); }}class Frm_jButton1_actionAdapter implements java.awt.event.ActionListener { Frm adaptee; Frm_jButton1_actionAdapter(Frm adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); }}class Frm_jButton3_actionAdapter implements java.awt.event.ActionListener { Frm adaptee; Frm_jButton3_actionAdapter(Frm adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton3_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -