「java窗口登陆」登录java实现

博主:adminadmin 2022-12-28 21:57:07 55

本篇文章给大家谈谈java窗口登陆,以及登录java实现对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java窗口登录问题

ResultSet rs=st.executeQuery("select * from XTDL where xuehao='"+myckstr+"' and password='"+checkstr+"'");

rs.next();

if(rs.next()){

Statement st1=con.createStatement();

ResultSet rs1=st1.executeQuery("select * from XTDL where quanxian='学生'");

rs1.next();

if(rs1.next()){

myframe1 = new MyJFrame();////登录系统的主窗体

this.setVisible(false);

dispose();

}

Statement st11=con.createStatement();

ResultSet rs11=st11.executeQuery("select * from XTDL where quanxian='老师'");

rs11.next();

if(rs11.next()){

myframe2 = new GengGaiTuBiao();////登录系统的主窗体

this.setVisible(false);

dispose();

}

}

else{

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

tfPass.setText("");

}

}

JAVA 制作登陆窗口

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class Login extends JFrame{

nbsp;public Login() {

nbsp;nbsp;setLayout(new GridLayout(1,2));//网格布局,1行2列,放置左面板和右面板

nbsp;nbsp;setTitle("发表iPhone说说");//设置窗口标题

nbsp;nbsp;setSize(550,300);//设置大小

nbsp;nbsp;setLocationRelativeTo(null);//设置窗口位置

nbsp;nbsp;setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置窗口关闭按钮动作

nbsp;nbsp;//左面板

nbsp;nbsp;JPanel leftPanel = new JPanel();

nbsp;nbsp;leftPanel.setBorder(BorderFactory.createTitledBorder("登录手机腾讯网"));//给左面板加上边框,并添加文字

nbsp;nbsp;leftPanel.setLayout(new BorderLayout());

nbsp;nbsp;JPanel leftPanelTop = new JPanel();

nbsp;nbsp;JPanel leftPanelBottom = new JPanel();

nbsp;nbsp;leftPanel.add(leftPanelTop, BorderLayout.CENTER);

nbsp;nbsp;leftPanel.add(leftPanelBottom, BorderLayout.SOUTH);

nbsp;nbsp;leftPanelTop.setLayout(new GridLayout(3,2));//网格布局,3行2列

nbsp;nbsp;nbsp;nbsp;nbsp;

nbsp;nbsp;//========================请在下面写上你的代码

nbsp;nbsp;JLabel qq = new JLabel("QQ号码");

nbsp;nbsp;JTextField qqNum = new JTextField();

nbsp;nbsp;JLabel pwd = new JLabel("QQ密码");

nbsp;nbsp;JPasswordFieldnbsp; qqPwd = new JPasswordField();

nbsp;nbsp;JLabel verify = new JLabel("验证码");

nbsp;nbsp;JTextField qqVer = new JTextField();

nbsp;nbsp;leftPanelTop.add(qq);

nbsp;nbsp;leftPanelTop.add(qqNum);

nbsp;nbsp;leftPanelTop.add(pwd);

nbsp;nbsp;leftPanelTop.add(qqPwd);

nbsp;nbsp;leftPanelTop.add(verify);

nbsp;nbsp;leftPanelTop.add(qqVer);

nbsp;nbsp;leftPanelBottom.setLayout(new GridLayout(1,2));

nbsp;nbsp;JLabel i_vc = new JLabel(new ImageIcon("images/VerificationCode.jpg"));//这是显示验证码的标签,帮你写好了,后面直接调用即可。

nbsp;nbsp;JButton bt1 = new JButton("帐号密码登陆");

nbsp;nbsp;JButton bt2 = new JButton("带验证码登陆");

nbsp;nbsp;JPanel btPanel = new JPanel();

nbsp;nbsp;btPanel.setLayout(new GridLayout(2,1));

nbsp;nbsp;btPanel.add(bt1);

nbsp;nbsp;btPanel.add(bt2);

nbsp;nbsp;leftPanelBottom.add(i_vc);

nbsp;nbsp;leftPanelBottom.add(btPanel);

nbsp;nbsp;//============================================

nbsp;nbsp;add(leftPanel);//将左面板放入窗体中

nbsp;nbsp;//右面板

nbsp;nbsp;JPanel rightPanel = new JPanel();

nbsp;nbsp;rightPanel.setBorder(BorderFactory.createTitledBorder("发表iPhone说说"));//给右面板加上边框,并添加文字

nbsp;nbsp;//========================请在下面写上你的代码

nbsp;nbsp;JTextArea msg = new JTextArea();

nbsp;nbsp;JButton submit = new JButton("马上发表说说");

nbsp;nbsp;rightPanel.setLayout(new BorderLayout());

nbsp;nbsp;rightPanel.add(msg, BorderLayout.CENTER);

nbsp;nbsp;rightPanel.add(submit, BorderLayout.SOUTH);

nbsp;nbsp;//============================================

nbsp;nbsp;add(rightPanel);//将右面板放入窗体中

nbsp;nbsp;setVisible(true);//使窗体可见

nbsp;}

nbsp;public static void main(String[] args){

nbsp;nbsp;new Login();

nbsp;}

}

