Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package frauas.fb2.project.ordermanagement.view;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import java.awt.Font;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.ButtonGroup;
- import javax.swing.JFormattedTextField;
- import javax.swing.SwingConstants;
- import javax.swing.GroupLayout;
- import javax.swing.GroupLayout.Alignment;
- import javax.swing.JPasswordField;
- import javax.swing.JTextField;
- import javax.swing.LayoutStyle.ComponentPlacement;
- import javax.swing.JButton;
- import java.awt.Color;
- import javax.swing.JRadioButton;
- import javax.swing.JComboBox;
- import javax.swing.DefaultComboBoxModel;
- import frauas.fb2.project.ordermanagement.beans.User;
- import frauas.fb2.project.ordermanagement.controler.LoginControler;
- /**
- * This class is for the registration window.
- *
- * @author James Toribio
- * @version 1.0
- */
- public class SignUpView extends JFrame implements ActionListener{
- /**
- *
- */
- /*Some global Variables*/
- private static final long serialVersionUID = 1L;
- public JFrame frmSignUp;
- private JPasswordField passwordField;
- private JTextField textField;
- private JTextField txtFirstName;
- private JTextField txtPhoneNo;
- private JTextField txtEmail;
- private JTextField txtBIC;
- private JTextField textField_2;
- private JTextField txtLastName;
- private JTextField txtAddress;
- private JTextField txtZip;
- private JTextField txtCity;
- private JPasswordField passwordField_Confirm;
- private JTextField txtIBAN;
- private JRadioButton rdbtnCourier;
- private JRadioButton rdbtnInstitution;
- private JComboBox<String> comboBox;
- private User newUser;
- /**
- * Launch the application.
- */
- public void run() {
- try {
- SignUpView window = new SignUpView();
- window.frmSignUp.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * Create the application.
- */
- public SignUpView() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frmSignUp = new JFrame();
- frmSignUp.setTitle("Courier task tool - Sign Up");
- frmSignUp.getContentPane().setBackground(Coloring.LoginBackground);
- frmSignUp.setBounds(100, 100, 900, 650);
- frmSignUp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frmSignUp.setLocationRelativeTo(null);
- frmSignUp.setResizable(false);
- JLabel lblLogin = new JLabel("Registration");
- lblLogin.setForeground(new Color(255, 255, 255));
- lblLogin.setVerticalAlignment(SwingConstants.BOTTOM);
- lblLogin.setHorizontalAlignment(SwingConstants.CENTER);
- lblLogin.setFont(new Font("Tahoma", Font.BOLD, 40));
- JLabel lblEmail = new JLabel("E-Mail:");
- lblEmail.setForeground(new Color(255, 255, 255));
- lblEmail.setFont(new Font("Tahoma", Font.PLAIN, 20));
- JLabel lblPassword = new JLabel("Password:");
- lblPassword.setForeground(new Color(255, 255, 255));
- lblPassword.setFont(new Font("Tahoma", Font.PLAIN, 20));
- passwordField = new JPasswordField();
- textField = new JTextField();
- textField.setColumns(10);
- JButton btnSignUp = new JButton("Save");
- btnSignUp.setFont(new Font("Tahoma", Font.BOLD, 15));
- btnSignUp.addActionListener(this);
- btnSignUp.setActionCommand("cmd_save");
- JLabel lblName = new JLabel("First name:");
- lblName.setForeground(new Color(255, 255, 255));
- lblName.setFont(new Font("Tahoma", Font.PLAIN, 20));
- JLabel lblAddress = new JLabel("<html>Street name and <br>house number:</html>");
- lblAddress.setForeground(new Color(255, 255, 255));
- lblAddress.setFont(new Font("Tahoma", Font.PLAIN, 20));
- JLabel lblCountry = new JLabel("Country:");
- lblCountry.setForeground(Color.WHITE);
- lblCountry.setFont(new Font("Tahoma", Font.PLAIN, 20));
- JLabel lblPhoneNumber = new JLabel("Confirm Password:");
- lblPhoneNumber.setForeground(Color.WHITE);
- lblPhoneNumber.setFont(new Font("Tahoma", Font.PLAIN, 20));
- JLabel lblAccountInformations = new JLabel("Account Informations:");
- lblAccountInformations.setForeground(Color.WHITE);
- lblAccountInformations.setFont(new Font("Tahoma", Font.PLAIN, 20));
- rdbtnCourier = new JRadioButton("Courier");
- rdbtnCourier.setForeground(Color.WHITE);
- rdbtnCourier.setFont(new Font("Tahoma", Font.PLAIN, 15));
- rdbtnCourier.setBackground(Coloring.LoginBackground);
- rdbtnCourier.setActionCommand("CourierRadio");
- rdbtnCourier.addActionListener(this);
- rdbtnCourier.setSelected(true);
- JLabel lblRegisterAs = new JLabel("Register as:");
- lblRegisterAs.setForeground(Color.WHITE);
- lblRegisterAs.setFont(new Font("Tahoma", Font.PLAIN, 20));
- rdbtnInstitution = new JRadioButton("Institution");
- rdbtnInstitution.setForeground(Color.WHITE);
- rdbtnInstitution.setFont(new Font("Tahoma", Font.PLAIN, 15));
- rdbtnInstitution.setBackground(Coloring.LoginBackground);
- rdbtnInstitution.setActionCommand("InstitutionRadio");
- rdbtnInstitution.addActionListener(this);
- /*Adding a ButtonGroup for Courier Radio- and Institution RadioButton*/
- ButtonGroup btnGroup = new ButtonGroup();
- btnGroup.add(rdbtnCourier);
- btnGroup.add(rdbtnInstitution);
- txtFirstName = new JTextField();
- txtFirstName.setColumns(10);
- txtPhoneNo = new JTextField();
- txtPhoneNo.setColumns(10);
- txtEmail = new JTextField();
- JLabel label = new JLabel("Phone number:");
- label.setForeground(Color.WHITE);
- label.setFont(new Font("Tahoma", Font.PLAIN, 20));
- txtBIC = new JTextField();
- txtBIC.setColumns(10);
- /*################################################### LAYOUT START #####################################################################################*/
- comboBox = new JComboBox<>();
- comboBox.setFont(new Font("Tahoma", Font.PLAIN, 12));
- comboBox.setToolTipText("Choose your country");
- comboBox.setModel(new DefaultComboBoxModel<String>(new String[] {"Australia", "Belgium", "Germany", "USA"}));
- textField_2 = new JTextField();
- textField_2.setColumns(10);
- JLabel lblLastName = new JLabel("Last name:");
- lblLastName.setForeground(Color.WHITE);
- lblLastName.setFont(new Font("Tahoma", Font.PLAIN, 20));
- txtLastName = new JTextField();
- txtLastName.setColumns(10);
- JLabel lblIban = new JLabel("IBAN:");
- lblIban.setForeground(Color.WHITE);
- lblIban.setFont(new Font("Tahoma", Font.PLAIN, 20));
- JLabel lblBic = new JLabel("BIC:");
- lblBic.setForeground(Color.WHITE);
- lblBic.setFont(new Font("Tahoma", Font.PLAIN, 20));
- txtAddress = new JTextField();
- txtAddress.setColumns(10);
- txtZip = new JFormattedTextField();
- txtZip.setColumns(10);
- JLabel lblZipCode = new JLabel("Zipcode:");
- lblZipCode.setForeground(Color.WHITE);
- lblZipCode.setFont(new Font("Tahoma", Font.PLAIN, 20));
- JLabel lblCity = new JLabel("City:");
- lblCity.setForeground(Color.WHITE);
- lblCity.setFont(new Font("Tahoma", Font.PLAIN, 20));
- txtCity = new JTextField();
- txtCity.setColumns(10);
- passwordField_Confirm = new JPasswordField();
- txtIBAN = new JTextField();
- txtIBAN.setColumns(10);
- JButton btnCancel = new JButton("Cancel");
- btnCancel.setFont(new Font("Tahoma", Font.BOLD, 15));
- btnCancel.setActionCommand("cmd_cancel");
- btnCancel.addActionListener(this);
- GroupLayout groupLayout = new GroupLayout(frmSignUp.getContentPane());
- groupLayout.setHorizontalGroup(
- groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createSequentialGroup()
- .addGap(55)
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
- .addGroup(groupLayout.createSequentialGroup()
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addComponent(lblZipCode, GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
- .addComponent(lblCity, GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
- .addComponent(lblCountry, GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
- .addComponent(label, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
- .addComponent(lblEmail, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
- .addComponent(lblPassword, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
- .addComponent(lblPhoneNumber, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE))
- .addGap(10))
- .addGroup(groupLayout.createSequentialGroup()
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addComponent(lblLastName, GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
- .addComponent(lblAddress, GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
- .addGroup(groupLayout.createSequentialGroup()
- .addPreferredGap(ComponentPlacement.RELATED)
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addComponent(lblRegisterAs, GroupLayout.PREFERRED_SIZE, 126, GroupLayout.PREFERRED_SIZE)
- .addComponent(lblName, GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE))))
- .addPreferredGap(ComponentPlacement.UNRELATED)))
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
- .addComponent(comboBox, 0, 176, Short.MAX_VALUE)
- .addComponent(txtCity)
- .addComponent(txtEmail)
- .addComponent(txtZip, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
- .addComponent(txtPhoneNo))
- .addGroup(groupLayout.createSequentialGroup()
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
- .addComponent(txtLastName, Alignment.LEADING)
- .addComponent(txtFirstName, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
- .addGroup(groupLayout.createSequentialGroup()
- .addComponent(rdbtnCourier)
- .addGap(18)
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addComponent(lblLogin)
- .addGroup(groupLayout.createSequentialGroup()
- .addComponent(rdbtnInstitution)
- .addGap(122)
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addComponent(lblAccountInformations, GroupLayout.PREFERRED_SIZE, 212, GroupLayout.PREFERRED_SIZE)
- .addGroup(groupLayout.createSequentialGroup()
- .addComponent(btnSignUp, GroupLayout.PREFERRED_SIZE, 146, GroupLayout.PREFERRED_SIZE)
- .addGap(18)
- .addComponent(btnCancel, GroupLayout.PREFERRED_SIZE, 146, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(ComponentPlacement.RELATED))
- .addGroup(groupLayout.createSequentialGroup()
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
- .addComponent(lblIban)
- .addComponent(lblBic, GroupLayout.PREFERRED_SIZE, 51, GroupLayout.PREFERRED_SIZE))
- .addGap(18)
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addComponent(txtBIC, GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE)
- .addComponent(txtIBAN, GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE))))))))
- .addGap(292))
- .addComponent(txtAddress, GroupLayout.PREFERRED_SIZE, 241, GroupLayout.PREFERRED_SIZE)
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
- .addComponent(passwordField, Alignment.LEADING)
- .addComponent(passwordField_Confirm, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)))
- .addGap(30)
- .addComponent(textField_2, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE)
- .addGap(40)
- .addComponent(textField, 177, 177, Short.MAX_VALUE)
- .addContainerGap())
- );
- groupLayout.setVerticalGroup(
- groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createSequentialGroup()
- .addGap(29)
- .addComponent(lblLogin)
- .addGap(47)
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
- .addGroup(groupLayout.createSequentialGroup()
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
- .addComponent(textField, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
- .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
- .addComponent(lblRegisterAs, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
- .addComponent(rdbtnCourier)
- .addComponent(rdbtnInstitution)))
- .addPreferredGap(ComponentPlacement.UNRELATED))
- .addGroup(groupLayout.createSequentialGroup()
- .addComponent(lblAccountInformations, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
- .addGap(15)))
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createSequentialGroup()
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
- .addComponent(textField_2, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
- .addComponent(lblName, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))
- .addComponent(txtFirstName, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(ComponentPlacement.RELATED)
- .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
- .addComponent(txtLastName, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
- .addComponent(lblLastName, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)))
- .addGroup(groupLayout.createSequentialGroup()
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
- .addComponent(txtBIC, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
- .addComponent(lblIban, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(ComponentPlacement.UNRELATED)
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
- .addComponent(txtIBAN, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
- .addComponent(lblBic, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))))
- .addPreferredGap(ComponentPlacement.UNRELATED)
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addComponent(txtAddress, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
- .addComponent(lblAddress, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createSequentialGroup()
- .addGap(9)
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
- .addComponent(lblZipCode, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
- .addComponent(txtZip, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(ComponentPlacement.RELATED)
- .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
- .addComponent(lblCity, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
- .addComponent(txtCity, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(ComponentPlacement.RELATED)
- .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
- .addComponent(lblCountry, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
- .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE))
- .addGap(11)
- .addComponent(txtPhoneNo, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE))
- .addGroup(groupLayout.createSequentialGroup()
- .addGap(109)
- .addComponent(label, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)))
- .addGap(9)
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
- .addComponent(txtEmail, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
- .addComponent(lblEmail))
- .addPreferredGap(ComponentPlacement.UNRELATED)
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addComponent(lblPassword)
- .addComponent(passwordField, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(ComponentPlacement.UNRELATED)
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createSequentialGroup()
- .addComponent(passwordField_Confirm, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
- .addGap(24)
- .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
- .addComponent(btnSignUp, GroupLayout.PREFERRED_SIZE, 42, GroupLayout.PREFERRED_SIZE)
- .addComponent(btnCancel, GroupLayout.PREFERRED_SIZE, 42, GroupLayout.PREFERRED_SIZE)))
- .addComponent(lblPhoneNumber, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))
- .addContainerGap(26, Short.MAX_VALUE))
- );
- frmSignUp.getContentPane().setLayout(groupLayout);
- }
- /*########################################################## LAYOUT END #######################################################################################*/
- /**
- * Performs actions when Button is clicked
- *
- */
- @Override
- // Actions that will be executed when the corresponding button is clicked.
- public void actionPerformed(ActionEvent e)
- {
- /*Radio Button Courier*/
- if("CourierRadio".equals(e.getActionCommand()))
- {
- LoginControler ctr = LoginControler.getInstance();
- /*Create local variables*/
- // String[] firstName = new String[50];
- // String[] lastName = new String[50];
- // String[] address = new String[50];
- // String[] accInfo = new String[30];
- // int[] phoneNo = new int[15];
- // String[] eMail = new String[50];
- // frmSignUp.dispose();
- // LoginView login_window = new LoginView();
- // login_window.run();
- }
- /*Radio Button Institution*/
- else if("InstitutionRadio".equals(e.getActionCommand()))
- {
- // LoginControler ctr = new LoginControler();
- //
- // /*Create local variables*/
- // String[] firstName = new String[50];
- // String[] lastName = new String[50];
- // String[] address = new String[50];
- // String[] accInfo = new String[30];
- // int[] phoneNo = new int[15];
- // String[] eMail = new String[50];
- //
- // frmSignUp.dispose();
- // LoginView login_window = new LoginView();
- // login_window.run();
- }
- /*Save*/
- else if("cmd_save".equals(e.getActionCommand()))
- {
- LoginControler ctr = LoginControler.getInstance();
- //start
- String userid = "1";
- String name = txtFirstName.getText() + " " + txtLastName.getText();
- String address = txtAddress.getText() + ", " + txtZip.getText() +" "+txtCity.getText();
- String country = (String) comboBox.getSelectedItem();
- String accountinfo = "IBAN:" + txtIBAN.getText() + ", BIC:" + txtBIC.getText();
- String phoenenumber = txtPhoneNo.getText();
- String email = txtEmail.getText();
- String pass = passwordField.getText();
- String role = "";
- if(rdbtnCourier.isSelected())
- {
- role = "Courier";
- }else if(rdbtnInstitution.isSelected())
- {
- role = "Customer";
- }
- newUser = new User(userid, name, address, country, accountinfo, phoenenumber, email, pass, role, 0, false);
- try
- {
- ctr.register(newUser);
- }catch(Exception e1)
- {
- e1.printStackTrace();
- }
- JOptionPane.showMessageDialog(null, "Der Benutzer wurde Erfolgreich eingefügt.", "Erfolgreich eingefügt", JOptionPane.INFORMATION_MESSAGE);
- //ende
- /*Create local variables (to assign to the database (?)) | MAYBE NOT NEEDED*/
- // String[] firstName = new String[50];
- // String[] lastName = new String[50];
- // String[] address = new String[50];
- // String[] accInfo = new String[30];
- // int[] phoneNo = new int[15];
- // String[] eMail = new String[50];
- // frmSignUp.dispose();
- // LoginView login_window = new LoginView();
- // login_window.run();
- }
- /*Cancel*/
- else if("cmd_cancel".equals(e.getActionCommand()))
- {
- frmSignUp.dispose();
- LoginView login_window = new LoginView();
- login_window.run();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement