001: package guam;
002:
003: import java.awt.*;
004: import javax.swing.*;
005: import java.awt.event.*;
006:
007: /**
008: * Title: GUAM
009: * Description:
010: * Copyright: Copyright (c) 2002
011: * Company:
012: * @author dkc
013: * @version 1.0
014: */
015:
016: public class UserCreate extends JFrame {
017: JLabel UsernameLabel = new JLabel();
018: JLabel PassLabel = new JLabel();
019: JLabel PassAgainLabel = new JLabel();
020: JTextField Username = new JTextField();
021: JTextField Password = new JPasswordField();
022: JTextField ConfirmPass = new JPasswordField();
023: JButton CancelButton = new JButton();
024: JButton ApplyButton = new JButton();
025: MainFrame mymainframe = null;
026: UserMain myusermain = null;
027: String username = null;
028:
029: public UserCreate(MainFrame mymainframe) {
030: this .mymainframe = mymainframe;
031: try {
032: jbInit();
033: } catch (Exception e) {
034: e.printStackTrace();
035: }
036: }
037:
038: public UserCreate(UserMain myusermain, String username) {
039: this .username = username;
040: this .myusermain = myusermain;
041: try {
042: jbInit();
043: } catch (Exception e) {
044: e.printStackTrace();
045: }
046: }
047:
048: private void jbInit() throws Exception {
049: UsernameLabel.setFont(new java.awt.Font("Dialog", 1, 12));
050: UsernameLabel.setText("Username:");
051: UsernameLabel.setBounds(new Rectangle(14, 10, 80, 23));
052: this .getContentPane().setLayout(null);
053: PassLabel.setBounds(new Rectangle(14, 35, 80, 23));
054: PassLabel.setText("Password:");
055: PassLabel.setFont(new java.awt.Font("Dialog", 1, 12));
056: PassAgainLabel.setBounds(new Rectangle(14, 60, 80, 23));
057: PassAgainLabel.setText("Confirm Pass:");
058: PassAgainLabel.setFont(new java.awt.Font("Dialog", 1, 12));
059: Username.setBounds(new Rectangle(98, 11, 169, 21));
060: Password.setBounds(new Rectangle(98, 36, 169, 21));
061: ConfirmPass.setBounds(new Rectangle(98, 61, 169, 21));
062: if (this .username != null) {
063: Username.setText(this .username);
064: Username.setEnabled(false);
065: }
066: CancelButton.setText("Cancel");
067: CancelButton.setBounds(new Rectangle(202, 91, 77, 29));
068: CancelButton
069: .addActionListener(new java.awt.event.ActionListener() {
070: public void actionPerformed(ActionEvent e) {
071: CancelButton_actionPerformed(e);
072: }
073: });
074: ApplyButton.setBounds(new Rectangle(120, 91, 77, 29));
075: ApplyButton
076: .addActionListener(new java.awt.event.ActionListener() {
077: public void actionPerformed(ActionEvent e) {
078: ApplyButton_actionPerformed(e);
079: }
080: });
081: ApplyButton.setText("Apply");
082: this
083: .setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
084: this .getContentPane().add(UsernameLabel, null);
085: this .getContentPane().add(PassLabel, null);
086: this .getContentPane().add(PassAgainLabel, null);
087: this .getContentPane().add(Username, null);
088: this .getContentPane().add(Password, null);
089: this .getContentPane().add(ConfirmPass, null);
090: this .getContentPane().add(CancelButton, null);
091: this .getContentPane().add(ApplyButton, null);
092: }
093:
094: boolean checkModified() {
095: if (username == null) {
096: if (Username.getText().equals("")) {
097: return false;
098: } else {
099: return true;
100: }
101: } else {
102: if (Password.getText().equals("")
103: && ConfirmPass.getText().equals("")) {
104: return false;
105: } else {
106: return true;
107: }
108: }
109: }
110:
111: void CancelButton_actionPerformed(ActionEvent e) {
112: int x = 0;
113: if (this .checkModified()) {
114: x = JOptionPane.showConfirmDialog(this ,
115: "Are you sure you want to lose changes?",
116: "Confirm cancel", JOptionPane.YES_NO_OPTION,
117: JOptionPane.WARNING_MESSAGE);
118: }
119: if (x == 0) {
120: if (mymainframe != null) {
121: mymainframe.reEnable();
122: } else {
123: myusermain.reEnable();
124: }
125: this .dispose();
126: }
127: }
128:
129: void ApplyButton_actionPerformed(ActionEvent e) {
130: boolean passOK = false;
131: if (this .checkModified()) {
132: String p1 = Password.getText();
133: String p2 = ConfirmPass.getText();
134: if (p1.equals(p2)) {
135: passOK = true;
136: } else {
137: JOptionPane.showMessageDialog(this ,
138: "Passwords entered do not match!", "Error",
139: JOptionPane.WARNING_MESSAGE);
140: return;
141: }
142: if (username == null) {
143: //create user
144: if (GUAM.dbi.createUser(Username.getText(), p1)) {
145: mymainframe.openUserEdit(Username.getText());
146: } else {
147: JOptionPane.showMessageDialog(this ,
148: "Could not create user!", "Error",
149: JOptionPane.ERROR_MESSAGE);
150: }
151: } else {
152: if (GUAM.dbi.changeUserPass(Username.getText(), p1)) {
153: JOptionPane.showMessageDialog(this ,
154: "Password changed", "Success",
155: JOptionPane.INFORMATION_MESSAGE);
156: } else {
157: JOptionPane.showMessageDialog(this ,
158: "Password NOT changed!", "Error",
159: JOptionPane.ERROR_MESSAGE);
160:
161: }
162: }
163: if (mymainframe != null) {
164: mymainframe.refreshUserList();
165: mymainframe.reEnable();
166: } else {
167: myusermain.reEnable();
168: }
169: this.dispose();
170: }
171: }
172: }
|