|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I currently have one GUI window called 'Ossian'
and one Class called 'Holiday' this is a travel holiday package, which allows the user to input holidays, which are stored in an array then later saved to file. (the saved to file will be worryed about later) just now all im after is allowing the holidays to be stored in the array. basically i've got 7 blank textboxes, where you insert holiday details into, then click the add button. It then adds that holiday to an array which can hold up to 50. the class holds all the varible's from the textboxes it has recived so they can be used around my program. here is my code i attempted to do. it runs but i dont think its storing the values in the class at all. or im displaying it incorrectly. all im trying to achive here is to add holidays to an array at this stage, the display was put in simply to see if it added at all. am i coding this correctly to add a holiday to an array? Main GUI Code: public class Ossian extends javax.swing.JFrame { static Holiday h[] = new Holiday[50]; static int count; public Ossian() { initComponents(); } public static void EnterHoliday() { jTextField1.setText(""); jTextField2.setText(""); jTextField3.setText(""); jTextField4.setText(""); jTextField5.setText(""); jTextField6.setText(""); jTextField7.setText(""); h[count].Resort = "" + jTextField1.getText (); h[count].Airport = "" + jTextField2.getText (); h[count].Accomodation = "" + jTextField3.getText (); h[count].Departure_date = "" + jTextField4.getText (); h[count].Length_stay = "" + jTextField5.getText (); h[count].Price = "" + jTextField6.getText (); h[count].Holiday_ref_no = "" + jTextField7.getText (); } public static void displayHolidays() { jLabel1.setText(h[count].Resort); jLabel2.setText(h[count].Airport); jLabel3.setText(h[count].Accomodation); jLabel4.setText(h[count].Departure_date); jLabel5.setText(h[count].Length_stay); jLabel6.setText(h[count].Price); jLabel7.setText(h[count].Holiday_ref_no); } public static void initialiseHolidays() { int count; for(count=0;count<50;count++) { h[count] = new Holiday(); h[count].Resort = "XXX"; } } public static void AddHolidayDetails() { int index = 0; while(!(h[index].Resort.equals("XXX"))&& index < 50) { index ++; } if(index==50) { jLabel8.setText("FULL UP - NO ROOM TO ADD"); } else { EnterHoliday(); } } public static void ListHolidayDetails() { int count = 0; while(!(h[count].Resort.equals("XXX"))&& count < 50) { displayHolidays(); count++; } } private void initComponents() { jTextField1 = new javax.swing.JTextField(); jTextField2 = new javax.swing.JTextField(); jTextField3 = new javax.swing.JTextField(); jTextField4 = new javax.swing.JTextField(); jTextField5 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jTextField6 = new javax.swing.JTextField(); jTextField7 = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); getContentPane().setLayout(null); setTitle("Ossian Travel - Add Holiday"); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); jTextField1.setText("jTextField1"); getContentPane().add(jTextField1); jTextField1.setBounds(50, 40, 230, 20); jTextField2.setText("jTextField2"); getContentPane().add(jTextField2); jTextField2.setBounds(50, 80, 230, 20); jTextField3.setText("jTextField3"); getContentPane().add(jTextField3); jTextField3.setBounds(50, 120, 230, 20); jTextField4.setText("jTextField4"); getContentPane().add(jTextField4); jTextField4.setBounds(50, 160, 230, 20); jTextField5.setText("jTextField5"); getContentPane().add(jTextField5); jTextField5.setBounds(50, 200, 230, 20); jButton1.setText("Add"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); getContentPane().add(jButton1); jButton1.setBounds(310, 130, 60, 26); jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0))); getContentPane().add(jPanel1); jPanel1.setBounds(20, 330, 360, 12); jLabel1.setText("jLabel1"); getContentPane().add(jLabel1); jLabel1.setBounds(20, 360, 160, 16); jLabel2.setText("jLabel2"); getContentPane().add(jLabel2); jLabel2.setBounds(20, 390, 160, 16); jLabel3.setText("jLabel3"); getContentPane().add(jLabel3); jLabel3.setBounds(20, 420, 160, 16); jLabel4.setText("jLabel4"); getContentPane().add(jLabel4); jLabel4.setBounds(20, 450, 170, 16); jLabel5.setText("jLabel5"); getContentPane().add(jLabel5); jLabel5.setBounds(20, 480, 200, 16); jTextField6.setText("jTextField6"); getContentPane().add(jTextField6); jTextField6.setBounds(50, 240, 230, 20); jTextField7.setText("jTextField7"); getContentPane().add(jTextField7); jTextField7.setBounds(50, 280, 230, 20); jLabel6.setText("jLabel6"); getContentPane().add(jLabel6); jLabel6.setBounds(20, 510, 160, 16); jLabel7.setText("jLabel7"); getContentPane().add(jLabel7); jLabel7.setBounds(20, 540, 230, 16); jLabel8.setText("jLabel8"); getContentPane().add(jLabel8); jLabel8.setBounds(70, 580, 280, 16); pack(); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize (); setSize(new java.awt.Dimension(400, 684)); setLocation((screenSize.width-400)/2,(screenSize.height-684)/2); } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { EnterHoliday(); displayHolidays(); } /** Exit the Application */ private void exitForm(java.awt.event.WindowEvent evt) { System.exit(0); } public static void main(String args[]) { initialiseHolidays(); new Ossian().show(); } // Variables declaration - do not modify private static javax.swing.JLabel jLabel8; private static javax.swing.JTextField jTextField6; private static javax.swing.JLabel jLabel4; private static javax.swing.JTextField jTextField7; private static javax.swing.JLabel jLabel1; private static javax.swing.JLabel jLabel3; private static javax.swing.JTextField jTextField3; private static javax.swing.JLabel jLabel2; private javax.swing.JButton jButton1; private static javax.swing.JTextField jTextField5; private static javax.swing.JLabel jLabel7; private javax.swing.JPanel jPanel1; private static javax.swing.JTextField jTextField2; private static javax.swing.JLabel jLabel6; private static javax.swing.JTextField jTextField1; private static javax.swing.JTextField jTextField4; private static javax.swing.JLabel jLabel5; // End of variables declaration } Class Holiday Code: public class Holiday { String Resort; String Airport; String Accomodation; String Holiday_ref_no; String Departure_date; String Length_stay; String Price; public Holiday() { } } |
|
#2
|
|||
|
|||
|
ok i found out why, it was because i was clearing the text fields before it. that was having some effect. however my array is letting me add as many holidays as i want, it should however max out at 50
public static void AddHolidayDetails() { int index = 0; while(!(h[index].Resort.equals("XXX"))&& index < 50) { index ++; } if(index==50) { jLabel8.setText("FULL UP - NO ROOM TO ADD"); } else { EnterHoliday(); } } |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Java Project Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|