Click to See Complete Forum and Search --> : Help needed: array, storage, data between classes.


Random Hero
04-06-2005, 03:56 PM
I'm stuck on some homework.

I have to create a database for a video shop in java. With a GUI front end to it. The 'database' is just a .data file which contains a list of Video titles, actors, rating.

I need the program to save user input fields to the .data file, but I dont know how.

So far for the add part of the class I have:


public void addVideo( Video newVideo ) {

if (arrayOfVideos = DEFAULT_SIZE) {
arrayHasChanged = false;
}

else {

//arrayOfVideos[10]= VideoInputWindow.newVideo;
arrayOfVideos.add (VideoInputWindow.newVideo(newTitle));

numberOfVideos++;
arrayHasChanged = true; //this gives the user option to save

}


Anyways I cant figure out how to import the data the user inputs from one class to another. And I also cant figure out how to store that data in the array. I'm only a beginner at java, so help/shove in the right direction would be much appreciated. Thanks.

Edit: I have the main GUI and input GUI down fine. Did that in classes a little while back. But I dont know what to do here, tried a few things and a few sources, books (Java J2SE 5 Edition) but I dont truly know what I'm looking for to help me. Such a java noob.

BuezaWebDev
04-06-2005, 04:21 PM
What do you mean by importing data from the user inputs from one class to another? Please show some code.

I'll try to assume that the user inputs go straight into the .data file and that you want other classes to be able to access that information.

This is my approach to this situation: Make an interface that will let the classes that implement it receive the ability to grab the text off that .data file.


public interface RetrieveDataFile {
void getData();
}


Now, in whatever class you want you can put:

public class ClassA implements RetrieveDataFile {
String buffer;
protected ClassA() {}
public getData() {
/* process data file by opening it and then reading off the file. Then you put the
contents of that file into the string buffer. */

/* OR, you can read the file line by line by using a WHILE loop */

}
public static void main(final String[] args) {
getData();
System.out.println(buffer);
}
}


That's my approach to it. Hope that helps.