成都创新互联网站制作重庆分公司

java窗体代码登录界面 java实现登陆窗口

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

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

左贡ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!

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怎么实现QQ登录界面?

用java做QQ登录界面的写法如下:

package ch10;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

1、//定义该类继承自JFrame,实现ActionListener接口

public class LoginTest extends JFrame implements ActionListener

{

2、//创建JPanel对象

private JPanel jp=new JPanel();

3、//创建3个标并加入数组

JLabel name = new JLabel("请输入用户名");

JLabel password = new JLabel("请输入密码");

JLabel show = new JLabel("");

private JLabel[] jl={name,password,show};

4、//创建登陆和重置按扭并加入数组

JButton login = new JButton("登陆");

JButton reset = new JButton("重置");

private JButton[] jb={login,reset};

5、//创建文本框以及密码框

private JTextField jName=new JTextField();

private JPasswordField jPassword =new JPasswordField();

public LoginTest()

{

6、//设置布局管理器为空布局,这里自己摆放按钮、标签和文本框

jp.setLayout(null);

for(int i=0;i2;i++)

{

7、//设置标签和按扭的位置与大小

jl[i].setBounds(30,20+40*i,180,20);

jb[i].setBounds(30+110*i,100,80,20);

8、//添加标签和按扭到JPanel容器中

jp.add(jl[i]);

jp.add(jb[i]);

//为2个按钮注册动作事件监听器

jb[i].addActionListener(this);

}

9、//设置文本框的位置和大小,注意满足美观并足够用户名的长度

jName.setBounds(130,15,100,20);

10、//添加文本框到JPanel容器中

jp.add(jName);

11、//为文本框注册动作事件监听器

jName.addActionListener(this);

12、//设置密码框的位置和大小,注意满足美观和足够密码的长度

jPassword.setBounds(130,60,100,20);

13、//添加密码框到JPanel容器中

jp.add(jPassword);

14、//设置密码框中的回显字符,这里设置美元符号

jPassword.setEchoChar('$');

15、//为密码框注册动作事件监听器

jPassword.addActionListener(this);

16、//设置用于显示登陆状态的标签大小位置,并将其添加进JPanel容器

jl[2].setBounds(10,180,270,20);

jp.add(jl[2]);

17、//添加JPanel容器到窗体中

this.add(jp);

18、//设置窗体的标题、位置、大小、可见性及关闭动作

this.setTitle("登陆窗口");

this.setBounds(200,200,270,250);

this.setVisible(true);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

19、//实现动作监听器接口中的方法actionPerformed

public void actionPerformed(ActionEvent e)

{

20、//如果事件源为文本框

if(e.getSource()==jName)

{

21、//切换输入焦点到密码框

jPassword.requestFocus();

}

22、//如果事件源为重置按扭

else if(e.getSource()==jb[1])

{

23、//清空姓名文本框、密码框和show标签中的所有信息

jl[2].setText("");

jName.setText("");

jPassword.setText("");

24、//让输入焦点回到文本框

jName.requestFocus();

}

25、//如果事件源为登陆按钮,则判断登录名和密码是否正确

else

{

26、//判断用户名和密码是否匹配

if(jName.getText().equals("lixiangguo")

String.valueOf(jPassword.getPassword()).equals("19801001"))

{

27、jl[2].setText("登陆成功,欢迎您的到来!");

}

else

{

28、jl[2].setText("对不起,您的用户名或密码错误!");

}

}

}

public static void main(String[] args)

{

29、//创建LoginTest窗体对象

new LoginTest();

}

}

Java制作一个用户登录的窗口

Java用户登陆这块,主要还是类:

1,边界布局:BorderLayout。他主要分为五个布局,是JFrame(顶层容器),JDialog(创建对话框窗口的类)的默认布局方式。其最多容量为5个组件,超出5个得用其他的。设置方式为:BorderLayout.NORTH;BorderLayout.SOUTH;BorderLayout.CENTER;Borderlayout.CENTER;BorderLayout.LEFT;BorderLayout.RIGHT。

2,流式布局:FlowLayout。布局方式为从左到右,从上到下。是JPanel(轻量级容器)的默认面板布局。

3,网格布局:GridLayout。布局方式为行和列组成的网络。布局方法:setLayout(new

GridLayout(3,2,3,3));其中强两位数字表示三行两列,后两位表示行与行的间距为3,列与列的间距为3.

接着,就接触到JPanel面板。JPanel是非顶层容器,所以,一个界面只能由一个JFrame,但是可以有多个JPanel组件。其默认布局方式为流式布局。在JPanel这块,学到了用户登录界面的设计。从而接触到另外三个组件:文本框组件:JTextField;密码框组件:JPasswordField;标签组件:JLabel;复选框组件:JCheckBox;单选框组件:JRadioButton;按钮组件JButton。

用java程序编写一个简单的登录界面

import javax.swing.JFrame;//框架

import javax.swing.JPanel;//面板

import javax.swing.JButton;//按钮

import javax.swing.JLabel;//标签

import javax.swing.JTextField;//文本框

import java.awt.Font;//字体

import java.awt.Color;//颜色

import javax.swing.JPasswordField;//密码框

import java.awt.event.ActionListener;//事件监听

import java.awt.event.ActionEvent;//事件处理

import javax.swing.JOptionPane;//消息窗口public class UserLogIn extends JFrame{

public JPanel pnluser;

public JLabel lbluserLogIn;

public JLabel lbluserName;

public JLabel lbluserPWD;

public JTextField txtName;

public JPasswordField pwdPwd;

public JButton btnSub;

public JButton btnReset;

public UserLogIn(){

pnluser = new JPanel();

lbluserLogIn = new JLabel();

lbluserName = new JLabel();

lbluserPWD = new JLabel();

txtName = new JTextField();

pwdPwd = new JPasswordField();

btnSub = new JButton();

btnReset = new JButton();

userInit();

}

public void userInit(){

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭框架的同时结束程序

this.setSize(300,200);//设置框架大小为长300,宽200

this.setResizable(false);//设置框架不可以改变大小

this.setTitle("用户登录");//设置框架标题

this.pnluser.setLayout(null);//设置面板布局管理

this.pnluser.setBackground(Color.cyan);//设置面板背景颜色

this.lbluserLogIn.setText("用户登录");//设置标签标题

this.lbluserLogIn.setFont(new Font("宋体",Font.BOLD | Font.ITALIC,14));//设置标签字体

this.lbluserLogIn.setForeground(Color.RED);//设置标签字体颜色

this.lbluserName.setText("用户名:");

this.lbluserPWD.setText("密 码:");

this.btnSub.setText("登录");

this.btnReset.setText("重置");

this.lbluserLogIn.setBounds(120,15,60,20);//设置标签x坐标120,y坐标15,长60,宽20

this.lbluserName.setBounds(50,55,60,20);

this.lbluserPWD.setBounds(50,85,60,25);

this.txtName.setBounds(110,55,120,20);

this.pwdPwd.setBounds(110,85,120,20);

this.btnSub.setBounds(85,120,60,20);

this.btnSub.addActionListener(new ActionListener()//匿名类实现ActionListener接口

{

public void actionPerformed(ActionEvent e){

btnsub_ActionEvent(e);

}

}

);

this.btnReset.setBounds(155,120,60,20);

this.btnReset.addActionListener(new ActionListener()//匿名类实现ActionListener接口

{

public void actionPerformed(ActionEvent e){

btnreset_ActionEvent(e);

}

}

);

this.pnluser.add(lbluserLogIn);//加载标签到面板

this.pnluser.add(lbluserName);

this.pnluser.add(lbluserPWD);

this.pnluser.add(txtName);

this.pnluser.add(pwdPwd);

this.pnluser.add(btnSub);

this.pnluser.add(btnReset);

this.add(pnluser);//加载面板到框架

this.setVisible(true);//设置框架可显

}

public void btnsub_ActionEvent(ActionEvent e){

String name = txtName.getText();

String pwd = String.valueOf(pwdPwd.getPassword());

if(name.equals("")){

JOptionPane.showMessageDialog(null,"账号不能为空","错误",JOptionPane.ERROR_MESSAGE);

return;

}else if (pwd.equals("")){

JOptionPane.showMessageDialog(null,"密码不能为空","错误",JOptionPane.ERROR_MESSAGE);

return;

}else if(true){

this.dispose();

}else{

JOptionPane.showMessageDialog(null,"账号或密码错误","错误",JOptionPane.ERROR_MESSAGE);

return;

}

}

public void btnreset_ActionEvent(ActionEvent e){

txtName.setText("");

pwdPwd.setText("");

}

public static void main(String[] args){

new UserLogIn();

}

}

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

