Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  
  /*
   * CreateAccountFrame.java
   *
   * Created on 10.08.2009, 20:19:29
  */
 package ch.tatool.app.gui;
 
 import java.awt.Image;
 
 
UI for creating a new user account

Author(s):
Andre Locher
 
 public class CreateAccountFrame extends javax.swing.JFrame {
 
     private static final long serialVersionUID = 8458295653422189812L;
 
    
UserAccountService - provides data for this frame.
 
     private UserAccountService userAccountService;
    
    
Reference to the LoginFrame.
 
     private LoginFrame loginFrame;
     
     private Messages messages;
     
     public CreateAccountFrame() {
     }
     
     public void init() {
         initComponents();
     }
 
     public void setLoginFrame(LoginFrame loginFrame) {
     	this. = loginFrame;
     }
     
     public void initialize() {
         pack();
         Dimension size = getSize();
         size.height += 20;
         setSize(size);
         setLocationRelativeTo(null);
         java.net.URL iconUrl = this.getClass().getResource("/ch/tatool/app/gui/icon.png"); //$NON-NLS-1$
 		Image icon = getToolkit().getImage(iconUrl); 
 		setIconImage(icon);
     }
     
     public void createAccount() {
         String userName = .getText();
         String birthYear = .getText();
         String sex = null;
         if (getSelection() != null) {
         	sex = getSelection().getName();
         }
         if (userName.equals("") || userName == null) { //$NON-NLS-1$
             JOptionPane.showMessageDialog(this.getString("CreateAccountFrame.errorMessage.userNameMissing"), //$NON-NLS-1$
                     .getString("General.errorMessage.windowTitle.warning"), .); //$NON-NLS-1$
             return;
         }
 
         HashMap<StringStringaccountProperties = new HashMap<StringString>();
 
         if (!birthYear.equals("") && birthYear != null) { //$NON-NLS-1$
             accountProperties.put(.birthYear);
         }
         if (sex != null) {
             accountProperties.put(.sex);
         }
         
         // set account language
         String language = (String.getSelectedItem();
         String lang = "en"//$NON-NLS-1$
         if (language.equals("Deutsch")) { //$NON-NLS-1$
         	lang = "de"//$NON-NLS-1$
         } else if (language.equals("English")) { //$NON-NLS-1$
         	lang = "en"//$NON-NLS-1$
         }
         accountProperties.put(.lang);
         
         // add machine properties
         accountProperties.put(., System.getProperty("os.name")); //$NON-NLS-1$
        accountProperties.put(., System.getProperty("os.arch")); //$NON-NLS-1$
        accountProperties.put(., System.getProperty("os.version")); //$NON-NLS-1$
        accountProperties.put(., System.getProperty("user.home")); //$NON-NLS-1$
        UserAccount account = .createAccount(userName,
                accountPropertiesnull);
        // if we got one, open it now
        if (account != null) {
            .openAccount(account);
        } else {
        	JOptionPane.showMessageDialog(this.getString("CreateAccountFrame.errorMessage.userNameExists"), //$NON-NLS-1$
        			.getString("General.errorMessage.windowTitle.warning"), .); //$NON-NLS-1$
        }
    }
    public void cancelAccount() {
    	.setText(""); //$NON-NLS-1$
        .setText(""); //$NON-NLS-1$
        setVisible(false);
    }
    
    public static AbstractButton getSelection(ButtonGroup group) {
        for (Enumeration<AbstractButtone = group.getElements(); e.hasMoreElements();) {
        	AbstractButton b = e.nextElement();
            if (b.getModel() == group.getSelection()) {
                return b;
            }
        }
        return null;
    }
    
    public void setMessages(Messages messages) {
    	this. = messages;
    }
    
    public Messages getMessages() {
    	return ;
    }

    
This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;
         = new javax.swing.ButtonGroup();
         = new javax.swing.JPanel();
         = new javax.swing.JLabel();
         = new javax.swing.JTextField();
         = new javax.swing.JButton();
         = new javax.swing.JButton();
         = new javax.swing.JLabel();
         = new javax.swing.JTextField();
         = new javax.swing.JLabel();
         = new javax.swing.JRadioButton();
         = new javax.swing.JRadioButton();
         = new javax.swing.JLabel();
         = new javax.swing.JComboBox();
        setTitle(.getString("General.title"));
        getContentPane().setLayout(new java.awt.GridBagLayout());
        .setBorder(javax.swing.BorderFactory.createTitledBorder(null.getString("CreateAccountFrame.labelTitle.newUser"), ........new java.awt.Font("Tahoma", 1, 14))); // NOI18N
        .setText(.getString("CreateAccountFrame.label.user"));
        .setText(.getString("General.okLabel"));
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createButtonActionPerformed(evt);
            }
        });
        .setText(.getString("General.cancelLabel"));
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });
        .setText(.getString("CreateAccountFrame.label.birthYear"));
        .setText(.getString("CreateAccountFrame.label.sex"));
        .setText(.getString("CreateAccountFrame.label.sex.female"));
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                maleRadioButtonActionPerformed(evt);
            }
        });
        .setText(.getString("CreateAccountFrame.label.sex.male"));
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                femaleRadioButtonActionPerformed(evt);
            }
        });
        .setText(.getString("CreateAccountFrame.label.language"));
        .setModel(new javax.swing.DefaultComboBoxModel(new String[] { .getString("CreateAccountFrame.label.language.German"), .getString("CreateAccountFrame.label.language.English") }));
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout();
        .setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(....)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(....)
                    .addComponent()
                    .addComponent()
                    .addComponent()
                    .addComponent())
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(....)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(..., 86, .)
                        .addPreferredGap(....)
                        .addComponent())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent()
                        .addPreferredGap(....)
                        .addComponent())
                    .addComponent(..., 177, .)
                    .addComponent(, 0, 177, .))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(....)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(....)
                    .addComponent()
                .addGroup(jPanel1Layout.createParallelGroup(....)
                    .addComponent()
                .addGroup(jPanel1Layout.createParallelGroup(....)
                    .addComponent())
                .addGroup(jPanel1Layout.createParallelGroup(....)
                    .addComponent()
                    .addComponent()
                    .addComponent())
                .addGroup(jPanel1Layout.createParallelGroup(....)
                    .addComponent()
                    .addComponent())
                .addContainerGap(12, .))
        );
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = ...;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(11, 10, 11, 10);
        getContentPane().add(gridBagConstraints);
        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void maleRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_maleRadioButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_maleRadioButtonActionPerformed
    private void femaleRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_femaleRadioButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_femaleRadioButtonActionPerformed
    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_cancelButtonActionPerformed
    	cancelAccount();
    }// GEN-LAST:event_cancelButtonActionPerformed
    private void createButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_createButtonActionPerformed
        createAccount();
    }// GEN-LAST:event_createButtonActionPerformed

    

Parameters:
args the command line arguments
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CreateAccountFrame().setVisible(true);
            }
        });
    }
    public void setUserAccountService(UserAccountService userAccountService) {
        this. = userAccountService;
    }
        return ;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JButton createButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
New to GrepCode? Check out our FAQ X