From c51acfe72996e440259af7da10c89a33fd059e2a Mon Sep 17 00:00:00 2001 From: camjan Date: Fri, 27 Feb 2015 12:59:09 +0100 Subject: [PATCH] Login GUI completed --- ruralHouses/db/DBjcampos004.yap | Bin 3933 -> 3705 bytes ruralHouses/src/configuration/Config.java | 2 - ruralHouses/src/gui/IntroduceOfferGUI.java | 110 +++++++++++---------- ruralHouses/src/gui/StartWindow.java | 7 +- 4 files changed, 62 insertions(+), 57 deletions(-) diff --git a/ruralHouses/db/DBjcampos004.yap b/ruralHouses/db/DBjcampos004.yap index 672ef193be65b0c8c908202683e6d4541f32aea4..a4f2ba588b08a050f7bf95e9760015ee41d669a1 100644 GIT binary patch delta 143 zcmcaB_fv*7CCMb8adIP{_~Z$E9Gr{{42%mH7}$Po)b(K0TDp+6<5c!91_lO&bOQqu zOLJp06BA2ALzATB#6;6XLjzMIGgA`-GegVC^BEOcf-W>QY(B#Hj**MW5~zm>h|f&k j!z{1p3uN&!Ffca*X#t>wB9ImY^0Oc`+r!O&m}|KJx;`Pf delta 330 zcmewu?Tmckf1fm5%ny(T_SOW1zT@OaB{Iq2qr?P(mxeDn9 z1}2u~#%3lamWGBVNy&+3X=Y}LW=UqLCYGit29xJADzcbw4rbVVgz+6C7sDB#9ws2N zoVKO6u6 diff --git a/ruralHouses/src/configuration/Config.java b/ruralHouses/src/configuration/Config.java index 756c01b..164bca9 100644 --- a/ruralHouses/src/configuration/Config.java +++ b/ruralHouses/src/configuration/Config.java @@ -8,10 +8,8 @@ public class Config { private final String serviceRMI = "RuralHouses"; - //private final String javaPolicyPath="/Users/joniturrioz/Asignaturas/gradoISO/CasaRuralSG/java.policy"; private final String javaPolicyPath="java.policy"; - //final static String db4oFilename = "/Users/joniturrioz/DB/ruralHouses.db4o"; private final String db4oFilename = "db/DBjcampos004.yap"; //Two possible values: "open" or "initialize" diff --git a/ruralHouses/src/gui/IntroduceOfferGUI.java b/ruralHouses/src/gui/IntroduceOfferGUI.java index 5d768e8..77d1488 100644 --- a/ruralHouses/src/gui/IntroduceOfferGUI.java +++ b/ruralHouses/src/gui/IntroduceOfferGUI.java @@ -1,21 +1,26 @@ package gui; import javax.swing.*; -import java.awt.Rectangle; +import java.awt.Frame; +import java.awt.Rectangle; import java.util.Vector; import businessLogic.ApplicationFacadeInterface; import domain.Owner; import domain.RuralHouse; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; public class IntroduceOfferGUI extends JFrame { private static final long serialVersionUID = 1L; private JPanel jContentPane = null; - private JComboBox jComboBox = null; - private JButton jButton = null; + private JTextField usernameField; + private JPasswordField passwordField; + private JTextField textField; + private LoginManager loginManager = new LoginManagerInterface(); public IntroduceOfferGUI() { super(); @@ -25,7 +30,7 @@ public class IntroduceOfferGUI extends JFrame { private void initialize() { this.setSize(449, 293); this.setContentPane(getJContentPane()); - this.setTitle("Choose owner"); + this.setTitle("Login"); } @@ -33,58 +38,55 @@ public class IntroduceOfferGUI extends JFrame { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(null); - jContentPane.add(getJComboBox(), null); - jContentPane.add(getJButton(), null); - } - return jContentPane; - } - - private JComboBox getJComboBox() { - if (jComboBox == null) { - try { - ApplicationFacadeInterface facade=StartWindow.getBusinessLogic(); - Vector owners=facade.getOwners(); - jComboBox = new JComboBox(owners); - jComboBox.setBounds(new Rectangle(63, 38, 175, 44)); - } - catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - return jComboBox; - } - - private JButton getJButton() { - if (jButton == null) { - jButton = new JButton(); - jButton.setBounds(new Rectangle(113, 146, 95, 59)); - jButton.setText("Show houses"); - jButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - Owner owner=(Owner)jComboBox.getSelectedItem(); - System.out.println(owner.getUsername()); - Vector houseList=null; - try { - //Obtain the business logic from a StartWindow class (local or remote) - ApplicationFacadeInterface facade=StartWindow.getBusinessLogic(); - houseList=facade.getRuralHouses(owner); - - } - catch (Exception e1) { - e1.printStackTrace(); - } - if (houseList.isEmpty()!=true) { - JFrame a = new IntroduceOffer2GUI(houseList); - a.setVisible(true); + + JLabel usernameTag = new JLabel("Username:"); + usernameTag.setBounds(56, 67, 104, 20); + jContentPane.add(usernameTag); + + JLabel passwordTag = new JLabel("Password:"); + passwordTag.setBounds(56, 132, 104, 15); + jContentPane.add(passwordTag); + + usernameField = new JTextField(); + usernameField.setBounds(208, 68, 114, 19); + jContentPane.add(usernameField); + usernameField.setColumns(10); + + passwordField = new JPasswordField(); + passwordField.setBounds(208, 129, 114, 18); + jContentPane.add(passwordField); + + JButton loginButton = new JButton("Login"); + loginButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + Owner owner = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword()); + if(owner==null){ + textField.setText("Incorrect username or password"); + }else{ + Vector ownerHouseList=null; + try{ + ownerHouseList = StartWindow.getBusinessLogic().getRuralHouses(owner); + }catch (Exception e){ + e.printStackTrace(); + } + if(!ownerHouseList.isEmpty()){ + Frame a = new IntroduceOffer2GUI(ownerHouseList); + a.setVisible(true); + } + else if(ownerHouseList.isEmpty()) + textField.setText("Login OK , but no houses in your name"); } - else if (houseList.isEmpty()==true) { - System.out.print("Owner does not exist or has no registered houses "); - } + } }); + loginButton.setBounds(151, 178, 117, 25); + jContentPane.add(loginButton); + + textField = new JTextField(); + textField.setBounds(127, 227, 185, 26); + jContentPane.add(textField); + textField.setColumns(10); } - return jButton; + return jContentPane; } - -} // @jve:decl-index=0:visual-constraint="222,33" +} // @jve:decl-index=0:visual-constraint="222,33" diff --git a/ruralHouses/src/gui/StartWindow.java b/ruralHouses/src/gui/StartWindow.java index b6afbf1..4c0ec76 100644 --- a/ruralHouses/src/gui/StartWindow.java +++ b/ruralHouses/src/gui/StartWindow.java @@ -1,12 +1,16 @@ package gui; import javax.swing.*; + import java.awt.*; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import businessLogic.FacadeImplementation; import businessLogic.ApplicationFacadeInterface; import java.rmi.*; + import configuration.Config; public class StartWindow extends JFrame { @@ -26,7 +30,7 @@ public class StartWindow extends JFrame { public StartWindow() { super(); initialize(); - this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static ApplicationFacadeInterface getBusinessLogic(){ @@ -120,6 +124,7 @@ public class StartWindow extends JFrame { try { facade.close(); setVisible(false); + System.exit(1); } catch (RemoteException e1) { // TODO Auto-generated catch block -- 2.20.1