import java.awt.*; \x0d\x0aimport javax.swing.*; \x0d\x0aimport java.awt.event.*; \x0d\x0aimport java.sql.*; \x0d\x0a\x0d\x0aclass LoginFrm extends JFrame implements ActionListener \x0d\x0a{ \x0d\x0aJLabel lbl1=new JLabel("用户名"); \x0d\x0aJLabel lbl2=new JLabel("密码"); \x0d\x0aJTextField txt=new JTextField(15); \x0d\x0aJPasswordField pf=new JPasswordField(); \x0d\x0aJButton btn1=new JButton("确定"); \x0d\x0aJButton btn2=new JButton("取消"); \x0d\x0a\x0d\x0apublic LoginFrm() \x0d\x0a{ \x0d\x0athis.setTitle("登陆"); \x0d\x0aJPanel jp=(JPanel)this.getContentPane(); \x0d\x0ajp.setLayout(new GridLayout(3,2,10,10)); \x0d\x0ajp.add(lbl1);jp.add(txt); \x0d\x0ajp.add(lbl2);jp.add(pf); \x0d\x0ajp.add(btn1);jp.add(btn2); \x0d\x0abtn1.addActionListener(this); \x0d\x0abtn2.addActionListener(this); \x0d\x0a} \x0d\x0a\x0d\x0apublic void actionPerformed(ActionEvent ae) \x0d\x0a{ \x0d\x0aif(ae.getSource()==btn1) \x0d\x0a{ \x0d\x0atry \x0d\x0a{ \x0d\x0aClass.forName("sun.jdbc.odbc.JdbcOdbcDriver"); \x0d\x0aConnection con=DriverManager.getConnection("jdbc:odbc:MyDB","",""); \x0d\x0aStatement cmd=con.createStatement(); \x0d\x0aResultSet rs=cmd.executeQuery("select * from loginAndpassword where login='"+txt.getText()+"' and password='"+pf.getText()+"'"); \x0d\x0aif(rs.next()) \x0d\x0a{ \x0d\x0aJOptionPane.showMessageDialog(null,"登陆成功!"); \x0d\x0a} \x0d\x0aelse \x0d\x0aJOptionPane.showMessageDialog(null,"用户名或密码错误!"); \x0d\x0a} catch(Exception ex){} \x0d\x0a\x0d\x0aif(ae.getSource()==btn2) \x0d\x0a{ \x0d\x0atxt.setText(""); \x0d\x0apf.setText(""); \x0d\x0a} \x0d\x0a} \x0d\x0a} \x0d\x0a\x0d\x0apublic static void main(String arg[]) \x0d\x0a{ \x0d\x0aJFrame.setDefaultLookAndFeelDecorated(true); \x0d\x0aLoginFrm frm=new LoginFrm(); \x0d\x0afrm.setSize(400,200); \x0d\x0afrm.setVisible(true); \x0d\x0a} \x0d\x0a}


文章题目:java窗体代码登录界面 java实现登陆窗口
标题URL:http://cxhlcq.com/article/hphodh.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部