java vector closing problem

need help closing everthing with quit selected

Page 1 of 1

7 Replies - 777 Views - Last Post: 19 October 2008 - 06:38 PM Rate Topic: -----

#1 deedee66  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 21-September 08

java vector closing problem

Posted 19 October 2008 - 02:29 PM

Hello,

I need help getting everything to close by selecting quit. I have tried several things and none seem to work. the rest of the code works great but I can not get everything to close.

import myGui.*;
import java.util.Vector;
import java.io.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.FileDialog;


class Music
{
	public static void main(String[] args)
	{
		String[] prompts = {"Name of Song", "Name of Artist","Category Of Song"};
		String[] whatNext = {"Insert Song Name","Find Song Name","List all Songs","Load from File","Save Songs","Print Store Info","Print Store Owner Info","Quit"};
		
		String[] fields = new String[3];
		
		Vector dataStore = new Vector();
		
		WindowPane screen = new WindowPane();
		RadioButtons buttons = new
		RadioButtons(screen, "What next?", whatNext);
		TextInput Song = new TextInput(screen, "Name of Song?");
		DataInputBox input = new DataInputBox(screen, prompts);
		DataOutputBox output = new
		DataOutputBox(screen, prompts, "The Music Plus Song File");
		WritingPad notes = new WritingPad(screen);
		
		screen.showWindowPane();
		buttons.showRadioButtons();
		String choice = buttons.getNameOfButton();
		
		while (! choice.equals("Quit"))
		{
			if (choice.equals("Insert Song Name"))
			{
				input.showDataInputBox();
				fields = input.getFields();
				
				dataStore.addElement(new Song(fields[0],fields[1],fields[2]));
			}
			else if (choice.equals("Find Song Name"))
			{
				Song.showTextInput();
				String nameOfSong = Song.getString();
				
				for (int index=0; index != dataStore.size(); index++)
				{
					Song datum = (Song)
					dataStore.elementAt(index);
					
					if (nameOfSong.equals(datum.getName()))
					{
						output.showDataOutputBox();
						fields[0] = datum.getName();
						fields[1] = datum.getArtist();
						fields[2] = datum.getCategory();
						output.setFields(fields);
					}
				}
			}
				else if (choice.equals("List all Songs"))
			{
				Song datum;
				
				notes.showWritingPad();
				for (int index=0; index != dataStore.size(); index++)
				{
					datum = (Song)
								dataStore.elementAt(index);
					notes.write(datum.getName()+
							" "+datum.getArtist()+
							" "+datum.getCategory()+"\n");
				}
				notes.write("\n");
			}
			else if (choice.equals("Load from File"))
			{
				FileDialog file = new
				FileDialog(screen,"",FileDialog.LOAD);
				file.show();
				
				String filename = file.getFile();
				if ( filename != null)
				{
					try
						{
							FileInputStream fis = new
							FileInputStream(filename);
							ObjectInputStream in = new
							ObjectInputStream(fis);
							
							Vector newStore = (Vector)in.readObject();
							in.close();
							dataStore = newStore;
						}
						catch (Exception e){}
				}
			}
			else if (choice.equals("Save Songs"))
			{
				FileDialog file = new
				FileDialog(screen, "",FileDialog.SAVE);
				file.show();
				
				String filename = file.getFile();
				if (filename !=null)
				{
					try
						{
							FileOutputStream fos = new
							FileOutputStream(filename);
							ObjectOutputStream out = new
							ObjectOutputStream(fos);
							out.writeObject(dataStore);
							out.flush();
							out.close();
						}
						catch (IOException e){}
				}
			}
			else if (choice.equals("Print Store Info"))
			  {
				notes.showWritingPad();
				
					notes.write("Music Plus\nMusic Mall\nMusic Country, USA\n\n");
					notes.write("\n");
			  }
			else if (choice.equals("Print Store Owner Info"))
				{
					notes.showWritingPad();
				
					notes.write("Owners of Music Plus:\nMusic People & Friends\n\n");
					notes.write("\n");
					}
					
			buttons.showRadioButtons();
			choice = buttons.getNameOfButton();
		}
  }	

}




thanks for any help.

Is This A Good Question/Topic? 0
  • +

Replies To: java vector closing problem

#2 stauffski  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 210
  • Joined: 03-November 07

Re: java vector closing problem

Posted 19 October 2008 - 05:00 PM

Place
dispose();
at the end of your loop.

This post has been edited by stauffski: 19 October 2008 - 05:17 PM

Was This Post Helpful? 0
  • +
  • -

#3 deedee66  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 21-September 08

Re: java vector closing problem

Posted 19 October 2008 - 05:14 PM

View Poststauffski, on 19 Oct, 2008 - 05:00 PM, said:

Place
dispose();
at the end of you loop.



unfortunately that did not work
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: java vector closing problem

Posted 19 October 2008 - 05:41 PM

Why do you want to clean up if your application closes ?
Was This Post Helpful? 0
  • +
  • -

#5 deedee66  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 21-September 08

Re: java vector closing problem

Posted 19 October 2008 - 06:05 PM

View Postpbl, on 19 Oct, 2008 - 05:41 PM, said:

Why do you want to clean up if your application closes ?



the assignment was to get the songs to be able to input, list, find,save, load and quit the program with selecting quit.
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: java vector closing problem

Posted 19 October 2008 - 06:21 PM

View Postdeedee66, on 19 Oct, 2008 - 06:05 PM, said:

[the assignment was to get the songs to be able to input, list, find,save, load and quit the program with selecting quit.

So you quit that's all
Was This Post Helpful? 0
  • +
  • -

#7 deedee66  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 21-September 08

Re: java vector closing problem

Posted 19 October 2008 - 06:25 PM

View Postpbl, on 19 Oct, 2008 - 06:21 PM, said:

View Postdeedee66, on 19 Oct, 2008 - 06:05 PM, said:

[the assignment was to get the songs to be able to input, list, find,save, load and quit the program with selecting quit.

So you quit that's all

but i still have to close each window individually. they need to all close when i select quit. that has to be one of the most unhelpful posts i have ever read on here.
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: java vector closing problem

Posted 19 October 2008 - 06:38 PM

View Postdeedee66, on 19 Oct, 2008 - 06:25 PM, said:

but i still have to close each window individually. they need to all close when i select quit. that has to be one of the most unhelpful posts i have ever read on here.

System.exit(0);
and Java will close all your windoes for you
Your are not in C++ where you have to do your garbage collection, Java will do it for you
OK unhelpful post I shut out... but you are wasting your time more than I do
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1