JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi Norm. Sorry to appear contradictory, but aren't "Algebra 1" and "Form 9D" pieces of the data? In which case testName and formName would be the variable names. In which case it would me something like

testName = tokens[1]; // "Algebra 1" is the second token

I think the OP's statement about assigning was just "imprecise".
(If I'm wrong just say and I'll butt out)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Using The index is the ONLY way to get elements out of an array.

Or an enhanced for-each loop (may be easier)?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

textJT array contains 6 text fields, but the clear code (line 157) only clears the first 3

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Suppose f1=new FileInputStream(p[0]); fails. You will go to the catch block, print a message and continue. Eventually you get to i=f1.read(); but f1 will not have been initialised. That's the circumstance the compiler complained about.
Now if you have a return; in the catch block you will not continue after new FileInputStream fails, so you won't ever get to i=f1.read();, so there's nothing to complain about.
Same applies to f2.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

sounds like you should have method that populates all the upper buttons with random problems, and that method should be executed when the user selects a level (or one method for each level...).
You can set up a problem with something like this (pseudocode)...

int op1 = random number 1-9, eg 7
int op2 = random number 1-9, eg 2
boolean plus = random boolean (nextBoolean method) eg false
// true for addition, false for subtraction
if (plus)  
  text = op1 + "+" + op2;
  // uses + operator to concatenate Strings, ints are converted to strings automatically
  correct = op1 + op2  // right answer for checking
  // uses + operator to add two ints numerically
else 
  text = op1 + "-" + op2   eg "7-2"
  correct = op1 - op2  // right answer for checking

set button with text
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you not read Norm's post re equals method? Or did you just decide to ignore it?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So Dish's are objects that have a meaningful toString method. In that case you can simply use that method to convert your enumerated Dish's into Strings that can be written by java.io.BufferedWriter's write method.

ps Since Java 1.5 there's an easier and safer way to iterate through a Vector (or any other kind of Collection) - called the for-each loop. It looks like this example:

Vector<String> v = ...
for (String s : v) { // "for each String s in the Collection v..."
   System.out.println(s);  // or whatever
}

pps Vectors are an old class that have been superceded by ArrayLists for most purposes

ppps Please keep trying with the API doc. Being able to search and use it is just as essential as being able to write a for loop.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Absolutely no difference at all. You can put those modifiers in any order.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your Vector does not seem to have any type associated with it, so it's assumed to contain Objects, so enu.nextElement() is seen as returning an Object.
System.out.println is a bit cunning in that it secretly calls the toString() method on anything you try to print, so your enu.nextElement() gets converted to a String, and printed.
However, java.io.BufferedWriter's write method doesn't do that, it needs a proper String (or equivalent - see the API doc for details), and doesn't know how to write unspecified Objects. Hence the error message.
Without knowing how your Vector is declared and populated it's hard to give a "best" answer. Can you supply that info?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Are you sure it didn't open it?
It looks like your button handler creates a new MyForm and makes it visible exactly like you do in main(...) - so the new MyForm will be identical to the existing one and sit exactly on top of it, so it looks like nothing has happened (maybe?)
Try dragging the form somewhere else on the screen...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Use the join() method from the Thread class - it waits until the thread has finished. Plenty of examples on the web.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
for (int x=0;x<3;textJT[x].setText(temp).x++);

you probably meant

for (int x=0;x<3;x++)  textJT[x].setText(temp);

ps: many people would prefer

