導航:首頁 > 源碼編譯 > 與賬號登錄java源碼

與賬號登錄java源碼

發布時間:2022-08-10 12:06:57

⑴ 關於用java下載需要輸入賬戶和密碼的網站上的網頁,怎麼實現

http://..com/question/120327079.html

⑵ 求一個用Java寫的登陸界面的源代碼,輸入用戶名,密碼,登錄後顯示歡迎登錄,加分

這個是我之前做著玩的,只做了個登錄,不要介意,登錄名:admin,密碼:admin。

⑶ java 登錄注冊界面代碼怎麼寫不鏈接資料庫。不用mysql !

給你提供個思路吧
1、注冊界面把注冊的人的用戶名和密碼存儲到本地的一個txt文件中
2、登錄時比較登錄輸入的用戶名和密碼和txt文件中的是否一致,如果一致就允許登錄,不一致提示異常

⑷ 急求一段簡單的java源代碼(用戶名、密碼操作界面)

下面的程序可以直接通過編譯運行,自己尋找要用到的代碼段。

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class UserLogin extends JPanel implements ActionListener{
JTextField userjt=null;//用戶輸入框
JPasswordField pwdjt=null;
JTextField sysUserjt=null;//系統顯示用戶名輸入框
JTextField sysPwdjt=null;
public UserLogin(){
super(new GridLayout(1,2));
JPanel userPanel=new JPanel();//用戶界面,左邊
userPanel.setLayout(new BoxLayout(userPanel,BoxLayout.Y_AXIS));
this.add(userPanel);
JPanel userUpPanel=new JPanel();//用戶界面上半部分
userPanel.add(userUpPanel);
JPanel userDownPanel=new JPanel();//用戶界面下半部分
userPanel.add(userDownPanel);

JPanel sysPanel=new JPanel();//系統界面,右邊
sysPanel.setLayout(new BoxLayout(sysPanel,BoxLayout.Y_AXIS));
this.add(sysPanel);
JPanel sysUserPanel=new JPanel();//系統界面上半部分
sysPanel.add(sysUserPanel);
JPanel sysPwdPanel=new JPanel();//系統界面下半部分
sysPanel.add(sysPwdPanel);

userjt=new JTextField(5);
userjt.setText("用戶名");
userUpPanel.add(userjt);
pwdjt=new JPasswordField(5);
pwdjt.setText("密碼");
pwdjt.setEchoChar('\0');
userDownPanel.add(pwdjt);
JLabel sysUserjl=new JLabel("用戶名為:");
sysUserPanel.add(sysUserjl);
sysUserjt=new JTextField(5);
sysUserPanel.add(sysUserjt);
JLabel sysPwdjl=new JLabel("密碼為:");
sysPwdPanel.add(sysPwdjl);
sysPwdjt=new JTextField(5);
sysPwdPanel.add(sysPwdjt);

userjt.addActionListener(this);
pwdjt.addActionListener(this);
userjt.addFocusListener(new FocusListener(){
public void focusGained(FocusEvent e) {
if(userjt.getText().equals("用戶名"))
userjt.setText("");
}
public void focusLost(FocusEvent e) {
if(userjt.getText().equals(""))
userjt.setText("用戶名");

}});
pwdjt.addFocusListener(new FocusListener(){
public void focusGained(FocusEvent e) {
if(new String(pwdjt.getPassword()).equals("密碼")){
pwdjt.setText("");
pwdjt.setEchoChar('*');
}
}
public void focusLost(FocusEvent e) {
if(new String(pwdjt.getPassword()).equals("")){
pwdjt.setText("密碼");
pwdjt.setEchoChar('\0');
}

}});
}
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(userjt)){
pwdjt.requestFocus();
}else{
if(new String(pwdjt.getPassword()).equals("")||userjt.getText().equals("")||userjt.getText().equals("用戶名")) return;
sysUserjt.setText(userjt.getText());
sysPwdjt.setText(new String(pwdjt.getPassword()));
try {
writetoFile();
} catch (IOException e1) {
System.out.println("寫入文件發生異常!");
e1.printStackTrace();
}
}
}
private void writetoFile() throws IOException{
File f=new File("User_Psd.txt");
// if(!f.exists()) f.createNewFile();
RandomAccessFile accessFile=new RandomAccessFile(f, "rw");
accessFile.seek(accessFile.length());
accessFile.write(("user:"+userjt.getText()+"\r\npassword:"+new String(pwdjt.getPassword())+"\r\n\r\n").getBytes());
}

public static void main(String args[]){
JFrame jf=new JFrame("用戶登陸模塊測試");
jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);
jf.add(new UserLogin());
jf.setBounds(400,300,280,150);
jf.setVisible(true);
}

}

⑸ 用JAVA語言編程實現一個用戶登錄窗口

