6 import java.text.DateFormat;
11 import java.awt.event.*;
14 import businessLogic.OfferManager;
16 import com.toedter.calendar.JCalendar;
18 import domain.RuralHouse;
20 public class IntroduceOffer2GUI extends JFrame {
22 private static final long serialVersionUID = 1L;
24 private JComboBox jComboBox1;
25 private JLabel jLabel1 = new JLabel();
26 private JLabel jLabel2 = new JLabel();
27 private JTextField jTextField1 = new JTextField();
28 private JLabel jLabel3 = new JLabel();
29 private JTextField jTextField2 = new JTextField();
30 private JLabel jLabel4 = new JLabel();
31 private JTextField jTextField3 = new JTextField();
32 private JButton jButton1 = new JButton();
34 private JCalendar jCalendar1 = new JCalendar();
35 private JCalendar jCalendar2 = new JCalendar();
36 private Calendar calendarInicio = null;
37 private Calendar calendarFin = null;
38 private JButton jButton2 = new JButton();
39 private JLabel jLabel5 = new JLabel();
41 public IntroduceOffer2GUI(Vector<RuralHouse> v) {
50 private void jbInit(Vector<RuralHouse> v) throws Exception {
51 this.getContentPane().setLayout(null);
52 this.setSize(new Dimension(513, 433));
53 this.setTitle("Set availability");
55 jComboBox1 = new JComboBox(v);
56 jComboBox1.setBounds(new Rectangle(115, 30, 115, 20));
57 jLabel1.setText("List of houses:");
58 jLabel1.setBounds(new Rectangle(25, 30, 95, 20));
59 jLabel2.setText("First day :");
60 jLabel2.setBounds(new Rectangle(25, 75, 85, 25));
61 jTextField1.setBounds(new Rectangle(25, 265, 220, 25));
62 jTextField1.setEditable(false);
63 jLabel3.setText("Last day :");
64 jLabel3.setBounds(new Rectangle(260, 75, 75, 25));
65 jTextField2.setBounds(new Rectangle(260, 265, 220, 25));
66 jTextField2.setEditable(false);
67 jLabel4.setText("Price:");
68 jLabel4.setBounds(new Rectangle(260, 30, 75, 20));
69 jTextField3.setBounds(new Rectangle(350, 30, 115, 20));
70 jTextField3.setText("0");
71 jButton1.setText("Accept");
72 jButton1.setBounds(new Rectangle(100, 360, 130, 30));
73 jTextField3.addFocusListener(new FocusListener() {
74 public void focusGained(FocusEvent e) {}
75 public void focusLost(FocusEvent e) {
76 jTextField3_focusLost();
79 jButton1.addActionListener(new ActionListener() {
80 public void actionPerformed(ActionEvent e) {
81 jButton1_actionPerformed(e);
84 jButton2.setText("Cancel");
85 jButton2.setBounds(new Rectangle(270, 360, 130, 30));
86 jButton2.addActionListener(new ActionListener() {
87 public void actionPerformed(ActionEvent e) {
88 jButton2_actionPerformed(e);
91 jLabel5.setBounds(new Rectangle(100, 320, 300, 20));
92 jLabel5.setForeground(Color.red);
93 jLabel5.setSize(new Dimension(305, 20));
94 jCalendar1.setBounds(new Rectangle(25, 100, 220, 165));
95 jCalendar2.setBounds(new Rectangle(260, 100, 220, 165));
98 this.jCalendar1.addPropertyChangeListener(new PropertyChangeListener() {
99 public void propertyChange(PropertyChangeEvent propertychangeevent) {
100 if (propertychangeevent.getPropertyName().equals("locale")) {
101 jCalendar1.setLocale((Locale) propertychangeevent.getNewValue());
102 DateFormat dateformat = DateFormat.getDateInstance(1, jCalendar1.getLocale());
103 jTextField1.setText(dateformat.format(calendarInicio.getTime()));
105 else if (propertychangeevent.getPropertyName().equals("calendar")) {
106 calendarInicio = (Calendar) propertychangeevent.getNewValue();
107 DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar1.getLocale());
108 jTextField1.setText(dateformat1.format(calendarInicio.getTime()));
109 jCalendar1.setCalendar(calendarInicio);
114 this.jCalendar2.addPropertyChangeListener(new PropertyChangeListener() {
115 public void propertyChange(PropertyChangeEvent propertychangeevent) {
116 if (propertychangeevent.getPropertyName().equals("locale")) {
117 jCalendar2.setLocale((Locale) propertychangeevent.getNewValue());
118 DateFormat dateformat = DateFormat.getDateInstance(1, jCalendar2.getLocale());
119 jTextField2.setText(dateformat.format(calendarFin.getTime()));
121 else if (propertychangeevent.getPropertyName().equals("calendar")) {
122 calendarFin = (Calendar) propertychangeevent.getNewValue();
123 DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar2.getLocale());
124 jTextField2.setText(dateformat1.format(calendarFin.getTime()));
125 jCalendar2.setCalendar(calendarFin);
130 this.getContentPane().add(jCalendar2, null);
131 this.getContentPane().add(jCalendar1, null);
132 this.getContentPane().add(jLabel5, null);
133 this.getContentPane().add(jButton2, null);
134 this.getContentPane().add(jButton1, null);
135 this.getContentPane().add(jTextField3, null);
136 this.getContentPane().add(jLabel4, null);
137 this.getContentPane().add(jTextField2, null);
138 this.getContentPane().add(jLabel3, null);
139 this.getContentPane().add(jTextField1, null);
140 this.getContentPane().add(jLabel2, null);
141 this.getContentPane().add(jLabel1, null);
142 this.getContentPane().add(jComboBox1, null);
145 private void jButton1_actionPerformed(ActionEvent e) {
146 RuralHouse ruralHouse=((RuralHouse)jComboBox1.getSelectedItem());
147 Date firstDay=new Date(jCalendar1.getCalendar().getTime().getTime());
148 //Remove the hour:minute:second:ms from the date
149 firstDay=Date.valueOf(firstDay.toString());
150 Date lastDay=new Date(jCalendar2.getCalendar().getTime().getTime());
151 //Remove the hour:minute:second:ms from the date
152 lastDay=Date.valueOf(lastDay.toString());
153 //It could be to trigger an exception if the introduced string is not a number
154 float price= Float.parseFloat(jTextField3.getText());
156 //Obtain the business logic from a StartWindow class (local or remote)
157 OfferManager offerM = new OfferManager();
159 offerM.createOffer(ruralHouse, firstDay, lastDay, price);
161 this.setVisible(false);
163 catch (Exception e1) {
164 e1.printStackTrace();
168 private void jButton2_actionPerformed(ActionEvent e) {
169 this.setVisible(false);
172 private void jTextField3_focusLost() {
174 new Integer (jTextField3.getText());
177 catch (NumberFormatException ex) {
178 jLabel5.setText("Error: Please introduce a number");