java代码不连数据库 java实现数据库连接代码( 三 )


.addComponent(jLabel3)
.addComponent(
jTextField2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(43, 43, 43)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE,
33,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jButton2,
javax.swing.GroupLayout.PREFERRED_SIZE,
33,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(48, Short.MAX_VALUE)));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
layout.createSequentialGroup().addContainerGap().addComponent(
jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap()));
layout.setVerticalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
layout.createSequentialGroup().addContainerGap().addComponent(
jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)));
pack();
setLocationRelativeTo(null);//居中
}// /editor-fold
//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//事件处理,不建议这样做
// TODO add your handling code here:
String name = this.jTextField1.getText().trim();//获得用户名,去空格
String password = this.jTextField2.getText().trim();//获得密码,去空格
if (name.equals("admin")password.equals("123456")) {//如果符合条件.....其实这里应该去和数据库关联,这是死代码
//Showinformation sf=new Showinformation();//我估计是另外一个框架 , 就是登录成功之后的框架
//sf.setVisible(true);
//sf.show();//这个方法就直接秒杀 , 不用了,因为sf.setVisible(true)已经被调用了 , 这里就多次一举了
} else {//用户名或者密码验证失败
JOptionPane.showMessageDialog(this, "用户名或者密码错误啦~", "提示",//提示框
JOptionPane.INFORMATION_MESSAGE);
this.jTextField1.setText("");//清空输入框
this.jTextField2.setText("");
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//事件处理 , 其实可以将jButton1ActionPerformed放在一起处理,只要获得按钮的标签内容(JButton)(evt.getSuorse()).getText()就做对比就ko了
// TODO add your handling code here:
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {//好方法,呵呵使用该方式的原因是:awt是单线程模式的,所有awt的组件只能在(推荐方式)事件处理线程中访问 , 从而保证组件状态的可确定性 。java核心编程技术中每个实例基本都用到了
public void run() {
new Main().setVisible(true);
}
});
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;}

推荐阅读