方法一:
採用JOptionPane中的一個非常有用的靜態方法 showOptionPane();
源碼如下:
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JOptionPane;
import javax.swing.BoxLayout;
import javax.swing.Box;
import javax.swing.BorderFactory;
public class Login1 {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
static void createAndShowGUI() {
JFrame mainFrame = new JFrame();
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setBounds(250,250,400,300);
mainFrame.setVisible(false);
usernameField = new JTextField(10);
passwordField = new JPasswordField(10);
Object[] options = {"登錄","取消"};
int i = JOptionPane.showOptionDialog(null,createLoginPanel(),"登錄信息",JOptionPane.DEFAULT_OPTION,JOptionPane.PLAIN_MESSAGE,null,options,options[0]);
if(i==0) {
String username = usernameField.getText();
String password = passwordField.getText();
if(!username.equals("") && !password.equals("")) {
mainFrame.getContentPane().add(new JLabel("用戶名:"+username+" 密碼是:"+password,JLabel.CENTER));
mainFrame.show();
}
else {
JOptionPane.showMessageDialog(null,"用戶名和密碼不能為空","提示",JOptionPane.WARNING_MESSAGE);
System.exit(1);
}
}
else System.exit(0);
}
static JPanel createLoginPanel() {
JPanel ret = new JPanel();

JPanel usernamePanel = new JPanel();
usernamePanel.add(new JLabel("用戶名:",JLabel.RIGHT));
usernamePanel.add(usernameField);
JPanel passwordPanel = new JPanel();
passwordPanel.add(new JLabel("密 碼:",JLabel.RIGHT));
passwordPanel.add(passwordField);

Box box = new Box(BoxLayout.Y_AXIS);
box.add(usernamePanel); box.add(passwordPanel);
ret.add(box);

ret.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(new Color(244,144,44)),"填寫登錄信息"));
return ret;
}
static JFrame mainFrame = null;
static JTextField usernameField = null;
static JPasswordField passwordField = null;
}
運行:
javac -deprecation Login1.java
java Login
(因為有一個過期的API,所以用了 -deprecation 命令

方法二,使用了兩個JFrame類共同實現,第一次顯示第一個frame,當點了登錄後且操作合法時,第一個窗口就被釋放了 dispose();再顯示第二個窗口:
源碼如下:
import java.awt.Color;
import java.awt.BorderLayout;
import java.awt.event.*;
import javax.swing.*;
public class Login2 {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
static void createAndShowGUI() {
//////////////////////////////////////////////////////////////
loginWindow = new JFrame("登錄信息");
loginWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
loginWindow.setBounds(350,350,250,200);
loginWindow.setResizable(false);
JPanel usernamePanel = new JPanel();
usernamePanel.add(new JLabel("用戶名:",JLabel.CENTER));
usernamePanel.add(usernameField);

JPanel passwordPanel = new JPanel();
passwordPanel.add(new JLabel("密 碼:",JLabel.CENTER));
passwordPanel.add(passwordField);
Box box = new Box(BoxLayout.Y_AXIS);
box.add(usernamePanel); box.add(passwordPanel);
JPanel infoPanel = new JPanel();
infoPanel.add(box);
infoPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(new Color(244,144,44)),"填寫登錄信息"));
JButton submitButton = new JButton("登錄");
JButton cancelButton = new JButton("取消");
submitButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
String username = usernameField.getText();
String password = passwordField.getText();

if(!username.equals("") && !password.equals("")) {
loginWindow.dispose();
mainFrame.getContentPane().add(new JLabel("用戶名:"+username+" 密碼是:"+password,JLabel.CENTER));
mainFrame.setVisible(true);
}
else {
JOptionPane.showMessageDialog(null,"用戶名和密碼不能為空","提示",JOptionPane.WARNING_MESSAGE);
System.exit(1);
}
}
});
cancelButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
JPanel buttonPanel = new JPanel();
buttonPanel.add(submitButton); buttonPanel.add(cancelButton);
loginWindow.getContentPane().add(infoPanel,BorderLayout.CENTER);
loginWindow.getContentPane().add(buttonPanel,BorderLayout.SOUTH);
loginWindow.getContentPane().add(new JPanel(),BorderLayout.EAST);
loginWindow.getContentPane().add(new JPanel(),BorderLayout.WEST);
loginWindow.setVisible(true);
/////////////////////////////////////////////////////////////////
mainFrame = new JFrame();
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setBounds(250,250,400,300);
mainFrame.setVisible(false);
}
static JFrame loginWindow,mainFrame;
static final JTextField usernameField = new JTextField(10);
static final JPasswordField passwordField = new JPasswordField(10);
}
運行:
javac -deprecation Login2.java
java Login2

⑹ 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 {
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();
}
}
}

⑺ 求Java 注冊登錄 連接到資料庫的源代碼。

package cc.icoc.javaxu.;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=true&characterEncoding=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 ee源碼,最好賦上詳細注釋。j2ee初學者 謝謝!

昨天貌似有人問過類似的問題,給你個你自己看看合不合要求,我自己寫的,可以給個採納吧親

⑼ 用java可以做qq登錄界面,那個源代碼怎麼寫

源碼:http://wenku..com/view/4b03494ccf84b9d528ea7a26.html

閱讀全文

與與賬號登錄java源碼相關的資料

熱點內容
如何理解php面向對象 瀏覽:96
macword轉pdf 瀏覽:848
python列表求交集 瀏覽:872
解壓包如何轉音頻 瀏覽:447
機明自動編程軟體源碼 瀏覽:325
php埠號設置 瀏覽:541
phperegreplace 瀏覽:320
androidgridview翻頁 瀏覽:537
ssh協議編程 瀏覽:634
如何開我的世界電腦伺服器地址 瀏覽:861
玄關pdf 瀏覽:609
程序員學習論壇 瀏覽:940
程序員的毒雞湯怎麼做 瀏覽:548
安卓怎麼降級軟體到手機 瀏覽:281
雲與伺服器入門書籍推薦產品 瀏覽:636
delphi編程助手 瀏覽:762
電腦遇到伺服器問題怎麼辦 瀏覽:515
加工中心編程結束方法 瀏覽:296
了解什麼是web伺服器 瀏覽:140
面向對象的編程的基本特徵 瀏覽:718