java用户登录界面设计代码(java用户登录界面设计)

http://www.itjxue.com  2023-01-31 16:10  来源:未知  点击次数: 

求JAVA实现用户登录界面代码?

你要先学会截图哦,你发的看不清楚,重新写了一个你参考参考!

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();

}

}

实现界面登陆,退出功能的java代码怎么写?

CS结构系统的退出如下:public void init() {\x0d\x0a this.setTitle("用户登录界面");\x0d\x0a this.add(createCenterPane());\x0d\x0a this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);\x0d\x0a this.setSize(new Dimension(450, 335));\x0d\x0a this.setLocationRelativeTo(null);\x0d\x0a // this.setVisible(true);\x0d\x0a this.addWindowListener(new WindowAdapter() {\x0d\x0a public void windowClosing(WindowEvent e) {\x0d\x0a int choose = JOptionPane.showConfirmDialog(null, "是否要退出登录界面?",\x0d\x0a "系统提示:", JOptionPane.YES_NO_OPTION);\x0d\x0a if (choose == JOptionPane.YES_OPTION) {\x0d\x0a System.exit(1);\x0d\x0a }\x0d\x0a }\x0d\x0a });\x0d\x0a }其中this为JFrame对象。BS结构的退出直接用windows.close()方法就行了!

登陆界面的java代码怎么写?

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.sql.*;

class LoginFrm extends JFrame implements ActionListener

{

JLabel lbl1=new JLabel("用户名");

JLabel lbl2=new JLabel("密码");

JTextField txt=new JTextField(15);

JPasswordField pf=new JPasswordField();

JButton btn1=new JButton("确定");

JButton btn2=new JButton("取消");

public LoginFrm()

{

this.setTitle("登陆");

JPanel jp=(JPanel)this.getContentPane();

jp.setLayout(new GridLayout(3,2,10,10));

jp.add(lbl1);jp.add(txt);

jp.add(lbl2);jp.add(pf);

jp.add(btn1);jp.add(btn2);

btn1.addActionListener(this);

btn2.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()+"'");

if(rs.next())

{

JOptionPane.showMessageDialog(null,"登陆成功!");

}

else

JOptionPane.showMessageDialog(null,"用户名或密码错误!");

} catch(Exception ex){}

if(ae.getSource()==btn2)

{

txt.setText("");

pf.setText("");

}

}

}

public static void main(String arg[])

{

JFrame.setDefaultLookAndFeelDecorated(true);

LoginFrm frm=new LoginFrm();

frm.setSize(400,200);

frm.setVisible(true);

}

}

用java写一个登录界面的代码,哪位大神会啊,谢谢。

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?class?Test26?{

public?static?void?main(String[]?args)?{

final?String?userName?=?"abc";

final?String?passwrod?=?"123";

JFrame?jFrame?=?new?JFrame("登陆界面");

Dimension?dimension?=?Toolkit.getDefaultToolkit().getScreenSize();

jFrame.setBounds(((int)dimension.getWidth()?-?200)?/?2,?((int)dimension.getHeight()?-?300)?/?2,?200,?150);

jFrame.setResizable(false);

jFrame.setLayout(null);

jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JLabel?label1?=?new?JLabel("姓名");

label1.setBounds(10,?10,?100,?30);

jFrame.add(label1);

JLabel?label2?=?new?JLabel("密码");

label2.setBounds(10,?40,?100,?30);

jFrame.add(label2);

final?JTextField?text1?=?new?JTextField();

text1.setBounds(50,?15,?130,?20);

jFrame.add(text1);

final?JPasswordField?text2?=?new?JPasswordField();

text2.setBounds(50,?45,?130,?20);

jFrame.add(text2);

JButton?button?=?new?JButton("Login");

button.setBounds(10,?75,?170,?40);

button.addActionListener(new?ActionListener()?{

@Override

public?void?actionPerformed(ActionEvent?e)?{

if(userName.equals(text1.getText())??passwrod.equals(text2.getText()))?{

JOptionPane.showMessageDialog(null,?"登陆成功误",?"提示",?JOptionPane.INFORMATION_MESSAGE);

}?else?{

JOptionPane.showMessageDialog(null,?"错误",?"提示",?JOptionPane.ERROR_MESSAGE);

text1.setText("");

text2.setText("");

}

}

});

jFrame.add(button);

jFrame.setVisible(true);

}

}

我有一个微信公众号,经常会分享一些Java技术相关的干货,还有一些学习资源。

如果你喜欢我的分享,可以用微信搜索“Java团长”或者“javatuanzhang”关注。

(责任编辑:IT教学网)

更多

推荐Access文章