From: camjan Date: Fri, 27 Feb 2015 11:59:09 +0000 (+0100) Subject: Login GUI completed X-Git-Url: https://xp-dev.com/git/RRRRHHHH_Code/commitdiff_plain/c51acfe72996e440259af7da10c89a33fd059e2a Login GUI completed --- diff --git a/ruralHouses/db/DBjcampos004.yap b/ruralHouses/db/DBjcampos004.yap index 672ef19..a4f2ba5 100644 Binary files a/ruralHouses/db/DBjcampos004.yap and b/ruralHouses/db/DBjcampos004.yap differ 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