你要先学会截图哦,你发的看不清楚,重新写了一个你参考参考!
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;
private static final long serialVersionUID = 1L;
private JLabel labelName,labelId,labelPass,labelMoney,labelSelect,labelCar;
private JComboBoxString jcb;
private ButtonGroup btg;
this.setTitle("注册账户");
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
init();
this.setVisible(true);
}
private void init() {
jcb=new JComboBox(str.split(","));
labelId=new JLabel("账号:");
labelName=new JLabel("姓名:");
labelPass=new JLabel("密码:");
labelMoney=new JLabel("开户金额:");
labelSelect=new JLabel("存款类型:");
labelCar=new JLabel("卡片类型:");
addFun1();
this.add(jp1);
private void addFun1() {
jp1=new JPanel();
jp1.add(labelId);
btg=new ButtonGroup();
jr1=new JRadioButton("定期");
btg.add(jr1);
public static void main(String[] args) {
分三个包,自己建个包,导进去就ok了,数据库是access的.
package 登录;
import java.awt.EventQueue;
public class Cilent {
private JFrame frame;
private JTextField textField;
private JPasswordField passwordField;
/**
* Launch the application.
*/
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Cilent window = new Cilent();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
});
* Create the application.
public Cilent() {
initialize();
* Initialize the contents of the frame.
private void initialize() {
frame = new JFrame();
frame.setTitle("登陆界面");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setResizable(false);
JLabel lblNewLabel = new JLabel("用户名");
frame.getContentPane().add(lblNewLabel);
textField = new JTextField();
frame.getContentPane().add(textField);
textField.setColumns(10);
JLabel label = new JLabel("密 码");
frame.getContentPane().add(label);
passwordField = new JPasswordField();
frame.getContentPane().add(passwordField);
JButton btnNewButton = new JButton("登 录");
frame.getContentPane().add(btnNewButton);
btnNewButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
UserCheck UC=new UserCheck(textField.getText(),String.valueOf(passwordField.getPassword()));
if(UC.getI()!=0) //有此用户
{
frame.setVisible(false);
else
textField.setText("");
passwordField.setText("");
JButton button = new JButton("取 消");
frame.getContentPane().add(button);
button.addActionListener(new ActionListener() {
/*****************************************************************/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import 操作处理.UsersCL;
* 检测登录的用户在数据库中有无,若没有,则提示没有此用户,
* 若有,则判断级别:普通用户还是管理员.
public class UserCheck {
UserCheck(String name ,String password)
String jdriver="sun.jdbc.odbc.JdbcOdbcDriver";
String connectDB="jdbc:odbc:Students";
Statement stmt=null;
ResultSet rs=null;
Connection con=null;
Class.forName(jdriver);
con=DriverManager.getConnection(connectDB);
stmt=con.createStatement();
String query="select * from users where name='"+name+"' and passwd='"+password+"'";
rs=stmt.executeQuery(query);
if(rs.next())
//数据库中有此用户,访问成功
UsersCL UL=new UsersCL(i);
i=0; //没有用户是默认是0级
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
} catch (SQLException e) {
public int getI() {
return i;
/********************************************************************************************/
package 操作处理;
public class UsersCL implements ActionListener{
private JTextField textField_1;
private int i=0;
public UsersCL(int i) {
this.i=i;
frame.setTitle("用户处理界面");
frame.setVisible(true);
JLabel lblNewLabel = new JLabel("学 号");
JLabel label = new JLabel("姓 名");
JLabel label_1 = new JLabel("年 龄");
frame.getContentPane().add(label_1);
textField_1 = new JTextField();
textField_1.setColumns(10);
frame.getContentPane().add(textField_1);
if(1==i)
JButton btnNewButton = new JButton("追 加");
btnNewButton.addActionListener(this);
btnNewButton.setActionCommand("追加");
JButton button_1 = new JButton("删 除");
frame.getContentPane().add(button_1);
button_1.addActionListener(this);
button_1.setActionCommand("删除");
JButton button = new JButton("查 询");
button.addActionListener(this);
button.setActionCommand("查询");
public void actionPerformed(ActionEvent e) {
String name,age,sex,query=null;
int num,age1,count=0;
num=Integer.parseInt(textField.getText());
name=textField_1.getText();
if(e.getActionCommand().equals("追加"))
query="insert into students values("+num+","+"'"+name+"',"+age1+",'"+sex+"');";
count=1;
else if(e.getActionCommand().equals("查询"))
query="select * from students where XSB="+num+";";
else if(e.getActionCommand().equals("删除"))
query="delete from students where XSB="+num+" and name="+"'"+name+"'";
String query1=null;
if(count==1)
query1="select * from students where XSB="+num+";";
rs=stmt.executeQuery(query1);
stmt.executeUpdate(query);
stmt.executeQuery(query);
query1="select * from students where XSB="+num+" and name="+"'"+name+"'";
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (SQLException e1) {
finally{
//关闭资源
if(stmt!=null){
stmt.close();
// TODO: handle exception
stmt=null;
if(con!=null){
con.close();
con=null;
import?java.awt.Dimension;
import?java.awt.Toolkit;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?javax.swing.JButton;
import?javax.swing.JFrame;
import?javax.swing.JLabel;
import?javax.swing.JOptionPane;
import?javax.swing.JPasswordField;
import?javax.swing.JTextField;
public?static?void?main(String[]?args)?{
final?String?userName?=?"abc";
JFrame?jFrame?=?new?JFrame("登陆界面");
Dimension?dimension?=?Toolkit.getDefaultToolkit().getScreenSize();
jFrame.setResizable(false);
jFrame.setLayout(null);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel?label1?=?new?JLabel("姓名");
jFrame.add(label1);
final?JTextField?text1?=?new?JTextField();
jFrame.add(text1);
JButton?button?=?new?JButton("Login");
button.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?e)?{
JOptionPane.showMessageDialog(null,?"登陆成功误",?"提示",?JOptionPane.INFORMATION_MESSAGE);
}?else?{
JOptionPane.showMessageDialog(null,?"错误",?"提示",?JOptionPane.ERROR_MESSAGE);
text1.setText("");
jFrame.add(button);
jFrame.setVisible(true);
我有一个微信公众号,经常会分享一些Java技术相关的干货,还有一些学习资源.
如果你喜欢我的分享,可以用微信搜索"Java团长"或者"javatuanzhang"关注.
用java做QQ登录界面的写法如下:
package ch10;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
①.、//定义该类继承自JFrame,实现ActionListener接口
public class LoginTest extends JFrame implements ActionListener
private JPanel jp=new JPanel();
JLabel name = new JLabel("请输入用户名");
JLabel password = new JLabel("请输入密码");
JLabel show = new JLabel("");
private JLabel[] jl={name,password,show};
JButton login = new JButton("登陆");
JButton reset = new JButton("重置");
private JButton[] jb={login,reset};
private JTextField jName=new JTextField();
private JPasswordField jPassword =new JPasswordField();
public LoginTest()
jp.setLayout(null);
jp.add(jl[i]);
jp.add(jb[i]);
jb[i].addActionListener(this);
①.0、//添加文本框到JPanel容器中
jp.add(jName);
①.1、//为文本框注册动作事件监听器
jName.addActionListener(this);
jp.add(jPassword);
jPassword.setEchoChar('$');
jPassword.addActionListener(this);
this.add(jp);
this.setTitle("登陆窗口");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
public void actionPerformed(ActionEvent e)
if(e.getSource()==jName)
jPassword.requestFocus();
else if(e.getSource()==jb[1])
jName.setText("");
jPassword.setText("");
jName.requestFocus();
if(jName.getText().equals("lixiangguo")
public static void main(String[] args)
new LoginTest();
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JPasswordField;
public class Login {
private JFrame frame = new JFrame("登录");
private Container c = frame.getContentPane();
private JTextField username = new JTextField();
private JPasswordField password = new JPasswordField();
private JButton ok = new JButton("确定");
private JButton cancel = new JButton("取消");
public Login(){
c.setLayout(new BorderLayout());
initFrame();
private void initFrame() {
//顶部
JPanel titlePanel = new JPanel();
titlePanel.setLayout(new FlowLayout());
titlePanel.add(new JLabel("系统管理员登录"));
c.add(titlePanel,"North");
//中部表单
JPanel fieldPanel = new JPanel();
fieldPanel.setLayout(null);
JLabel l1 = new JLabel("用户名:");
fieldPanel.add(l1);
fieldPanel.add(username);
fieldPanel.add(password);
c.add(fieldPanel,"Center");
//底部按钮
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
buttonPanel.add(ok);
buttonPanel.add(cancel);
c.add(buttonPanel,"South");
public static void main(String[] args){
new Login();
import java.sql.*;
class LoginFrm extends JFrame implements ActionListener
JLabel lbl1=new JLabel("用户名");
JPasswordField pf=new JPasswordField();
JButton btn1=new JButton("确定");
public LoginFrm()
this.setTitle("登陆");
JPanel jp=(JPanel)this.getContentPane();
jp.add(lbl1);jp.add(txt);
btn1.addActionListener(this);
public void actionPerformed(ActionEvent ae)
if(ae.getSource()==btn1)
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:MyDB","","");
Statement cmd=con.createStatement();
ResultSet rs=cmd.executeQuery("select * from loginAndpassword where login='"+txt.getText()+"' and password='"+pf.getText()+"'");
JOptionPane.showMessageDialog(null,"登陆成功!");
JOptionPane.showMessageDialog(null,"用户名或密码错误!");
} catch(Exception ex){}
txt.setText("");
pf.setText("");
public static void main(String arg[])
JFrame.setDefaultLookAndFeelDecorated(true);
LoginFrm frm=new LoginFrm();
frm.setVisible(true);
以上就是土嘎嘎小编为大家整理的java界面登录代码相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!