Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package client;
- import java.awt.BorderLayout;
- public class Login extends JDialog {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private JPanel contentPane;
- private JTextField usernameTextField;
- private JPasswordField passwordTextField;
- private JButton btnLogin;
- private JButton btnRegister;
- private String dbURL;
- private String user;
- private String pw;
- private boolean loginSuccess;
- private String[] query = null;
- public boolean loginReq = false;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Login login = new Login(new JFrame(), "Login");
- login.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public Login(final JFrame parent, String title) {
- super(parent, title, true);
- if (parent != null) {
- Dimension parentSize = parent.getSize();
- Point p = parent.getLocation();
- setLocation(p.x + parentSize.width / 4, p.y + parentSize.height / 4);
- }
- //set user & pw dbURl
- setUser("s3392695");//TODO
- setPw("sadi12");
- setDbURL("jdbc:oracle:thin:@emu.cs.rmit.edu.au:1521:GENERAL");
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- JLabel lblUsername = new JLabel("Username:");
- JLabel lblPassword = new JLabel("Password:");
- usernameTextField = new JTextField();
- usernameTextField.setColumns(10);
- passwordTextField = new JPasswordField();
- passwordTextField.setColumns(10);
- btnRegister = new JButton("Register");
- btnRegister.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- Register register = new Register(parent, "Register");
- query = register.getQuery();
- dispose();
- }
- });
- btnLogin = new JButton("Login");
- btnLogin.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- //fill query
- query = new String []{"Login", getUsernameTextField(), getPasswordTextField()};
- loginReq = true;
- dispose();
- // try {
- // Class.forName("oracle.jdbc.driver.OracleDriver");
- //
- //
- // Connection con = DriverManager.getConnection(""+getDbURL(),getUser(),getPw());
- // Statement stmt = con.createStatement();
- // // stmt.execute("CREATE DATABASE IF NOT EXISTS usersDB");
- // // stmt.execute("Use usersDB");
- // //table exist
- //
- //
- // ResultSet rs = stmt.executeQuery("select * from tab where tname='users'");
- //
- // if(!rs.next()){
- // stmt.executeUpdate("create table users (username varchar(15), password varchar(20), firstname varchar(15), lastname varchar(15), address varchar(30), phonenumber varchar(12))");
- // }
- //
- //
- // Statement stmt1 = con.createStatement();
- // //check username and pw
- // ResultSet rs1 = stmt1.executeQuery("SELECT * FROM users WHERE username = '"+getUsernameTextField()+"'");
- // if(rs1.next()){
- // if(rs1.getString("password").compareTo(getPasswordTextField())==0){
- // //set Login flag
- // loginSuccess = true;
- // System.out.println("Login succesful!");
- // }
- // }else{
- // System.out.println("Username doesn't exist!");
- // }
- // stmt.close();
- // stmt1.close();
- // rs1.close();
- // con.close();
- //
- //
- //
- // } catch (ClassNotFoundException e) {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }catch(SQLException sqlex){
- // //TODO
- // sqlex.printStackTrace();
- // System.out.println(sqlex.getMessage());
- // }
- // // Sends the login status to the server
- // if(loginSuccess){
- //
- // }else{
- // }
- }
- });
- GroupLayout gl_contentPane = new GroupLayout(contentPane);
- gl_contentPane.setHorizontalGroup(
- gl_contentPane.createParallelGroup(Alignment.LEADING)
- .addGroup(gl_contentPane.createSequentialGroup()
- .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
- .addGroup(gl_contentPane.createSequentialGroup()
- .addContainerGap()
- .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
- .addComponent(lblPassword, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(lblUsername, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addPreferredGap(ComponentPlacement.UNRELATED)
- .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
- .addComponent(passwordTextField)
- .addComponent(usernameTextField)))
- .addGroup(gl_contentPane.createSequentialGroup()
- .addGap(30)
- .addComponent(btnLogin)
- .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(btnRegister)))
- .addContainerGap(266, Short.MAX_VALUE))
- );
- gl_contentPane.setVerticalGroup(
- gl_contentPane.createParallelGroup(Alignment.LEADING)
- .addGroup(gl_contentPane.createSequentialGroup()
- .addContainerGap()
- .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
- .addComponent(lblUsername)
- .addComponent(usernameTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(ComponentPlacement.RELATED)
- .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
- .addComponent(lblPassword)
- .addComponent(passwordTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(ComponentPlacement.RELATED)
- .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
- .addComponent(btnLogin)
- .addComponent(btnRegister))
- .addContainerGap(166, Short.MAX_VALUE))
- );
- contentPane.setLayout(gl_contentPane);
- getContentPane().add(contentPane);
- setDefaultCloseOperation(DISPOSE_ON_CLOSE);
- pack();
- setVisible(true);
- }
- public String getDbURL() {
- return dbURL;
- }
- public void setDbURL(String dbURL) {
- this.dbURL = dbURL;
- }
- public String getUser() {
- return user;
- }
- public void setUser(String user) {
- this.user = user;
- }
- public String getPw() {
- return pw;
- }
- public void setPw(String pw) {
- this.pw = pw;
- }
- public String getUsernameTextField() {
- return usernameTextField.getText();
- }
- public String getPasswordTextField() {
- return passwordTextField.getText();
- }
- public String[] getQuery() {
- // TODO Auto-generated method stub
- return query;
- }
- }
Add Comment
Please, Sign In to add comment