这是毕业设计吗?看起来不难啊,你自己做了然后不懂问问,别人帮你做了你还是不会
javaswing登陆界面code
/*
*Login.java
*
*Createdon__DATE__,__TIME__
*/
packagecom.agen.library.window;
importjava.awt.Image;
importjava.awt.Toolkit;
importjavax.swing.JOptionPane;
importjavax.swing.UIManager;
importjavax.swing.UnsupportedLookAndFeelException;
importcom.agen.library.factory.DAOFactory;
importcom.agen.library.util.GlobalUser;
importcom.agen.library.vo.User;
/**
*@author__USER__
publicclassLoginextendsjavax.swing.JFrame{
privatestaticfinallongserialVersionUID=-2176093732040600809L;
/**CreatesnewformLogin*/
publicLogin(){
super("易云图书管理软件V1.0");
Imageime=Toolkit.getDefaultToolkit().getImage(
getClass().getResource("/images/ico.png"));
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(ClassNotFoundExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}catch(InstantiationExceptione){
}catch(IllegalAccessExceptione){
}catch(UnsupportedLookAndFeelExceptione){
}
setIconImage(ime);
initComponents();
setLocationRelativeTo(null);
this.setResizable(false);
*Thismethodiscalledfromwithintheconstructortoinitializetheform.
*WARNING:DoNOTmodifythiscode.Thecontentofthismethodisalways
*regeneratedbytheFormEditor.
//GEN-BEGIN:initComponents
//editor-folddefaultstate="collapsed"desc="GeneratedCode"
privatevoidinitComponents(){
jLabel2=newjavax.swing.JLabel();
jLabel3=newjavax.swing.JLabel();
jTextField1=newjavax.swing.JTextField();
jPasswordField1=newjavax.swing.JPasswordField();
jButton1=newjavax.swing.JButton();
jButton2=newjavax.swing.JButton();
jLabel1=newjavax.swing.JLabel();
jMenuBar1=newjavax.swing.JMenuBar();
jMenu1=newjavax.swing.JMenu();
jMenuItem1=newjavax.swing.JMenuItem();
jMenu2=newjavax.swing.JMenu();
jMenuItem2=newjavax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addKeyListener(newjava.awt.event.KeyAdapter(){
publicvoidkeyPressed(java.awt.event.KeyEventevt){
formKeyPressed(evt);
publicvoidkeyTyped(java.awt.event.KeyEventevt){
formKeyTyped(evt);
});
jLabel2.setFont(newjava.awt.Font("微软雅黑",0,14));
jLabel2.setText("\u7528\u6237\u540d\uff1a");
jLabel3.setFont(newjava.awt.Font("微软雅黑",0,14));
jLabel3.setText("\u5bc6\u7801\uff1a");
jTextField1.setFont(newjava.awt.Font("微软雅黑",0,14));
jTextField1.addActionListener(newjava.awt.event.ActionListener(){
publicvoidactionPerformed(java.awt.event.ActionEventevt){
jTextField1ActionPerformed(evt);
jPasswordField1.setFont(newjava.awt.Font("微软雅黑",0,12));
jPasswordField1.addKeyListener(newjava.awt.event.KeyAdapter(){
jPasswordField1KeyTyped(evt);
jButton1.setBackground(newjava.awt.Color(223,216,216));
jButton1.setFont(newjava.awt.Font("微软雅黑",0,14));
jButton1.setText("\u767b\u9646");
jButton1.addActionListener(newjava.awt.event.ActionListener(){
jButton1ActionPerformed(evt);
jButton2.setBackground(newjava.awt.Color(223,216,216));
jButton2.setFont(newjava.awt.Font("微软雅黑",0,14));
jButton2.setText("\u53d6\u6d88");
jButton2.addActionListener(newjava.awt.event.ActionListener(){
jButton2ActionPerformed(evt);
jLabel1.setIcon(newjavax.swing.ImageIcon(
getClass().getResource("/images/login_main.jpg")));//NOI18N
jMenu1.setText("File");
jMenu1.setFont(newjava.awt.Font("微软雅黑",0,14));
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
java.awt.event.KeyEvent.VK_Q,
java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setText("Exit");
jMenuItem1.addMouseListener(newjava.awt.event.MouseAdapter(){
publicvoidmouseClicked(java.awt.event.MouseEventevt){
jMenuItem1MouseClicked(evt);
jMenuItem1.addActionListener(newjava.awt.event.ActionListener(){
jMenuItem1ActionPerformed(evt);
jMenu1.add(jMenuItem1);
jMenuBar1.add(jMenu1);
jMenu2.setText("Help");
jMenu2.setFont(newjava.awt.Font("微软雅黑",0,14));
jMenuItem2.setText("About");
jMenuItem2.addActionListener(newjava.awt.event.ActionListener(){
jMenuItem2ActionPerformed(evt);
jMenu2.add(jMenuItem2);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayoutlayout=newjavax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(
layout.createSequentialGroup()
.addContainerGap()
layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
false)
.addComponent(
jLabel2,
javax.swing.GroupLayout.Alignment.LEADING)
javax.swing.GroupLayout.Alignment.LEADING,
jLabel3)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGap(10,
10,
10)
jButton1)
.addGap(47,
47,
47)
jButton2))
jPasswordField1)
jTextField1,
javax.swing.GroupLayout.DEFAULT_SIZE,
197,
Short.MAX_VALUE))
.addContainerGap()))));
layout.setVerticalGroup(layout
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
javax.swing.GroupLayout.PREFERRED_SIZE,
24,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel3)
jPasswordField1,
23,
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(
Short.MAX_VALUE)));
pack();
}///editor-fold
//GEN-END:initComponents
privatevoidjMenuItem2ActionPerformed(java.awt.event.ActionEventevt){
//TODOaddyourhandlingcodehere:
About.start();
privatevoidjPasswordField1KeyTyped(java.awt.event.KeyEventevt){
if(evt.getKeyChar()=='\n'){
Stringname=jTextField1.getText();//获取用户名
Stringpass=String.valueOf(jPasswordField1.getPassword());//获取密码
Useruser=null;
//未输入用户名
if(name.equals("")||name==null){
JOptionPane.showMessageDialog(this,"用户名不允许为空!","cuowu",0);
return;
user=DAOFactory.getIUserDAOInstance().findById(name);
if(user!=null){
if(user.getPass()!=nulluser.getPass().equals(pass)){
GlobalUser.LOGIN_USER=user;//记录当前用户
//进入主界面
Main.start();
this.dispose();
}else{
JOptionPane.showMessageDialog(this,"用户名或密码错误!");
}catch(Exceptione){
if(user==null){
JOptionPane.showMessageDialog(this,"用户名或密码错误!","消息",0);
privatevoidformKeyTyped(java.awt.event.KeyEventevt){
privatevoidformKeyPressed(java.awt.event.KeyEventevt){
privatevoidjTextField1ActionPerformed(java.awt.event.ActionEventevt){
privatevoidjButton2ActionPerformed(java.awt.event.ActionEventevt){
jTextField1.setText("");
jPasswordField1.setText("");
jTextField1.requestFocus();
privatevoidjButton1ActionPerformed(java.awt.event.ActionEventevt){
if(name.equals("")){
JOptionPane.showMessageDialog(this,"用户名不允许为空!");
privatevoidjMenuItem1ActionPerformed(java.awt.event.ActionEventevt){
if(JOptionPane.showConfirmDialog(this,"你确定要退出吗?","提示",
JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
System.exit(0);
privatevoidjMenuItem1MouseClicked(java.awt.event.MouseEventevt){
System.exit(1);
*@paramargs
*thecommandlinearguments
publicstaticvoidmain(Stringargs[]){
//System.out.println(Login.class.getResource("src/images/images/login_main.jpg"));
//newjavax.swing.ImageIcon(
//Login.class.getResource("../../../../images/login_main.jpg"));
//newLogin().setVisible(true);
java.awt.EventQueue.invokeLater(newRunnable(){
publicvoidrun(){
newLogin().setVisible(true);
//GEN-BEGIN:variables
//Variablesdeclaration-donotmodify
privatejavax.swing.JButtonjButton1;
privatejavax.swing.JButtonjButton2;
privatejavax.swing.JLabeljLabel1;
privatejavax.swing.JLabeljLabel2;
privatejavax.swing.JLabeljLabel3;
privatejavax.swing.JMenujMenu1;
privatejavax.swing.JMenujMenu2;
privatejavax.swing.JMenuBarjMenuBar1;
privatejavax.swing.JMenuItemjMenuItem1;
privatejavax.swing.JMenuItemjMenuItem2;
privatejavax.swing.JPasswordFieldjPasswordField1;
privatejavax.swing.JTextFieldjTextField1;
//Endofvariablesdeclaration//GEN-END:variables
这个有几种解决方案:
1、创建一个静态变量,直接将号码保存起来,其他类中直接类名调用即可
2、如果下次进来还想这个号码依然使用的话,就把这个号码写入到本地文件中去