可以应用百度Hi通知我们
目前创新互联已为上千家的企业提供了网站建设、域名、网站空间、成都网站托管、企业网站设计、宜君网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
有机会可以解决你的问题
具体的要求也可以通知我们
求一个java注册登录的完整代码
ES:\\F5D630A212EA1B5B7E68A1BCCF1CD15E
你要先学会截图哦,你发的看不清楚,重新写了一个你参考参考!
import java.awt.GridLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class Day30A extends JFrame {
private static final long serialVersionUID = 1L;
private JLabel labelName,labelId,labelPass,labelMoney,labelSelect,labelCar;
private JComboBoxString jcb;
private JPanel jp1,jp2,jp3,jp4,jp5,jp6,jp7;
private ButtonGroup btg;
private JRadioButton jr1,jr2;
Day30A(){
this.setTitle("注册账户");
this.setLayout(new GridLayout(7,1));
this.setSize(300,280);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
init();
this.setVisible(true);
}
private void init() {
String str="卡片类型1,卡片类型2,卡片类型3,卡片类型4,卡片类型5";
jcb=new JComboBox(str.split(","));
labelId=new JLabel("账号: ");
labelName=new JLabel("姓名: ");
labelPass=new JLabel("密码: ");
labelMoney=new JLabel("开户金额:");
labelSelect=new JLabel("存款类型:");
labelCar=new JLabel("卡片类型:");
addFun1();
addFun2();
}
private void addFun2() {
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.add(jp4);
this.add(jp5);
this.add(jp6);
this.add(jp7);
}
private void addFun1() {
jp1=new JPanel();
jp1.add(labelId);
jp1.add(new JTextField(15));
jp2=new JPanel();
jp2.add(labelName);
jp2.add(new JTextField(15));
jp3=new JPanel();
jp3.add(labelPass);
jp3.add(new JTextField(15));
jp4=new JPanel();
jp4.add(labelMoney);
jp4.add(new JTextField(13));
jp5=new JPanel();
jp5.add(labelSelect);
btg=new ButtonGroup();
jr1=new JRadioButton("定期");
jr2=new JRadioButton("活期",true);
btg.add(jr1);
btg.add(jr2);
jp5.add(jr1);
jp5.add(jr2);
jp6=new JPanel();
jp6.add(labelCar);
jp6.add(jcb);
jp7=new JPanel();
jp7.add(new JButton("确定"));
jp7.add(new JButton("取消"));
}
public static void main(String[] args) {
new Day30A();
}
}
package cc.icoc.javaxu.dao;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class MySQLOprea { /** * 增加记录 INSERT INTO 表名(字段名,字段名) VALUES (值,值); * 删除记录 DELETE FROM 表名 WHERE 条件() * 修改记录 UPDATE 表名 SET 字段=值,字段=值 WHERE 条件 * 查询记录 SELECT 字段,字段 FROM 表名 WHERE 条件 */ ResultSet rs = null; Connection conn = null; Statement statement = null; //链接 public Connection connSQL() { String DRIVER = "com.mysql.jdbc.Driver";// 数据库驱动 String URL = "jdbc:mysql://localhost:3306/mydata?useUnicode=truecharacterEncoding=gb2312";// String DBNAME = "root";// 用户名 String DBPASS = "341341";// 密码 try { Class.forName(DRIVER).newInstance();// 注册驱动 conn = DriverManager.getConnection(URL, DBNAME, DBPASS); statement = conn.createStatement(); } catch (Exception e) {} return conn; } //增 /** * 插入新记录的操作 * @param table 表名 * @param userName 插入的用户名 * @param passWord 插入的用户密码 * @return true代表插入成功,false代表插入失败 */ public String insert(String table, String userName, String passWord) { connSQL(); String s = "注册成功"; try { String insert = "insert into "+table+"(userName,passWord) values ("+"'"+userName+"'"+","+"'"+passWord+"'"+")"; statement.executeUpdate(insert); closeDB(); } catch (Exception e) { // TODO: handle exception s = "注册失败"+e.toString(); } return s; } //删 public void delete(String table, String whereValue) throws SQLException { String delete = "Delete from "+table+" where userName = "+whereValue; statement.executeUpdate(delete); } //改 public void update(String table, String whereValue , String newValue) throws SQLException { String update = "Update "+table+" set passWord ="+newValue+" where userName ="+whereValue; statement.executeUpdate(update); } //查 public String query(String table , String whereValue1 ,String whereValue2, String whatCol1, String whatCol2) throws SQLException { connSQL(); String query = null;// ResultSet set= null; try { query = "select "+whatCol1+","+whatCol2+" from "+table +" where "+whatCol1+"="+'"'+whereValue1+'"'+" and "+whatCol2+"="+'"'+whereValue2+'"'; rs = statement.executeQuery(query); closeDB(); } catch (Exception e) { // TODO: handle exception return "false exception:"+e.toString(); } if(rs.next()) { return "true:"; } return "false:"; } private void closeDB() { // TODO Auto-generated method stub try { if(rs != null) { rs.close(); } if(statement != null) { statement.close(); } if(conn != null) { conn.close(); } } catch (Exception e) { // TODO: handle exception System.out.println("数据库关闭时出现异常"); } }}
你这个不用数据库真的是有点难搞
我写了个用集合存储的,你看看,能否帮上你
java.util.ListString list = new ArrayListString();
list.add("qq=123");//存储的时候用(用户名=密码)的形式
list.add("ww=456");
String username = "qq";
String password = "123";
for (int i = 0; i list.size(); i++) {
String num = username +"="+password;
if(num.equals(list.get(i))){
System.out.println("登录成功");
break;
}
}
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 {
setDefaultCloseOperation(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();
}
}
}