Results 1 to 5 of 5
  1. #1
    Ian
    Ian is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Unhappy Problems Working in GUI

    Hi everyone,
    I'm fairly new to Java, and as an assignment I have been asked to create an appointment book, including a start time, end time, description, and location. Here are the specifications for the assignment:

    BACKGROUND:

    CTime - implements Serializable,
    CAppointment - implements Serializable,
    CDailyAppointmentBook - instead of using an array, use a custom linked list class or a built in class (such as vector or List) from the utility api in order to maintain the list of appointments.
    GUIAppointmentApp - extends JFrame. Enables GUI components for the menu described below and initializes the application.

    A GUI menu (use Swing components such as buttons, textfields and labels).
    The GUI has the following functionality:
    1. ADD - Create new appointment, and adds it to the vector
    2. EDIT - Edits the contents of one appointment
    3. DELETE - Deletes the currently displayed appointment from the vector.
    4. You only display one appointment record at a time, provide NEXT and PREVIOUS buttons to allow the user to preview other records in the vector
    5. LOAD - destroy the contents of the current vector and load a new one (prompt for file name).
    6. SAVE - save the current vector into a file (prompt for file name) - use Serialization.
    7. EXIT

    WHAT I DID:
    I've coded most of this program, however I strayed away from a few of the requirements:
    ---> I had my CDailyAppointmentBook class extend JFrame along with the components for my menu
    ---> I created a "a_canvas" class that includes JPanel and the vector that contains the appointments of my application

    MY PROBLEM:
    ---> All of my code works except for the next and previous buttons required for my code (instead, my code just paints each appointment as it's added to the vector). After searching for a while, I THINK there is a way to do this with a listIterator, but nothing I've tried seems to work.
    ---> I am having trouble deleting an appointment (should be deleted by start time). I understand that setting an object to null will release it for the garbage collector, but if my code is deleting the object (and I'm not sure if it actually is), the GUI is still displaying it.

    If you guys need more information or code let me know. I'd appreciate any insight you can give!

    Cheers,
    Ian

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Problems Working in GUI

    Quote Originally Posted by Ian View Post
    I've coded most of this program, however I strayed away from a few of the requirements:
    ---> I had my CDailyAppointmentBook class extend JFrame along with the components for my menu
    Don't do this. You need to first create a well-behaved working model before you can build a GUI around it. Do what your instructions tell you to do as they will promote good programming habits and a allow you to create a more flexible and robust program.

  3. #3
    Ian
    Ian is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Re: Problems Working in GUI

    Ya I really wish I didn't stray away from them, I'm kicking myself for it now. It is just under 750 lines of code... I don't want to rebuild it, is there any way I can work with the code I have?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Problems Working in GUI

    Quote Originally Posted by Ian View Post
    Ya I really wish I didn't stray away from them, I'm kicking myself for it now. It is just under 750 lines of code... I don't want to rebuild it, is there any way I can work with the code I have?
    I don't know. It's hard to say without the code.

  5. #5
    Ian
    Ian is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Re: Problems Working in GUI

    Alright, here is the code. To anyone that has the patience to actually read through it I would really really appreciate it!

    My CTime class:
    Java Code:
    package assignment2;
    
    import java.io.Serializable;
    import java.util.Scanner;
    
    /**
     * Class CTime: This class is designed to create a valid time using military time minutes and hours only. The class can be invoke using an overloaded constructor
     * 				or a copy constructor to be used with applications involving time
     * 
     * 				@author Ian Harlow	Student ID: 103475617
     *
     */
    
    @SuppressWarnings("serial")
    public class CTime implements Serializable{
    	int hour;		/** between 0 and 23 inclusive */
    	int minute;		/** between 0 and 59 */
    	
    	public CTime(String specs){
    		Scanner s = new Scanner(specs);
    		setTime(s.nextInt(),s.nextInt());
    	}
    	
    	/** constructor */
    	public CTime(int hour, int minute){
    		setTime(hour, minute);
    	}
    	
    	/** copy constructor */
    	public CTime(CTime t){
    		hour = t.getHour();
    		minute = t.getMinute();
    	}
    	
    	public void setTime(int hour, int minute){
    		if (isValidTime(hour, minute)){						/**Check if valid time*/
    			this.hour = hour;								/**valid, assign values*/
    			this.minute = minute;
    		}
    	}
    	
    	private boolean isValidTime(int hour, int minute){
    		return (isBetween(hour, 7, 19) && isBetween(minute, 00, 59));		/**hour must be between 7 and 19, minute between 00 and 59*/
    	}
    	
    	private boolean isBetween(int n, int min, int max){
    		return (n >= min && n <= max);										/**arbitrary value n must be between minimum and maximum allowable values*/
    	}
    	
    	public String toString(){
    		return "" + hour + ":" + minute;					/**display value*/
    	}
    	
    	public int getHour(){
    	return hour;											/**retrieve hour value*/
    	}	
    	
    	public int getMinute(){
    	return minute;											/**retrieve minute value*/
    	}
    }
    My CAppointment class:
    Java Code:
    package assignment2;
    
    /**
     * Class CAppointment: 	Maintains a valid appointment. This class is only valid for a single appointment that has a valid start time, end time, description,
     * 						and location. The start time must be before the end time and the locations must be constants specified as ER, MH, OB, EH, DH. This
     * 						will calculate the duration of an appointment and ensure that future appointments created will not overlap with one another. It also has the
     * 						functionality to edit an appointment specified by an application that maintains a list of appointments. Finally, this class can delete an 
     * 						appointment specified by an application that maintains a list of appointments
     *
     * 						@author Ian Harlow		Student ID: 103475617						
     */
    
    import java.awt.Color;
    import java.awt.Graphics;
    import java.io.Serializable;
    import java.util.NoSuchElementException;
    import java.util.Scanner;
    
    import javax.swing.JOptionPane;
    
    @SuppressWarnings("serial")
    public class CAppointment implements Serializable{
    	private static final String LOCATIONS[] = {"ER","MH","OB","EH","DH"};								/**constants for location*/
    	private CTime startTime;
    	private CTime endTime;
    	private String description;
    	private String location;
    	protected Color color = Color.RED;
    	public static int count = 55;
    	
    	public CAppointment(String specs)  throws NoSuchElementException
    	{
    			Scanner s = new Scanner(specs);
    			setStartTime(new CTime(s.nextInt(),s.nextInt()));
    			setEndTime(new CTime(s.nextInt(),s.nextInt()));
    			setDescription(s.next());
    			setLocation(s.next());
    	}
    	
    	
    	
    	protected void DrawAppointment(Graphics g) {
    		CAppointment draw = new CAppointment(startTime,endTime,description,location);
    		g.setColor(color);
    		g.drawString(draw.toString(),25,count);
    		count+=10;
    	}
    	
    	
    	
    	public CAppointment(CTime st, CTime et, String descript, String locat){
    		if(consistent(st,et)){												/**check for consistency (start time before end time)*/
    			startTime = new CTime(st.getHour(),st.getMinute());				/**invoke the overloaded constructor*/
    			endTime = new CTime(et);										/**invoke the copy constructor*/
    			this.description = descript;
    			this.location = locat;
    		}
    		else{
    			System.out.println("INVALID APPOINTMENT TIME");					/**inconsistent*/
    			System.exit(0);
    		}
    	}
    	
    	private static boolean consistent(CTime st, CTime et){
    		if (st == null){
    			return false;											/**must be start time*/
    		}
    		else if(et == null){
    			return false;											/**must be end time*/
    		}		
    		else if(st.getHour() < et.getHour()){
    			return true;											/**start hour smaller*/
    		}
    		else if(st.getHour() == et.getHour()){						/**start hour equal*/
    			if(st.getMinute() < et.getMinute()){					/**minute smaller*/
    				return true;
    			}
    		}	
    		return false;												/**everything else, false*/
    	}
    	
    	/**assume that no appointment lasts more than 23:59*/
    	public CTime calculateDuration(){								/**this method was supposed to calculate the duration of an appointment to avoid overlapping*/
    		int diffmin;
    		int diffhour;
    		CTime duration;
    		
    		diffmin = startTime.getMinute() - endTime.getMinute();		/**difference in minutes*/
    		diffhour = startTime.getHour() - endTime.getHour();			/**difference in hours*/
    		duration = new CTime(diffhour,diffmin);						/**instance of duration*/
    		
    		return duration;											/**return duration*/
    	}
    	
    	public void editAppointment(CAppointment editByST){					/**edit an appointment by start time*/
    																		/**allow user to input from keyboard*/
    		int hours1, minutes1;
    		int hours2, minutes2;
    		String check;
    		
    		try{
    			JOptionPane.showMessageDialog(null, "Editing Appointment at " + editByST);
    			
    			String specs = JOptionPane.showInputDialog("Do you need to reschedule? What time will the appointment start?");
    			Scanner keyboard = new Scanner(specs);
    			if(specs!=null){
    				hours1 = keyboard.nextInt();																/**enter new hours*/
    				minutes1 = keyboard.nextInt();																/**enter new minutes*/
    				editByST.setStartTime(new CTime(hours1,minutes1));											/**set new start time*/
    			}
    			
    			String specs2 = JOptionPane.showInputDialog("What time will the appointment end?");
    			Scanner keyboard2 = new Scanner(specs2);
    			if(specs2!=null){
    				hours2 = keyboard2.nextInt();																/**enter new hours*/
    				minutes2 = keyboard2.nextInt();																/**enter new minutes*/
    				//keyboard2.nextLine();																	
    				editByST.setEndTime(new CTime(hours2,minutes2));											/**set new end time*/
    			}
    			
    			String specs3 = JOptionPane.showInputDialog("What is the new description?");
    			Scanner keyboard3 = new Scanner(specs3);
    			if(specs3!=null){
    				editByST.setDescription(keyboard3.nextLine());												/**new description*/
    			}
    			
    			String specs4 = JOptionPane.showInputDialog("Where is this appointment located?");
    			Scanner keyboard4 = new Scanner(specs4);
    			if(specs4!=null){
    				check = keyboard4.nextLine();														
    				editByST.setLocation(check);																/**new location*/
    			}
    			
    			JOptionPane.showMessageDialog(null, "Appointment edited");
    		}
    		catch(Exception e){
    			JOptionPane.showMessageDialog(null, "You must write in the textfield!", "warning", JOptionPane.WARNING_MESSAGE);
    		}
    	}
    	
    	public CAppointment deleteAppointment(CAppointment toDelete, CAppointment toReplace){		/**for deleting an appointment*/
    		toDelete = toReplace;
    		return toDelete;
    	}
    	
    	public void setStartTime(CTime st){	
    		this.startTime = st;
    	}
    	
    	public CTime getStartTime(){
    		return startTime;
    	}
    	
    	public void setEndTime(CTime et){
    		boolean retry=false;
    		do{
    			if(consistent(this.startTime,et)){		/**must check for consistency*/
    				this.endTime = et;
    				retry=false;
    			}
    			else{
    				JOptionPane.showMessageDialog(null, "You're start time and end time are inconsistent!", "warning", JOptionPane.WARNING_MESSAGE);
    				String specs = JOptionPane.showInputDialog("What time will the appointment end?");
    				Scanner keyboard = new Scanner(specs);
    				if(specs!=null){
    					et.hour = keyboard.nextInt();
    					et.minute = keyboard.nextInt();
    					retry=true;
    				}
    			}
    		}while(retry==true);
    	}
    	
    	
    	
    	public CTime getEndTime(){
    		return endTime;
    	}
    	
    	public void setDescription(String descript){
    		this.description = descript;
    	}
    	
    	public String getDescription(){
    		return description;
    	}
    	
    	public void setLocation(String locat){		/**location must match one of the constants defined in array LOCATIONS*/
    		boolean retry=false;
    		do{
    			if(locat.equals(LOCATIONS[0]) || locat.equals(LOCATIONS[1]) || locat.equals(LOCATIONS[2]) || locat.equals(LOCATIONS[3]) || locat.equals(LOCATIONS[4])){
    				this.location = locat;
    				retry=false;
    			}
    			else{
    				JOptionPane.showMessageDialog(null, "Invalid Location!", "warning", JOptionPane.WARNING_MESSAGE);
    				String specs = JOptionPane.showInputDialog("What is the location?");
    				Scanner keyboard = new Scanner(specs);
    				if(specs!=null){
    					locat=keyboard.nextLine();
    					retry=true;
    				}
    			}
    		}while(retry==true);
    	}
    	
    	public String getLocation(){
    		return location;
    	}
    	
    	public String toString(){
    		return "Appointment starts at " + startTime + " and ends at " + endTime + " located at " + location + " Description: " + description;
    	}
    }
    My CDailyAppointmentBook class:
    Java Code:
    package assignment2;
    
    /**
     * class CDailyAppointmentBook: This is my driver class that includes the interactive menu that allows the user to add, edit, delete, and display appointments.
     * 								
     * @author Ian Harlow		Student ID: 103475617
     */
    
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.NoSuchElementException;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    
    
    @SuppressWarnings("serial")
    public class CDailyAppointmentBook extends JFrame{
    	
    	a_canvas canvas;
    	CAppointment appointment;
    	JMenu appointmentMenu;
    	JMenuBar menubar;
    	int index=0;
    	
    	public CDailyAppointmentBook(String title)
    	{
    		super(title);
    		
    		canvas = new a_canvas();
    		this.add(canvas);
    		 
    		menubar = new JMenuBar();
    		
    		appointmentMenu = new JMenu("Appointment");
    		appointmentMenu.setMnemonic('A');
    		
    		menubar.add(appointmentMenu);
    		
    		JMenuItem addMenu = new JMenuItem("ADD");
    		addMenu.setMnemonic('A');
    		addMenu.addActionListener(
    				new ActionListener()
    				{
    					public void actionPerformed(ActionEvent event)
    					{
    						boolean retry;
    						do
    						{
    							retry = false;
    							try 
    							{
    								String specs = JOptionPane.showInputDialog("please enter the appointment start time, end time, a description, and location:");
    								if (specs != null) canvas.addAppointment(new CAppointment(specs));
    							}
    							catch(NoSuchElementException nsee)
    							{
    								JOptionPane.showMessageDialog(null, "please make sure you enter all the data in the form of start time, end time, a description, and location", "warning", JOptionPane.WARNING_MESSAGE);
    								retry = true;
    							}	
    						}while(retry);
    						
    						//canvas.repaint();
    					}
    				}
    		);
    		appointmentMenu.add(addMenu);
    		
    		appointmentMenu.addSeparator();
    		
    		JMenuItem displayMenu = new JMenuItem("DISPLAY");
    		displayMenu.setMnemonic('D');
    
    		displayMenu.addActionListener(
    				new ActionListener()
    				{
    					public void actionPerformed(ActionEvent event)
    					{
    						//canvas.displayAppointment(index);
    						boolean retry;
    						do
    						{
    							retry = false;
    							try 
    							{
    										//String specs = JOptionPane.showInputDialog("Appointments:");
    										//	if (specs != null){
    										//CAppointment temp = canvas.getAppointment(i);
    										if(index==0){
    											index++;
    											System.out.println("1");
    											JButton next = new JButton("NEXT");
    											next.addActionListener(
    													new ActionListener(){
    														public void actionPerformed(ActionEvent event){
    																//ListIterator<?> listIterator = canvas.appointmentList.listIterator();
    																index--;
    																try{
    																	index++;
    																	canvas.displayAppointment(index);
    																	System.out.println("next button pressed");
    																}
    																catch(Exception e){
    																	JOptionPane.showMessageDialog(null, "No next appointment", "warning", JOptionPane.WARNING_MESSAGE);
    																}
    														}
    													}
    											);
    											
    											canvas.add(next);
    											canvas.revalidate();
    											canvas.repaint();
    											continue;
    										}
    										else if (index==1){
    											index++;
    											System.out.println("2");
    											JButton previous = new JButton("PREVIOUS");
    											previous.addActionListener(
    													new ActionListener(){
    														public void actionPerformed(ActionEvent event){
    																index--;
    																try{
    																	index--;
    																	canvas.displayAppointment(index);
    																	System.out.println("previous button pressed");
    																	
    																}
    																catch(Exception e){
    																	JOptionPane.showMessageDialog(null, "No previous appointment", "warning", JOptionPane.WARNING_MESSAGE);
    																}
    														}
    													}
    											);
    											canvas.add(previous);
    											canvas.revalidate();
    											canvas.repaint();
    											continue;
    										}
    										else{
    											canvas.revalidate();
    											canvas.repaint();
    										}
    									//}
    							}
    							catch(NoSuchElementException nsee)
    							{
    								JOptionPane.showMessageDialog(null, "No appointments to display", "warning", JOptionPane.WARNING_MESSAGE);
    								retry = true;
    							}	
    						}while(retry);
    						
    						//canvas.repaint();
    					}
    				}
    		);
    		appointmentMenu.add(displayMenu);
    		
    		appointmentMenu.addSeparator();
    		
    		JMenuItem editMenu = new JMenuItem("EDIT");
    		editMenu.setMnemonic('E');
    		editMenu.addActionListener(
    				new ActionListener()
    				{
    					public void actionPerformed(ActionEvent event)
    					{
    						boolean retry;
    						do
    						{
    							retry = false;
    							try 
    							{
    								String specs = JOptionPane.showInputDialog("please enter the start time of the appointment");
    						
    								if (specs != null) canvas.editAppointment(new CTime(specs));
    							}
    							catch(NoSuchElementException nsee)
    							{
    								JOptionPane.showMessageDialog(null, "please make sure you enter the start time in hours and minutes of the appointment", "warning", JOptionPane.WARNING_MESSAGE);
    								retry = true;
    							}	
    						}while(retry);
    						
    						canvas.repaint();
    					}
    				}
    		);
    		appointmentMenu.add(editMenu);
    		
    		appointmentMenu.addSeparator();
    		
    		JMenuItem deleteMenu = new JMenuItem("Delete");
    		deleteMenu.setMnemonic('D');
    		deleteMenu.addActionListener(
    				new ActionListener()
    				{
    					public void actionPerformed(ActionEvent event)
    					{
    						boolean retry;
    						do
    						{
    							retry = false;
    							try 
    							{
    								String specs = JOptionPane.showInputDialog("please enter the start time of the appointment you wish to delete");
    						
    								if (specs != null){
    									canvas.deleteAppointment(new CTime(specs));
    								}
    							}
    							catch(NoSuchElementException nsee)
    							{
    								JOptionPane.showMessageDialog(null, "please make sure you enter the start time in hours and minutes of the appointment", "warning", JOptionPane.WARNING_MESSAGE);
    								retry = true;
    							}	
    						}while(retry);
    						
    						canvas.revalidate();
    						canvas.repaint();
    						
    					}
    				}
    		);
    		appointmentMenu.add(deleteMenu);
    		
    		appointmentMenu.addSeparator();
    		
    		JMenuItem saveMenu = new JMenuItem("Save");
    		saveMenu.setMnemonic('S');
    		saveMenu.addActionListener(
    				new ActionListener()
    				{
    					public void actionPerformed(ActionEvent event)
    					{
    						if (!canvas.saveList())
    							JOptionPane.showMessageDialog(null, "Oops couldn't save for some reason!", "warning", JOptionPane.WARNING_MESSAGE);
    						canvas.repaint();
    					}
    				}
    		);
    		appointmentMenu.add(saveMenu);
    	
    		
    		JMenuItem loadMenu = new JMenuItem("Load");
    		loadMenu.setMnemonic('L');
    		loadMenu.addActionListener(
    				new ActionListener()
    				{
    					public void actionPerformed(ActionEvent event)
    					{
    						if (!canvas.loadList())
    							JOptionPane.showMessageDialog(null, "Oops couldn't load for some reason!", "warning", JOptionPane.WARNING_MESSAGE);
    						canvas.repaint();
    					}
    				}
    		);
    		appointmentMenu.add(loadMenu);
    		
    		appointmentMenu.addSeparator();
    	
    		
    		JMenuItem exitMenu = new JMenuItem("Exit");
    		exitMenu.setMnemonic('x');
    		exitMenu.addActionListener(
    				new ActionListener()
    				{
    					public void actionPerformed(ActionEvent event)
    					{
    						int reply = JOptionPane.showConfirmDialog(null, "are you sure you want to exit?", "confirm exit", JOptionPane.YES_NO_OPTION);
    					    if (reply == JOptionPane.YES_OPTION)
    					    {
    					      
    					      System.exit(0);
    					    }	
    					}
    				}
    		);
    		appointmentMenu.add(exitMenu);	
    		
    		this.setJMenuBar(menubar);
    	}
    	
    	public static void main(String args[]){
    		
    		CDailyAppointmentBook myApp = new CDailyAppointmentBook("My appointment application");
    		
    		myApp.setDefaultCloseOperation(EXIT_ON_CLOSE);
    		myApp.setSize(500, 400);
    		myApp.setVisible(true);
    	}
    }
    My a_canvas class:
    Java Code:
    package assignment2;
    
    import java.awt.Color;
    import java.awt.Graphics;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.util.Iterator;
    import java.util.Vector;
    
    import javax.swing.JPanel;
    
    
    @SuppressWarnings("serial")
    public class a_canvas extends JPanel{
    public Vector<CAppointment> appointmentList;
    int j = 0;
    
    	public a_canvas(){
    		appointmentList = new Vector<CAppointment>();
    		
    	}
    	
    	public  int getNumberOfAppointments(){
    		return appointmentList.size();
    	}
    	
    	public void paintComponent(Graphics g){
    		super.paintComponent(g);
    		
    		Iterator<CAppointment> itr = appointmentList.iterator();
    		
    		this.setBackground(Color.WHITE);
    		
    		while(itr.hasNext()) {
    		      itr.next().DrawAppointment(g);
    		      
    		}
    		CAppointment.count = 55;
    	}
    
    	public CAppointment getAppointment(int index){ 
    		
    		return appointmentList.elementAt(index);
    	}
    	
    	public void displayAppointment(int index){
    	
    	appointmentList.get(index); 
    	}
    	
    	public void addAppointment(CAppointment s){
    		appointmentList.add(s);
    		if(j!=0){
    			if(!compareTo(getAppointment(j).getStartTime(),getAppointment(j-1).getEndTime())){
    				System.out.println("error: appointment overlap problem");
    				System.out.println("" + getAppointment(j).getStartTime());
    				System.out.println("" + getAppointment(j-1).getEndTime());
    				System.exit(0);
    			}
    		}				
    		j++;
    	}
    	
    	private static boolean compareTo(CTime startTime2, CTime endTime1) {
    		// TODO Auto-generated method stub
    		if(startTime2==null || endTime1==null){
    			return false;
    		}
    		else if(startTime2.getHour() < endTime1.getHour()){
    			return false;
    		}
    		else if(startTime2.getHour() > endTime1.getHour()){
    			return true;
    		}
    		else if(startTime2.getHour()==endTime1.getHour()){
    			if(startTime2.getMinute()>=endTime1.getMinute()){
    				return true;
    			}
    		}
    		return false;
    	}
    	
    	public void editAppointment(CTime edit_key){
    		int i=0;
    		while(i<getNumberOfAppointments()){
    			
    			
    			if(compare(getAppointment(i).getStartTime(),edit_key)){			/**check if start time matched any appointment*/
    				System.out.println("editing bitches!");
    				getAppointment(i).editAppointment(getAppointment(i));	/**edit*/				
    			}
    			else{
    				System.out.println("you fail");
    			}
    					System.out.println("loop");
    			i++;
    		}
    	}
    	
    	public void deleteAppointment(CTime delete_key){
    		int i=0;
    		while(i<j){	
    			
    			if(compare(getAppointment(i).getStartTime(),delete_key)){			/**check if start time matched any appointment*/
    				System.out.println("deleting bitches!");				
    				while(getAppointment(i)!=null){
    					getAppointment(i).deleteAppointment(getAppointment(i),getAppointment(i+1));
    					++i;
    				}
    			}
    			else{
    				System.out.println("you fail");
    			}
    				System.out.println("loop");
    			i++;
    		}
    		j--;
    	}
    	
    	private static boolean compare(CTime startTime, CTime edit_key){
    		// TODO Auto-generated method stub
    		if(startTime==null || edit_key==null){
    			return false;
    		}
    		else if(startTime.getHour()==edit_key.getHour()){
    			if(startTime.getMinute()==edit_key.getMinute()){
    				return true;
    			}
    		}		
    		return false;
    	}
    	
    	public boolean saveList(){
    		// Object serialization 
    		try 
    		{ 
    			ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream("appointments.dat")); 
    			output.writeObject(appointmentList); 
    			output.flush(); 
    			output.close(); 
    			return true;
    		} 
    		catch(Exception e) 
    		{ 
    			System.out.println("Exception during serialization: " + e); 
    			return false;
    			//System.exit(0); 
    		} 
    	}
    	
    	@SuppressWarnings("unchecked")
    	public boolean loadList(){
    		try 
    		{ 
    	
    			ObjectInputStream input = new ObjectInputStream(new FileInputStream("appointments.dat")); 
    			appointmentList = (Vector<CAppointment>)input.readObject(); 
    			input.close(); 
    			return true;
    			
    		} 
    		catch(Exception e) 
    		{ 
    			System.out.println("Exception during deserialization: " + e); 
    			return false;			
    		}
    	}
    }
    I realize that this may be bad design, but I'm also very new to java. I'm open to criticism, after all I'm here to learn!

    Cheers,
    Ian

Similar Threads

  1. Replies: 6
    Last Post: 02-08-2012, 06:42 PM
  2. Collisions are working & not working
    By Jayayoh in forum Java 2D
    Replies: 1
    Last Post: 06-24-2011, 05:21 PM
  3. InputStream/Jar Problems/File IO Problems
    By rdjava in forum Advanced Java
    Replies: 31
    Last Post: 01-17-2011, 11:12 AM
  4. Replies: 2
    Last Post: 01-04-2011, 04:30 AM
  5. Replies: 8
    Last Post: 05-28-2008, 07:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •