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(); } } 。
- 314大写怎么写
- 游岩藤农场作文怎么写
- 怎么写间接引用
- parcel音标怎么写
- 11月日语怎么写
- best音标怎么写
- 四讲四爱的内容怎么写
- 授权律师怎么写
- 神笔马良英文怎么写
- 准妈咪阴道出血怎么急救?