用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登陆窗口

用JCreator创建一个JFC工程,会出现两个java文件,只改其中一个就行了.....-------------------------/**

* @(#)TestFrame.java

*

* JFC Test application

*

* @author

* @version 1.00 2010/5/30

*/import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class TestFrame extends JFrame {

/**

* The constructor

*/

public TestFrame() {

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

final JTextField txtUserName = new JTextField(); // 用户名

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

final JPasswordField pwfPassword = new JPasswordField(); // 密码

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

btnLogin.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

if (!txtUserName.getText().equals("111") || !pwfPassword.getText().equals("111")) {

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

} else {

JOptionPane.showMessageDialog(null, "成功登陆", "正确", JOptionPane.INFORMATION_MESSAGE);

}

}

});

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

btnCancel.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

TestFrame.this.windowClosed();

}

}); // Add window listener.

this.addWindowListener

(

new WindowAdapter() {

public void windowClosing(WindowEvent e) {

TestFrame.this.windowClosed();

}

}

);

GroupLayout layout = new GroupLayout(this.getContentPane());

this.getContentPane().setLayout(layout);

layout.setAutoCreateGaps(true);

layout.setAutoCreateContainerGaps(true); GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();

hGroup.addGroup(layout.createParallelGroup().addComponent(lblUserName).addComponent(lblPassword));

hGroup.addGroup(layout.createParallelGroup().addComponent(txtUserName, GroupLayout.PREFERRED_SIZE, 170,

GroupLayout.PREFERRED_SIZE).addComponent(pwfPassword, GroupLayout.PREFERRED_SIZE, 170,

GroupLayout.PREFERRED_SIZE).addGroup(GroupLayout.Alignment.CENTER,

layout.createSequentialGroup().addComponent(btnLogin).addComponent(btnCancel)));

layout.setHorizontalGroup(hGroup); GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();

vGroup.addGap(15);

vGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(lblUserName)

.addComponent(txtUserName, GroupLayout.PREFERRED_SIZE, 25,

GroupLayout.PREFERRED_SIZE));

vGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(lblPassword)

.addComponent(pwfPassword, GroupLayout.PREFERRED_SIZE, 25,

GroupLayout.PREFERRED_SIZE));

vGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(btnLogin).addComponent(

btnCancel));

layout.setVerticalGroup(vGroup);

setTitle("登陆");

setSize(new Dimension(250, 150));

setLocationRelativeTo(null);

}

/**

* Shutdown procedure when run as an application.

*/

protected void windowClosed() {

// TODO: Check if it is safe to close the application

// Exit application.

System.exit(0);

}

}

java窗口登陆的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于登录java实现、java窗口登陆的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-28,除非注明,否则均为首码项目网原创文章,转载请注明出处。