可以應用百度Hi通知我們
目前創(chuàng)新互聯(lián)已為上千家的企業(yè)提供了網(wǎng)站建設、域名、網(wǎng)站空間、成都網(wǎng)站托管、企業(yè)網(wǎng)站設計、宜君網(wǎng)站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
有機會可以解決你的問題
具體的要求也可以通知我們
求一個java注冊登錄的完整代碼
ES:\\F5D630A212EA1B5B7E68A1BCCF1CD15E
你要先學會截圖哦,你發(fā)的看不清楚,重新寫了一個你參考參考!
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";// 數(shù)據(jù)庫驅(qū)動 String URL = "jdbc:mysql://localhost:3306/mydata?useUnicode=truecharacterEncoding=gb2312";// String DBNAME = "root";// 用戶名 String DBPASS = "341341";// 密碼 try { Class.forName(DRIVER).newInstance();// 注冊驅(qū)動 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("數(shù)據(jù)庫關(guān)閉時出現(xiàn)異常"); } }}
你這個不用數(shù)據(jù)庫真的是有點難搞
我寫了個用集合存儲的,你看看,能否幫上你
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();
}
}
}