3.JAVA中登录窗口设计,源代码该怎么写【java怎么写登入代码】import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Test_Login extends javax.swing.JFrame {private JPanel jPanel1;private JButton bntLogin;private JButton bntCannel;private JPasswordField pwd;private JTextField username;private JLabel jLabel2;private JLabel jLabel1;public static void main(String[] args) { Test_Login inst = new Test_Login(); inst.setLocationRelativeTo(null); inst.setVisible(true);}public Test_Login() { super(); initGUI();}private void initGUI() { try { (WindowConstants.DISPOSE_ON_CLOSE); { jPanel1 = new JPanel(); getContentPane().add(jPanel1, BorderLayout.CENTER); jPanel1.setLayout(null); { jLabel1 = new JLabel(); jPanel1.add(jLabel1); jLabel1.setText("用户名"); jLabel1.setBounds(45, 30, 75, 25); } { jLabel2 = new JLabel(); jPanel1.add(jLabel2); jLabel2.setText("密码"); jLabel2.setBounds(45, 75, 55, 15); } { username = new JTextField(); jPanel1.add(username); username.setBounds(100, 30, 140, 25); } { pwd = new JPasswordField(); jPanel1.add(pwd); pwd.setBounds(100, 70, 140, 25); } { bntLogin = new JButton(); jPanel1.add(bntLogin); bntLogin.setText("登陆"); bntLogin.setBounds(40, 120, 60, 30); bntLogin.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (username.getText().equals("lisong") && pwd.getText().equals("lisong")) { JOptionPane.showMessageDialog(Test_Login.this,"登录成功"); } else { JOptionPane.showMessageDialog(Test_Login.this,"登录失败"); } } }); bntCannel = new JButton(); jPanel1.add(bntCannel); bntCannel.setText("取消"); bntCannel.setBounds(180, 120, 60, 30); bntCannel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { System.exit(0); } }); } } pack(); setSize(300, 215); } catch (Exception e) { e.printStackTrace(); }}} 。
4.谁能写出JAVA中用户登陆的代码import java.awt.*; import javax.swing.*; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import db.DBAccess; import java.sql.ResultSet; import java.sql.*; public class login extends JFrame { DBAccess da=new DBAccess(); public login() { try { jbInit(); } catch (Exception exception) { exception.printStackTrace(); } } private void jbInit() throws Exception { getContentPane().setLayout(null); jLabel3.setText("用户名"); jLabel3.setBounds(new Rectangle(50, 67, 89, 40)); uname.setBounds(new Rectangle(176, 67, 106, 37)); upwsd.setBounds(new Rectangle(170, 119, 106, 37)); jToggleButton1.setText("取消"); jToggleButton1.setBounds(new Rectangle(184, 214, 96, 32)); jToggleButton1.addActionListener(new login_jToggleButton1_actionAdapter(this)); jToggleButton2.setText("登陆"); jToggleButton2.setBounds(new Rectangle(39, 214, 96, 32)); jToggleButton2.addActionListener(new login_jToggleButton2_actionAdapter(this)); this.getContentPane().add(uname); this.getContentPane().add(upwsd); this.getContentPane().add(jToggleButton1); this.getContentPane().add(jToggleButton2); this.getContentPane().add(jLabel3); this.getContentPane().add(jLabel2); jLabel2.setText("密码"); jLabel2.setBounds(new Rectangle(47, 116, 89, 40)); } JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JTextField uname = new JTextField(); JTextField upwsd = new JTextField(); JToggleButton jToggleButton1 = new JToggleButton(); JToggleButton jToggleButton2 = new JToggleButton(); public void jToggleButton1_actionPerformed(ActionEvent e) { this.dispose(); } public void jToggleButton2_actionPerformed(ActionEvent e) { String name=uname.getText(); String pwsd=upwsd.getText(); try { ResultSet rs = da.getResultSet("select * from login where name='" + name + "' and pwsd='" + pwsd + "'"); if(rs.next()) { JOptionPane.showConfirmDialog(this,"登陆成功"); } else { JOptionPane.showConfirmDialog(this,"登陆失败"); } } catch (SQLException ex) { ex.printStackTrace(); } } } class login_jToggleButton2_actionAdapter implements ActionListener { private login adaptee; login_jToggleButton2_actionAdapter(login adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jToggleButton2_actionPerformed(e); } } class login_jToggleButton1_actionAdapter implements ActionListener { private login adaptee; login_jToggleButton1_actionAdapter(login adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jToggleButton1_actionPerformed(e); } } 。
- 电脑没声音怎么弄 电脑没声音怎么办win7
- cf怎么截图 CF游戏中怎么截图
- qq空间访问权限 手机怎么设置qq空间访问权限
- 鱼肉馅饺子怎么做 鱼肉馅饺子做法视频
- 怎么开葡萄酒 怎么开葡萄酒木塞小妙招
- 洗龙沟是什么意思 洗龙沟是什么意思衣机里面太脏了怎么办
- wow使命召唤怎么做 使命召唤怎么弄
- 文件隐藏了怎么恢复 windows文件隐藏了怎么恢复
- 英雄联盟查战斗力 英雄联盟怎么查战斗力
- 安卓手机如何省电 安卓手机怎么节省电量