for (int x=0;x<3;x++) {
   textJT[x].setText(temp);
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, glad to help.
Mark this thread "solved" so people know.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It would help if you redirected the output before sending it.
You need to run the redirection code when the app starts, then all subsequent out/err output goes to that file.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

and

System.setErr(printStream);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Redirect System.out Something like...

String fileName = "whatever.txt";
final boolean append = true, autoflush = true;
PrintStream printStream = new PrintStream(new FileOutputStream(fileName, append),
                                    autoflush);
System.setOut(printStream);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK! Come back here if you get stuck.
ps I see you are using AWT components - these have been superceded by their Swing equivalents (JApplet, JTextField etc) since Java 1.2 (1998).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Two comments:
1. if (someCondition== true) is a bit silly. What's wrong with if (someCondition)

2. for (int i = somePositiveIntegerValue; i < 0; i--){... // eg your line 86
How many times will this loop execute (when will i<0 be true)?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you mean that you want to animate the display of the numbers so they slide down out of sight and the next number slides down from the top?
If so, you need to override paintComponent for the text fields and draw the text at an x,y position where the y coordinate is increased every few millisecs by a jaxax.swing.Timer

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hardware or OS fault.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are trying to read from some kind of input stream, but the data is in the wrong format. This can happen if the format for reading doesn't match the format in which it was written, or the stream hasn't been closed properly, or you try to read the same stream with two consecutive different formats, or (less likely) the stream is corrupted by a problem external to your code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is not helping at all, guys. I don't want to change anything written in those classes because they seem to be built on the top of each other.

What would you like us to do to help you? Please believe that we cannot change the way that Java works. You have a project with over 800 errors. There's nothing that anybody on Earth can do to make that work without fixing the errors.
If you have any religious beliefs then maybe praying will work for you.
Good luck.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Bear in mind that I'm still new to Java language..

That may be so, but Java and Eclipse work the same way regardless of your experience

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have 689 uncorrected compile-time errors. Yet you say

It is strange that eclipse doesn't find any code to execute. How do you think I can possibly fix the issue?

There won't be any code to execute until the compiler generates some. The compiler won't compile your code until you fix the errors. Start with the first error and keep fixing them until they are all fixed. Then you will get some code to execute.

ps: Such a large number of errors suggests that you have problems with your project setup, eg incorrect path(s) - but the detailed messages will spell it out for you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Previous code is a good example of why an ArrayList is a better choice than an array for returning an unknown number of Objects - there's no need to size it, just keep adding Objects until they are all added.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is there any other way?

Yes, probably, maybe a custom DataFlavor...
But it's so easy and generalisable to convert any bean-like object to a plain String and back, that IMHO it's the easiest way to get the job done.
Here's a little bit of code to illustrate the XML encode/decode stuff...

public static String objectToXML(Object o) {
      ByteArrayOutputStream os = new ByteArrayOutputStream();
      XMLEncoder en = new XMLEncoder(os);
      en.writeObject(o);
      en.close();
      return os.toString();
   }
   
   public static Object  objectFromXML(String s) {
      ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
      XMLDecoder de = new XMLDecoder(is);
      return de.readObject();
   }

   public static void main(String[] args) {

      JButton jb = new JButton("Hello, world");
      jb.setActionCommand("command");
      jb.setBounds(0, 0, 100, 10);

      String s = objectToXML(jb);
      System.out.println(s);

      Object o = objectFromXML(s);
      System.out.println(o);
   }
murali_quest commented: Usefull +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Although you can in theory put pretty much anything you like on the clipboard, it can be difficult.
You can use XMLEncoder to convert your Swing objects to a simple text String that is really easy to put on the clipboard, and XMLDecoder to re-create the object from the clipboard text. Documentation is in the usual places.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your initial value for smallest is 0 - think that through. What result do you expect with that starting value?
If you still don't get it post again and I'll give you a more explicit hint.
ps: Please post all code in code tags in future.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, it really is just the same as any other array, so you can do stuff like:

GregorianCalendar[] myCal = new GregorianCalendar[99];
myCal[0] = new GregorianCalendar(1980,1,1);
...
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
System.out.println(sdf.format(myCal[0].getTime()));

Just experiment a bit with it. Everything you know about arrays of Strings applies to arrays of GregorianCalendar also.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Check the example in my previous post - you missed a method call

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes.
Input and output formats vary with locale, console vs GUI, user preferences etc, but a date is a date is a date regardless. Store the date and you're safe. Let people input them and view them however they want.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why not just create an array of GregorianCalendar instances, exactly like an array of Strings?

GregorianCalendar[] myCal = new GregorianCalendar[99];
myCal[0] = Calendar.getInstance();
// etc

To output a GregorianCalendar instance in any specific text format you can imagine, use SimpleDateFormat, eg like this:

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    Calendar c = Calendar.getInstance(); // today
    System.out.println(sdf.format(c.getTime()));

or use the java.util.Formatter class if you like C's printf approach

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I honestly can't claim enough expertise in JDO to be able to guide anyone. Maybe someone else can step in here? If you start a new topic specifically about JDO someone will notice.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

My idea is to create a class that represents a department. Then derive subclasses for each Batch (Iyr, IIyr, III and IV yrs ) then derive subclasses to represent ClassA and classB.

Don't confuse classes and instances. Batch may well be a good class, in which case you will have four instances of it, not subclasses. It's just like Student class - you don't have a subclass for each student, just an instance for each student

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

My suggestion: don't try to use any of those frameworks/applications/libraries at this stage. They are pretty complex, have steep learning curves of their own, and are designed to avoid or solve problems that you don't understand yet.
IMHO you should do this one by coding it yourself; in that process you will learn a lot, and what you learn will enable you to benefit from more advanced tools later.
In my mind this is an exact parallel to the way that we usually advise people to start with an editor and a command prompt before moving on to a full-blown IDE.

Anyone else want to offer an opinion on this?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So you basically want me to create an OO design of the project right?
And create classes for department, student etc? And populate them with data from database? and then populate the UI with this data?

That's how real Java developers do it in the real world...
You'll have to get used to that sooner or later...

ps. This is your project, so you can do it any way you chose, but there's a reason why people do the object model thing - in the long run it's the easiest. Good software is 80% design and 20% coding.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's going to be difficult for anyone to answer a question that's quite as wide open as this one.
You could look at a 3-layer architecture (GUI/object model/data persistence) - in which case start with the object model and define the classes and their public methods (these just need to match the functionality required in the spec), then go you can either up or down depending or your mood. I would not advise starting with the GUI, this often leads to you embedding the object model piece-by-piece right there in the GUI code resulting in a gigantic ball of spaghetti. Test the object model by hard-coding calls to its public methods before attempting to wire up a U.I.
By all means please post your ideas and problems here - the more specific the question, the easier it is to answer.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's a load of non-Java-language stuff in the source code download, including C code. I haven't looked at that, but you may find it there?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What doc are you getting that from?

The source code for the API is downloadable from
http://download.java.net/jdk6/source/

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Faced with a bug like this you should put lots of print statements into your code to check (a) if it is executing the code you expected for the expected number of times and (b) to check that the variables have the values you expected.
99 times out of 100 this process will let to home in on exactly where the problem is.

In this case it's printing when it should be printing, but its not printing what it should be printing -so the overall flow of the logic is OK, but there's something wrong with the values being assigned to the variables - in this case the value being returned from unistudent.printDetails() is null when it should be a long String. So that's where the problem is.
Have a closer look at printDetails; try printing the values inside that method to see where they go wrong. I'm not going to tell you the answer until you've had a really good go at solving it yourself!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You may be getting confused by the use of the words "send it to". That should be "return it to" - ie the formatted string is returned from the printDetails method when it is called from within printEnrolment. printDetails doesn't have to call or refer to anything other than its own Student instance variables.
printEnrolment just has to go something like this:

for (int i...
   String studentDetails = sa[i].printDetails(); // get the details for this student
   System.out.println(studentDetails); // ... and print them on the console
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Re static in Enrolment and Admin:
You decide whether to use static or not by asking "how many of these are there?". eg the name field in Student has one value for each Student, so it must be an instance variable, not static. eg In the Admin class you have a Scanner; there will only ever be one Scanner which everything will share, so that's static.

It seems you have exactly one Admin and one Enrolment. If so there are two ways to code them. (1) make everything in those classes static and refer to them via the class name or (2) create one instance of Admin and one instance of Enrolment, have everything non-static, and refer to them via the instances.
"Best practice" is option (2), and this is how an experienced developer would normally do it. (The main reason is that sooner or later someone will want more than one instance.) However, it does introduce a bit more complexity, and you do already have that stuff defined as static, so I suggest you leave them as they are and refer to the static methods and variables via the class name.

Selective print by year: you have an instance method in Student that returns the year that student enrolled, so you can call that for each student to compare the year, something like this:

for (int i ....
   if (sa[i].getYearStarted() == searchYear) sa[i].printDetails();
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

calling printDetails for one or more Students:
This is a lot simpler than you realise. All you need is a variable that refers to one student, then use that for the call, as in:

Student s = ... something
s.printDetails();

that variable can, of course, be an element from an array of Students, as in:

Student[] sa = new Student[99];
sa[0] = new Student(...
...
sa[0].printDetails();

or, if it's inside a loop

for (int i ...
   sa[i].printDetails();

Just use these concepts in your own code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I also wanted to ask is it a bad idea to create the array in Enrolment but store it in the Admin class?

It depends. If there is only one instance of Admin, and only one instance of Enrolment then it probably makes no difference. If you have (eg) one Admin but multiple Enrolments the each Enrolment would have its own array of Students. At a guess I would say put the array in Enrolment and give it a public accessor method so Admin can access it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, excellent! Mark this one solved. See you next time ;-)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The current version of Java is Java 6, confusingly version numbered as 1.6. There's no reason to work with any earlier version unless you are specifically required to do so.
(Java 7 / version 1.7 is due out later this year, but doesn't add much over 1.6.)
Anything you find for 1.5 will be good for 1.6 also, but beware of code written for earlier versions (mostly 1.4.2) because there were major improvements to the language in 1.5.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.

(API doc for StringTokeniser)

You should do a lot better by reading one whole line at a time then splitting it (String split method) on the tab delimiters to get a String array. I haven't tested this but you should get array elements of "" where there are consecutive tabs, although it may be better to trim() the elements to get rid of any spurious blanks.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is probably a dumb question, but here goes anyway...
Why not just use the page number (index+1) that's passed into print as its third parameter? Isn't that the number that you want to print?
(If not, what EXACTLY is "st" intended to be?)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I wondered that too.