1.登陆界面的java代码怎么写
原发布者:梦妙奇缘
用户登录的代码://LoginFrame.javaimportjavax.swing.*;importjava.awt.*;importjava.awt.event.*;{privateintcount=0;privateJLabellabel1,label2;privateJTextFieldtext;;privateJButtonbutton1,button2;MyJPanel(){label1=newJLabel("用户名");label2=newJLabel("密码");button1=newJButton("确定");button2=newJButton("取消");text=newJTextField(20);pass=newJPasswordField(20);button1.setMnemonic(KeyEvent.VK_O);//设置按钮快捷键button2.setMnemonic(KeyEvent.VK_C);button1.setActionCommand("entry");button2.setActionCommand("cancel");button1.addActionListener(this);//注册按钮事件button2.addActionListener(this);//注册按钮事件setBackground(Color.cyan);//设定面板背景色add(label1);add(text);add(label2);add(pass);add(button1);add(button2);}(ActionEvente){if(e.getActionCommand().equals("entry")){count++;//计数Stringusername,password;if(count<3){
2.用Java怎么写一个简单完整的登陆界面
package com.oristand.cn;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class QQlogin extends JFrame{
public QQlogin()
{
JFrame jf= new JFrame("QQ登陆界面");
jf.setLayout(new GridLayout(5,1,5,5));
JPanel jp=new JPanel();
JLabel jl=new JLabel("欢迎登陆");
jp.add(jl);
jf.add(jp);
JPanel jp1=new JPanel();
JLabel jl1=new JLabel("用户名");
JTextField jt=new JTextField(10);
jp1.add(jl1);
jp1.add(jt);
jf.add(jp1);
JPanel jp2=new JPanel();
JLabel jl2=new JLabel("密码");
JTextField jt1=new JPasswordField(10);
jp2.add(jl2);
jp2.add(jt1);
jf.add(jp2);
JPanel jp3=new JPanel();
JButton jb=new JButton("登陆");
JButton jb1=new JButton("注册");
JButton jb2=new JButton("设置");
jp3.add(jb);
jp3.add(jb1);
jp3.add(jb2);
jf.add(jp3);
JLabel jl3=new JLabel();
jf.add(jl3);
jf.setSize(300,400);
jf.setVisible(true);
jf.setResizable(false);
jf.(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
new QQlogin();
}
}
3.用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.(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(); } }。
4.java写一个登录界面
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class login extends JFrame implements ActionListener
{
public JPasswordField password;
public JTextField name;
JButton ok;
login()
{
setSize(300,200);//大小
setLocation(200,100);
JPanel panel = new JPanel();//创建一个面板对象
panel.setLayout(new GridBagLayout());
Container cn = this.getContentPane();
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(5,2,5,5);
c.gridheight = 1;
JLabel user = new JLabel("User:");
c.gridx = 1;
c.gridy = 1;
panel.add(user,c);
name = new JTextField(10);
c.gridx = 2;
panel.add(name,c);
JLabel pass = new JLabel("assword:");
c.gridx = 1;
c.gridy = 2;
panel.add(pass,c);
password = new JPasswordField(10);
c.gridx = 2;
c.gridy = 2;
panel.add(password,c);
c.gridx = 1;
c.gridy = 3;
ok = new JButton("login");
ok.addActionListener(this);
panel.add(ok,c);
cn.add(panel);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source == ok)
{
String username = this.name.getText();
String password = this.password.getText();
String message = username + " "+password;
try
{
byte[] b = message.getBytes();
FileOutputStream fos = new FileOutputStream("login.txt");
fos.write(b,0,b.length);
this.dispose();
}catch(Exception ex)
{
}
}
}
public static void main(String args[])
{
new login().show();
}
}
5.怎么用Java编写用户登陆界面
什么都不说了 直接给你代码吧package com.moliying.ui;import java.awt.BorderLayout;import java.awt.Container;import java.awt.FlowLayout;import java.awt.List;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.BufferedWriter;import java.io.FileOutputStream;import java.io.OutputStreamWriter;import java.util.ArrayList;import java.util.Arrays;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;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() { frame.setSize(300, 200); frame.setBounds(450, 300, 300, 200); c.setLayout(new B。
什么都不说了 直接给你代码吧package com.moliying.ui;import java.awt.BorderLayout;import java.awt.Container;import java.awt.FlowLayout;import java.awt.List;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.BufferedWriter;import java.io.FileOutputStream;import java.io.OutputStreamWriter;import java.util.ArrayList;import java.util.Arrays;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;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() { frame.setSize(300, 200); frame.setBounds(450, 300, 300, 200); c.setLayout(new BorderLayout()); initFrame(); frame.setVisible(true); } 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 a1 = new JLabel("用户名:"); a1.setBounds(50, 20, 50, 20); JLabel a2 = new JLabel("密 码:"); a2.setBounds(50, 60, 50, 20); fieldPanel.add(a1); fieldPanel.add(a2); username.setBounds(110, 20, 120, 20); password.setBounds(110, 60, 120, 20); 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"); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println(username.getText().toString()); } }); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { frame.setVisible(false); } }); } public static void main(String[] args) {// new Login(); String ss = "abbabbbaabbbccba"; System.out.println(ss.split("b").length);}}。
6.用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.(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); }}。
7.用java实现QQ登录界面怎么写
package ch10; import java.awt.*; import java.awt.event.*; import javax.swing.*;//定义该类继承自JFrame,实现ActionListener接口 public class LoginTest extends JFrame implements ActionListener { //创建JPanel对象 private JPanel jp=new JPanel(); //创建3个标并加入数组 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); for(int i=0;i { //设置标签和按扭的位置与大小 jl[i].setBounds(30,20+40*i,180,20); jb[i].setBounds(30+110*i,100,80,20); //添加标签和按扭到JPanel容器中 jp.add(jl[i]); jp.add(jb[i]); //为2个按钮注册动作事件监听器 jb[i].addActionListener(this); } //设置文本框的位置和大小,注意满足美观并足够用户名的长度 jName.setBounds(130,15,100,20); //添加文本框到JPanel容器中 jp.add(jName); //为文本框注册动作事件监听器 jName.addActionListener(this); //设置密码框的位置和大小,注意满足美观和足够密码的长度 jPassword.setBounds(130,60,100,20); //添加密码框到JPanel容器中 jp.add(jPassword); //设置密码框中的回显字符,这里设置美元符号 jPassword.setEchoChar('$'); //为密码框注册动作事件监听器 jPassword.addActionListener(this); //设置用于显示登陆状态的标签大小位置,并将其添加进JPanel容器 jl[2].setBounds(10,180,270,20); jp.add(jl[2]); //添加JPanel容器到窗体中 this.add(jp); //设置窗体的标题、位置、大小、可见性及关闭动作 this.setTitle("登陆窗口"); this.setBounds(200,200,270,250); this.setVisible(true); this.(JFrame.EXIT_ON_CLOSE); } //实现动作监听器接口中的方法actionPerformed public void actionPerformed(ActionEvent e) { //如果事件源为文本框 if(e.getSource()==jName) { //切换输入焦点到密码框 jPassword.requestFocus(); } //如果事件源为重置按扭 else if(e.getSource()==jb[1]) { //清空姓名文本框、密码框和show标签中的所有信息 jl[2].setText(""); jName.setText(""); jPassword.setText(""); //让输入焦点回到文本框 jName.requestFocus(); } //如果事件源为登陆按钮,则判断登录名和密码是否正确 else { //判断用户名和密码是否匹配 if(jName.getText().equals("lixiangguo")&& String.valueOf(jPassword.getPassword()).equals("19801001")) { jl[2].setText("登陆成功,欢迎您的到来!"); } else { jl[2].setText("对不起,您的用户名或密码错误!"); } } } public static void main(String[] args) { //创建LoginTest窗体对象 new LoginTest(); } } 这个简单点的。
8.用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.(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”关注。
转载请注明出处育才学习网 » java怎么写登录界面