Multiple joptionpane text boxes (jdialog implementation code)

Source: Internet
Author: User
Tags import database

Inherits the jdialog class. The first sentence of the constructor is super (owner, "title", modal );
If modal is set to true, a mode dialog box is displayed. If modal is set to false, a mode-free dialog box is displayed.

Package UI. Dialog;

Import java. AWT. event. actionevent;
Import java. AWT. event. actionlistener;
Import java. AWT. event. componentadapter;
Import java. AWT. event. componentevent;
Import java. AWT. event. windowadapter;
Import java. AWT. event. javaswevent;
Import java. Beans. propertychangeevent;
Import java. Beans. propertychangelistener;

Import javax. Swing. jcombobox;
Import javax. Swing. jdialog;
Import javax. Swing. joptionpane;
Import javax. Swing. jpasswordfield;
Import javax. Swing. jtextfield;

Import UI. adminui;
Import UI. mainclass;
Import database. databasebean. sparameteroperation;
Import database. databasebean. staffoperation;
Import database. entity. sparameter;
Import database. entity. staff;

Public class addstaffdialog extends jdialog implements actionlistener,
Propertychangelistener {
Public jtextfield staffidtextfield;

Public jtextfield staffnametextfield;

Public jpasswordfield staffpassword1textfield;

Public jpasswordfield staffpassword2textfield;

Public jcombobox staffrolecombobox;

Public jtextfield staffphonetextfield;

Public jtextfield staffaddresstextfield;

Public jtextfield staffemailtextfield;

Private string okbuttonstring = "OK ";

Private string cancelbuttonstring = "cancel ";

Private joptionpane optionpane;

Private mainclass;

Public addstaffdialog (adminui, mainclass main ){
Super (adminui, "add employee account", true );
Mainclass = Main;

Staffaddresstextfield = new jtextfield (10 );
Staffemailtextfield = new jtextfield (10 );
Staffidtextfield = new jtextfield (10 );
Staffnametextfield = new jtextfield (10 );
Staffpassword1textfield = new jpasswordfield (10 );
Staffpassword2textfield = new jpasswordfield (10 );
Staffphonetextfield = new jtextfield (10 );
Staffrolecombobox = new jcombobox (staff. Level );

String idstring = "employee ID :";
String namestring = "employee name :";
String passwordstring = "Enter Password :";
String ensurepasswordstring = "Confirm Password :";
String rolestring = "Employee permissions :";
String addressstring = "Residential Address :";
String phonestring = "contact number :";
String emailstring = "Email :";

Object array [] = {idstring, staffidtextfield, namestring,
Staffnametextfield, passwordstring, staffpassword1textfield,
Ensurepasswordstring, staffpassword2textfield, rolestring,
Staffrolecombobox, phonestring, staffphonetextfield,
Addressstring, staffaddresstextfield, emailstring,
Staffemailtextfield };

Object options [] = {okbuttonstring, cancelbuttonstring };

Optionpane = new joptionpane (array, joptionpane. plain_message,
Joptionpane. OK _cancel_option, null, options, options [0]);
Setcontentpane (optionpane );

Setdefaclocloseoperation (do_nothing_on_close );
Addwindowlistener (New windowadapter (){
Public void windowclosing (incluwevent we ){
/*
* Instead of directly closing the window, we're re going to change
* The joptionpane's value property.
*/
Optionpane. setvalue (New INTEGER (joptionpane. closed_option ));
}
});

Addwindowlistener (New windowadapter (){
Public void windowclosing (incluwevent we ){
// Change the joption's value before closing
Optionpane. setvalue (New INTEGER (joptionpane. closed_option ));
}
});

Optionpane. addpropertychangelistener (this );

Addcomponentlistener (New componentadapter (){
Public void componentshown (componentevent CE ){
Staffidtextfield. requestfocusinwindow ();
}
});
Setsize (320,450 );
Setresizable (false );
Setvisible (true );
}

Public void propertychange (propertychangeevent e ){
String prop = E. getpropertyname ();

If (E. getsource () = optionpane)
& (Joptionpane. value_property.equals (PROP) | joptionpane. input_value_property
. Equals (PROP ))){
Object value = optionpane. getvalue ();

If (value = joptionpane. uninitialized_value ){
// Ignore Reset
Return;
}

// Reset the joptionpane's value.
// If we don't do this, then if the user
// Presses the same button next time, no
// Property change event will be fired.
// Optionpane. setvalue (joptionpane. uninitialized_value );

If (okbuttonstring. Equals (value )){
String id = staffidtextfield. gettext ();
String name = staffnametextfield. gettext ();
String password1 = new string (staffpassword1textfield. GetPassword ());
String password2 = new string (staffpassword2textfield. GetPassword ());
String role = (string) staffrolecombobox. getselecteditem ();
String phone = staffphonetextfield. gettext ();
String address = staffaddresstextfield. gettext ();
String email = staffemailtextfield. gettext ();
// Todo add staff
If (password1.equals (password2) = false)
Joptionpane. showmessagedialog (null, "Incorrect password", "error", joptionpane. error_message );
Staffoperation. insertstaff (mainclass. Connection, new staff (
ID, name, password1, role, phone, address, email ));
}
Setvisible (false );
}
}

Public void actionreceivmed (actionevent e ){
Optionpane. setvalue (okbuttonstring );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.