java代码实现qq界面 java仿登录界面简洁( 二 )


//按钮
JButton myJButton1 = new JButton("确认");
JButton myJButton2 = new JButton("重置");
JButton myJButton3 = new JButton("注册");
//背景色
myJPanel.setBackground(Color.getHSBColor(212, 223, 23));
//设置面板布局
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
myJPanel.setLayout(gridbag);
MyLayout myLay = new MyLayout();
myLay.buildConstraints(constraints, 0, 0, 1, 1, 20, 35);
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.CENTER;
gridbag.setConstraints(myJLabel1, constraints);
myLay.buildConstraints(constraints, 1, 0, 1, 1, 80, 0);
constraints.fill = GridBagConstraints.HORIZONTAL;
gridbag.setConstraints(myJTextField1, constraints);
myLay.buildConstraints(constraints, 0, 1, 1, 1, 0, 25);
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.CENTER;
gridbag.setConstraints(myJLabel2, constraints);
myLay.buildConstraints(constraints, 1, 1, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.HORIZONTAL;
gridbag.setConstraints(myJPasswordField1, constraints);
myLay.buildConstraints(constraints, 0, 2, 1, 1, 33, 25);
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.CENTER;
gridbag.setConstraints(myJLabel3, constraints);
myLay.buildConstraints(constraints, 1, 2, 1, 1, 33, 0);
constraints.fill = GridBagConstraints.HORIZONTAL;
gridbag.setConstraints(myJTextField3, constraints);
myLay.buildConstraints(constraints, 2, 2, 1, 1, 34, 0);
constraints.fill = GridBagConstraints.HORIZONTAL;
@SuppressWarnings("unused")
JudgeCode myJudgeCode = new JudgeCode();
gridbag.setConstraints(JudgeCode.judgeCodeLabel, constraints);//验证码
myLay.buildConstraints(constraints, 0, 3, 1, 1, 33, 15);
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.CENTER;
gridbag.setConstraints(myJButton1, constraints);
myLay.buildConstraints(constraints, 1, 3, 1, 1, 33, 0);
constraints.fill = GridBagConstraints.CENTER;
gridbag.setConstraints(myJButton2, constraints);
myLay.buildConstraints(constraints, 2, 3, 1, 1, 34, 0);
constraints.fill = GridBagConstraints.NONE;
gridbag.setConstraints(myJButton3, constraints);
myJPanel.add(myJLabel1);
myJPanel.add(myJTextField1);
myJPanel.add(myJLabel2);
myJPanel.add(myJPasswordField1);
myJPanel.add(myJLabel3);
myJPanel.add(myJTextField3);
myJPanel.add(JudgeCode.judgeCodeLabel);
myJPanel.add(myJButton1);
myJPanel.add(myJButton2);
myJPanel.add(myJButton3);
myJFrame.add(myJPanel, BorderLayout.CENTER);
//确认单击事件
myJButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String username = new String(myJTextField1.getText()); //用户名
String mypassword = new String(myJPasswordField1.getPassword()); //获取密码
/**
* 数据库操作
*/
DataConn dataconn = new DataConn();
String sql = "select * from user_information where name = '"+username+"'";
dataconn.executeQuery(sql);
try {
if(username == null || username == "" || mypassword == null || mypassword == "" || myJTextField3.getText() == null || myJTextField3.getText() == ""){
JOptionPane.showMessageDialog(null, "用户名、密码、验证码不能为空!请重新输入!");
}
else if(!dataconn.rs.next()){
JOptionPane.showMessageDialog(null, "你输入的用户名不存在!请重新输入!");
myJTextField1.setText("");
myJPasswordField1.setText("");
}
else if(!dataconn.rs.getString("password").equals(mypassword))
{

推荐阅读