Current location - Training Enrollment Network - Books and materials - Book management system (java) code?
Book management system (java) code?
Java swing login interface code

/*

* Login.java

*

* Created on _ _ date _ _, _ _ time _ _

*/

Package com.agen.library.window;

Import java.awt.image;

Import java.awt.toolkit;

Import javax.swing.jooptionpane;

Import javax.swing.uimanager;

import javax . swing . unsupportedlookandfeelexception;

Import com.agen.library.factory.daofactory;

Import com.agen.library.util.globaluser;

Import com.agen.library.vo.user;

/**

*

* @author __USER__

*/

Common class login extension javax.swing.JFrame {

/**

*

*/

private static final long serialVersionUID =-2 176093732040600809 l;

/* * Create a new form login */

Public login () {

Super ("Easy Cloud Book Management Software V1.0");

image ime = toolkit . getdefaulttoolkit()。 getImage(

getClass()。 get resource("/images/ico . png ");

Try {

ui manager . setlookandfeel(ui manager . getsystemlookandfeelclassname());

} catch(ClassNotFoundException e){

// TODO automatically generated catch block

e . printstacktrace();

} catch(instantiation exception e){

// TODO automatically generated catch block

e . printstacktrace();

} catch(IllegalAccessException e){

// TODO automatically generated catch block

e . printstacktrace();

} catch(UnsupportedLookAndFeelException e){

// TODO automatically generated catch block

e . printstacktrace();

}

setIconImage(ime);

init components();

setLocationRelativeTo(null);

this . setresizable(false);

}

/**

* Call this method from the constructor to initialize the form.

* Warning: Do not modify this code. The content of this method is always

* Regenerated by the form editor.

*/

// GEN-BEGIN:initComponents

//& lt; Editor-folddefaultstate = "collapsed" desc = "generated code">

Private void initComponents() {

jlabel 2 = new javax . swing . jlabel();

jlabel 3 = new javax . swing . jlabel();

jtextfield 1 = new javax . swing . jtextfield();

jpassword field 1 = new javax . swing . jpasswordfield();

jbutton 1 = new javax . swing . jbutton();

jbutton 2 = new javax . swing . jbutton();

jlabel 1 = new javax . swing . jlabel();

jmenubar 1 = new javax . swing . jmenubar();

jmenu 1 = new javax . swing . jmenu();

jmenuitem 1 = new javax . swing . jmenuitem();

jmenu 2 = new javax . swing . jmenu();

jmenuitem 2 = new javax . swing . jmenuitem();

setDefaultCloseOperation(javax . swing . window constants . exit _ ON _ CLOSE);

addkey listener(new Java . awt . event . key adapter(){

public void key pressed(Java . awt . event . key event evt){

formkeypress(evt);

}

public void key typed(Java . awt . event . key event evt){

formkey typed(evt);

}

});

Jlabel2.setfont (newjava.awt.font ("Microsoft Yahei", 0,14));

jlabel 2 . settext(" \ u 7528 \ u 6237 \ u540d \ uff 1a ");

Jlabel3.setfont (newjava.awt.font ("Microsoft Yahei", 0,14));

jlabel 3 . settext(" \ u5bc 6 \ u 780 1 \ uff 1a ");

Jtextfield1.setfont (newjava.awt.font ("Microsoft Yahei", 0,14));

jtextfield 1 . addactionlistener(new Java . awt . event . action listener(){

public void action performed(Java . awt . event . action event evt){

jtextfield 1 action performed(evt);

}

});

JPasswordfield1.setfont (newjava.awt.font ("Microsoft Yahei", 0,12));

jpasswordfield 1 . addkey listener(new Java . awt . event . key adapter(){

public void key typed(Java . awt . event . key event evt){

jpasswordfield 1 key typed(evt);

}

});

jbutton 1 . set background(new Java . awt . color(223,2 16,2 16));

JButton1.setfont (newjava.awt.font ("Microsoft Yahei", 0,14));

jbutton 1 . settext(" \ u767b \ u 9646 ");

jbutton 1 . addactionlistener(new Java . awt . event . action listener(){

public void action performed(Java . awt . event . action event evt){

jbutton 1 action performed(evt);

}

});

jbutton 2 . set background(new Java . awt . color(223,2 16,2 16));

Jbutton2.setfont (newjava.awt.font ("Microsoft Yahei", 0,14));

jbutton 2 . settext(" \ u53d 6 \ u6d 88 ");

jbutton 2 . addactionlistener(new Java . awt . event . action listener(){

public void action performed(Java . awt . event . action event evt){

jbutton 2 action performed(evt);

}

});

JLabel 1.setIcon (new javax.swing.ImageIcon (

getClass()。 get resource("/images/log in _ main . jpg ")); // NOI 18N

jmenu 1 . settext(" File ");

Jmenu1.setfont (newjava.awt.font ("Microsoft Yahei", 0,14));

jmenuitem 1 . set accelerator(javax . swing . keystone . get keystone(

java.awt.event.KeyEvent.VK_Q,

Java . awt . event . input event . ctrl _ MASK));

jmenuitem 1 . settext(" Exit ");

jmenuitem 1 . addmouse listener(new Java . awt . event . mouse adapter(){

public void mouse clicked(Java . awt . event . mouse event evt){

jmenuitem 1 mouse clicked(evt);

}

});

jmenuitem 1 . addactionlistener(new Java . awt . event . action listener(){

public void action performed(Java . awt . event . action event evt){

jmenuitem 1 action performed(evt);

}

});

jmenu 1 . add(jmenu item 1);

jmenubar 1 . add(jmenu 1);

jmenu 2 . settext(" Help ");

Jmenu2.setfont (newjava.awt.font ("Microsoft Yahei", 0,14));

jmenuitem 2 . settext(" About ");

jmenuitem 2 . addactionlistener(new Java . awt . event . action listener(){

public void action performed(Java . awt . event . action event evt){

jmenuitem 2 action performed(evt);

}

});

jmenu 2 . add(jmenu item 2);

jmenubar 1 . add(jmenu 2);

setJMenuBar(jmenubar 1);

javax . swing . group layout layout = new javax . swing . group layout(

getContentPane());

getContentPane()。 SetLayout;

Layout.setHorizontalGroup (layout

. create parallel group(javax . swing . group layout . alignment . leading)

. addComponent(jLabel 1)

. Add group (

layout.createSequentialGroup()

. addContainerGap()

. Add group (

layout.createParallelGroup(

javax . swing . group layout . alignment . trailing,

False)

. Add a component (

jLabel2,

javax . swing . group layout . alignment . leading)

. Add group (

javax . swing . group layout . alignment . leading,

layout.createSequentialGroup()

. Add a component (

jLabel3)

. addPreferredGap(

javax . swing . layout style . component placement . related)

. Add group (

layout.createParallelGroup(

javax . swing . group layout . alignment . leading)

. Add group (

layout.createSequentialGroup()

. addGap( 10,

10,

10)

. Add a component (

jButton 1)

. addGap(47,

47,

47)

. Add a component (

jButton2))

. Add a component (

jPasswordField 1)

. Add a component (

jTextField 1,

javax . swing . group layout . default _ SIZE,

197,

Short. Maximum value))

. addContainerGap())))));

layout.setVerticalGroup(layout

. create parallel group(javax . swing . group layout . alignment . leading)

. Add group (

layout.createSequentialGroup()

. addComponent(jLabel 1)

. addPreferredGap(

javax . swing . layout style . component placement . related)

. Add group (

layout.createParallelGroup(

javax . swing . group layout . alignment . baseline)

. addComponent(jLabel2)

. Add a component (

jTextField 1,

javax . swing . group layout . preferred _ SIZE,

24,

javax . swing . group layout . preferred _ SIZE))

. addPreferredGap(

javax . swing . layout style . component placement . related)

. Add group (

layout.createParallelGroup(

javax . swing . group layout . alignment . baseline)

. addComponent(jLabel3)

. Add a component (

jPasswordField 1

javax . swing . group layout . preferred _ SIZE,

23,

javax . swing . group layout . preferred _ SIZE))

. addPreferredGap(

javax . swing . layout style . component placement . related)

. Add group (

layout.createParallelGroup(

javax . swing . group layout . alignment . baseline)

. addComponent(jButton 1)

. addComponent(jButton2))

. addContainerGap(

javax . swing . group layout . default _ SIZE,

Short. MAX _ VALUE)));

pack();

}//& lt; /editor-fold & gt;

// GEN-END:initComponents

private void jmenuitem 2 actionperformed(Java . awt . event . action event evt){

// TODO adds processing code here:

about . start();

}

private void jpasswordfield 1 key typed(Java . awt . event . key event evt){

if (evt.getKeyChar() == '\n') {

string name = jtextfield 1 . gettext(); //get the user name

string pass = string . value of(jpasswordfield 1 . get password()); //Get the password

User user = null

//No user name was entered.

if(name . equals(" " | | name = = null){

The Joption pane. Displays a message dialog box (here, "User name cannot be empty!") , "CuO Wu", 0);

Return;

}

Try {

user = Dao factory . getiuserdao instance()。 FindById (name);

If (user! = null) {

if (user.getPass()! = null & amp& ampuser.getPass()。 Equal to (pass)) {

GlobalUser。 LOGIN_USER = user; //Record the current user

//Enter the main interface

main . start();

this . dispose();

} Otherwise {

The Joption pane. Displays a message dialog box (here, "Wrong user name or password!" );

Return;

}

}

Catch (exception e) {

// TODO automatically generated catch block

e . printstacktrace();

}

if (user == null) {

The Joption pane. Displays a message dialog box (here, "Wrong user name or password!" , "Message", 0);

Return;

}

}

}

private void form key typed(Java . awt . event . key event evt){

}

private void form key pressed(Java . awt . event . key event evt){

}

private void jtextfield 1 action performed(Java . awt . event . action event evt){

// TODO adds processing code here:

}

private void jbutton 2 action performed(Java . awt . event . action event evt){

// TODO adds processing code here:

jtextfield 1 . settext(" ");

jpasswordfield 1 . settext(" ");

jtextfield 1 . request focus();

}

private void jbutton 1 action performed(Java . awt . event . action event evt){

string name = jtextfield 1 . gettext(); //get the user name

string pass = string . value of(jpasswordfield 1 . get password()); //Get the password

User user = null

//No user name was entered.

if(name . equals(" "){

The Joption pane. Displays a message dialog box (here, "User name cannot be empty!") );

Return;

}

Try {

user = Dao factory . getiuserdao instance()。 FindById (name);

If (user! = null) {

if (user.getPass()! = null & amp& ampuser.getPass()。 Equal to (pass)) {

GlobalUser。 LOGIN_USER = user; //Record the current user

//Enter the main interface

main . start();

this . dispose();

} Otherwise {

The Joption pane. Displays a message dialog box (here, "Wrong user name or password!" , "Message", 0);

Return;

}

}

Catch (exception e) {

// TODO automatically generated catch block

e . printstacktrace();

}

if (user == null) {

The Joption pane. Displays a message dialog box (here, "Wrong user name or password!" , "Message", 0);

Return;

}

}

private void jmenuitem 1 action performed(Java . awt . event . action event evt){

If (options pane. ShowConfirmilog (well, "Are you sure you want to quit?" , "tips",

JOptionPane。 YES_NO_OPTION) == JOptionPane。 Yes _ option) {

system . exit(0);

}

}

private void jmenuitem 1 mouse clicked(Java . awt . event . mouse event evt){

system . exit( 1);

}

/**

* @param args

* command line parameters

*/

Public static void main (strinargs []) {

//system . out . println(log in . class . get resource(" src/images/images/log in _ main . jpg "));

//new javax . swing . image icon(

//log in . class . get resource("../../../../images/log in _ main . jpg "));

//New login (). set visible(true);

Java . awt . event queue . invoke later(new Runnable(){

Public invalid operation () {

New login (). set visible(true);

}

});

}

// GEN-BEGIN: variable

//Variable declaration-Do not modify

private javax . swing . jbutton jbutton 1;

private javax . swing . jbutton jbutton 2;

private javax . swing . jlabel jlabel 1;

private javax . swing . jlabel jlabel 2;

private javax . swing . jlabel jlabel 3;

private javax . swing . jmenu jmenu 1;

private javax . swing . jmenu jmenu 2;

private javax . swing . jmenubar jmenubar 1;

private javax . swing . jmenuitem jmenuitem 1;

private javax . swing . jmenuitem jmenuitem 2;

private javax . swing . jpassword field jpassword field 1;

private javax . swing . jtextfield jtextfield 1;

//End of variable declaration //GEN-END: variable

}