Package edu.spbstu.hoteldb.panels

Source Code of edu.spbstu.hoteldb.panels.RegisterPanel

package edu.spbstu.hoteldb.panels;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.GridPane;
import edu.spbstu.hoteldb.Main;
import edu.spbstu.hoteldb.handlers.NameFilter;
import edu.spbstu.hoteldb.handlers.RegisterQueryEventHandler;
import edu.spbstu.hoteldb.interfaces.Panel;

public class RegisterPanel extends GridPane implements Panel {
  Connection connect;

  @Override
  public void create(List<Object> args) {   
    this.setHgap(10);
    this.setVgap(10);
   
    final TextArea results = (TextArea)args.get(0);
    final Main main = (Main)args.get(1);
   
    Label llogin = new Label("Login: ");
    TextField tflogin = new TextField();
    tflogin.addEventHandler(KeyEvent.KEY_TYPED, new NameFilter());
    tflogin.setPromptText("3-16 symbols");
    Label lemail = new Label("Email: ");
    TextField tfemail = new TextField();
    tfemail.addEventHandler(KeyEvent.KEY_TYPED, new NameFilter());
    tfemail.setPromptText("Required");
    Label lpass = new Label("Password: ");
    PasswordField tfpass = new PasswordField();
    tfpass.addEventHandler(KeyEvent.KEY_TYPED, new NameFilter());
    tfpass.setPromptText("Required");
    Label lname = new Label("Name: ");
    TextField tfname = new TextField();
    tfname.setPromptText("Required");
    tfname.addEventHandler(KeyEvent.KEY_TYPED, new NameFilter());
    Label lcountry = new Label("Country: ");
    ChoiceBox<String> cbcountry = new ChoiceBox<String>(
        FXCollections.observableArrayList("Russia", "Spain", "USA",
            "UK"));
    Label llang = new Label("Language: ");
    ChoiceBox<String> cblang = new ChoiceBox<String>(
        FXCollections.observableArrayList("ru", "es", "en", "ger"));
    Button btnthis = new Button("Register");
    List<Node> hargs = new ArrayList<Node>(6);
    hargs.add(0, tflogin);
    hargs.add(1, tfemail);
    hargs.add(2, tfpass);
    hargs.add(3, tfname);
    hargs.add(4, cbcountry);
    hargs.add(5, cblang);
    btnthis.setOnAction(new RegisterQueryEventHandler(connect, results,
        main, hargs));
    Button btnback = new Button("Back");
    btnback.setOnAction(new EventHandler<ActionEvent>() {
      @Override
      public void handle(ActionEvent event) {
        main.setPanel(PanelType.LoginPanel, null);
      }
    });
    this.add(llogin, 0, 0);
    this.add(tflogin, 1, 0);
    this.add(lpass, 0, 1);
    this.add(tfpass, 1, 1);
    this.add(lemail, 0, 2);
    this.add(tfemail, 1, 2);
    this.add(lname, 0, 3);
    this.add(tfname, 1, 3);
    this.add(lcountry, 0, 4);
    this.add(cbcountry, 1, 4);
    this.add(llang, 0, 5);
    this.add(cblang, 1, 5);
    this.add(btnthis, 0, 6);
    this.add(btnback, 1, 6);
  }
 
  @Override
  public void connect() throws ClassNotFoundException, SQLException {
    Class.forName("com.mysql.jdbc.Driver");
    connect = DriverManager
        .getConnection("jdbc:mysql://localhost/hotel_db?"
            + "user=hoteldb_reg&password=reg");
  }

  @Override
  public void close() throws SQLException {
    connect.close();
  }
}
TOP

Related Classes of edu.spbstu.hoteldb.panels.RegisterPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.