JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Add print statements after each line to print out the values that were set/changed on that line. Then you'll be able to understand how it works.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To be honest - some variant on that read/testEOF combo is in most programs that read from a file. I would really have to classify it as a common standard pattern. It's only "rare" in applets. But don't worry, some of us have been using Java since last century but still keep coming across things we didn't know about it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I can't make any sense of your undocumented code, but in general:
There is no restriction in Java anything like "only first function can access the variables."
Methods can share variables that are defined at class level, but not any variables that are declared within a method. If you declare a variable within a method that has the same name as a class variable then there is no compiler error, but it's very confusing.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It looks like tmp is a 50MByte array which you copy at least once, so you're probably just exceeding the default memory allocation for the JVM. This link is a decent summary of what you need to know...
http://javarevisited.blogspot.com/2011/05/java-heap-space-memory-size-jvm.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please edit that and put the code in code tags, properly indented, so we can read it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This kind of thing isn't particularly rare, nor is it reserved for advanced users. One case you see very often is when you read bytes from a Reader while checking for end-of-file (returns -1 for number of bytes read), eg

if (int bytesRead = reader.read(buffer) >= 0) {...

although the while (... version is even more common

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Well now, don't I feel really stupid!
I focussed on the array of Objects, but forgot that they were embedded in a Collection. This code I have tested, although I can't help feeling there is a better way...

System.out.println("Values of tree map: " +  Arrays.deepToString(tMap.values().toArray()));
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Although that approach can work, at least for a fixed size list of values, it's a pretty heavy way to overcome the OP's problem which was how to print an array of Strings.
A better answer would be to use the Arrays.toString method, as in

System.out.println("Values of tree map: " + Arrays.toString(tMap.values()));
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe your problem is that you get and update the Graphics in mouseMoved, but Swing doesn't know that you have done this. Swing is by default double-buffered, so the screen isn't getting updated with your new line until something else happens to cause a refresh of the screen.
If you want to do it that way you should call repaint() after drawing to the Graphics. However, in general, updating the component's Graphics outside paintComponent(..) isn't a great idea - it's hard to coordinate your drawing with Swing's event handing, eg on a window re-size.. It's normally better to update some data that describes the line in your mouse listener (or draw the line to your own off-screen graphics buffer), then call repaint(). Draw the latest version in paintComponent when that gets called by Swing.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please check again.
arr2 is an array of 1 element. length 1.
That one element arr2[0] contains a String of length 6.
The length of the array is not the same thing as the length of a single String arrayelement.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That would be length 1
danielagaba: Can you please post the complete error message - this looks funny to me. I would expect an array bounds exception, not a null exception

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The error message gives the line number where the error happened. Which line is it?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

chars are numeric values that are used to represent characters. You must always distinguish between the two, ie
char c = 0;
is not the same as
char c = '0';
in the second case c has the value 48.

From the API doc of Integer.toBinaryString
... The characters '0' ('\u0030') and '1' ('\u0031') are used as binary digits.
So your chars are '0' and '1', ASCII numeric values 48 and 49 respectively. The logical operators work with the numeric values, not the character representations, so you may need to rethink your code a bit.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Are those characters '1' and '0' (ASCII values) or are they numeric 0 and 1? It makes a big difference.

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

Is that coming from the compile, or is it when you try to run the code. Exactly what commands are you using?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you have one listener for multiple text fields then you can get the source of the event from the CaretEvent that's passed as a parameter to your caretUpdate method, eg

public void caretUpdate(CaretEvent e) {
   if (e.getSource() == myFirstTextField) { ...
   else if ((e.getSource() == mySecondTextField) { ...
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The "import java.io is never used" message means what it says - you don't need that import and can simply delete it.
I'm not a Linux buff, so I don;t understand the second half of that output.

But this should definitely run:

public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello, World");
  }
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, there's no java code outside a class definition

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's how java keeps track of what classes are where: Every public class is defined an a source file called classname.java, and the compiled code is in classname.class (where classname is the (case-sensitive) name of the public class).
Sp you need to rename your source file to HelloWorld.java (or rename your class to hi - not recommended!)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If I understand your question, then yes. eg
ArrayList<String> = ...
ArrayList<Vector<String>> = ...
etc

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
static String name;
static double perDayCharge;
static double maximumCharge;

static means that there is only one value for this variable, and all instances of the class share that same single value. I bet that's not what you intended!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The return type for that method is defined as void, ie it does not return a value, so the is no return value to go with the return; statement. The return; just terminates execution of the method (in this case because there has been a fatal error).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You read in the data, change it in memory, then exit. Until you write the code to write the changed data to a file you will not see any changes.
You can check your code so far by printing stringRad at line 29

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi Unsated. Paul's advice looks good to me. Listen to him. J.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's because you go ahead and compute the average, even if there are no numbers. The average calculation is sum/count so if count is zero you get a divide by zero error.
After the user has entered his numbers, but before you calculate the average, you can test for count == 0 and stop there (eg return; from your method).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Look for the constructor that has a width/height, and use a type of TYPE_4BYTE_ABGR (ordinary RGB image, with an alpha channel so it can be transparent where you haven't drawn). You'll also find a method that creates a Graphics2D that you can draw your car on to create the actual image.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes,just like Norm said.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's an awful lot of drawing to repeat every 20 mSec, especially since nothing changes except an x position offset.
Why not create an Image and draw the car into that just once, then you can draw that Image to the panel's Graphics with a single call, which will be just one place to specify the x position of the whole car?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, good luck.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Of course we will help you through it. Make a start, and if you get stuck post the complete details of whatever it is that's stopping you progressing.

What? You didn't expect anyone to do it for you, did you? That would be cheating.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, you said that already in your first post. Just repeating yourself isn't helpful.

What exactly is it that you are stuck on? Is it asking the user? Getting the number from the user? Putting an 'x' or 'o' in the array (that one was answered by masijade already)? Something else?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

For animation or other time-based Swing code do not use a loop/sleep - you;'ll have all sorts of problems and sooner or later will block Swing's own thread so everything stops.
The correct approach is to use a javax.swing.Timer. You create a Timer that fires every 1000 millisecs and calls an actionPeformed method to update your animation.
Here's a good tutorial on how to do it:
http://download.oracle.com/javase/tutorial/uiswing/misc/timer.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's great! Please now help everybody else here by explaining how you solved it. Thank you.

mKorbel commented: hehehe +9
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you know for sure that it's possible and/or sensible to convert it? At first sight I can't see a sensible way to do it, and I would keep the loop you've currently got.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's basically right. Except that you wont find the number 987. Can you see why not?
You could fine-tune and optimise it a bit, but it will still look much the same.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 118 is in this context:

big.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent event) {
   String Selection = event.getActionCommand();

This code is only triggered by the big button, so there's no point testing

if(Selection.equals("Big")){

... even if you do code the if test correctly (see my earlier post)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

One last time: What sizes did you set? - specifically for the panel where you overrode paintComponent?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I apologise - missed the bit where you use lastIndexOf. Sorry.
I think it's simpler with an ordinary while loop rather than recursion, as in

while ((index = in.indexOf(" ")) >= 0) {
         result = in.substring(0, index) + " " + result;
         in = in.substring(index + 1); 
      }
      return in + " " + result;
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Let me guess - that doesn't reverse the words? As you are picking words from the input you need to insert them at the beginning of the builder, not the end.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I have already written code which does the same. Just wanted to find a better way to do it.So i could know where I could improve. This aint any school assignment either.

OK, thanks for clarifying that. I'm sure you can understand how it looked from your first post.

Anyway, your recursive method is cunning, but could be more understandably coded as a simple loop. You could also add the parsed-out words directly to a result String or StringBuilder without the need for the ArrayList. So I agree with stultuske, this could be a whole lot simpler.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in coding your homework for you.

DaniWeb Member Rules include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/forums/faq.php?faq=daniweb_policies
http://www.daniweb.com/forums/announcement8-2.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I dont understand what you mean by ...

//add(menu);
fast.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent event) {
      if(event.equals("Fast")){

This listener class is added to the "fast" button, and no other buttons. So when it is called the source can only be the fast button, so there's no need to test the source or the actionevent.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What sizes did you set?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Right click project - export - runnable jar file

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

if (event.equals("Fast")) etc
event is an ActionEvent , "Fast" is a String. They can never be equal.

But since each listener listens to events from just one menu item, you don't need that test anyway!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I understood it to be numbers like 321 or 987, but not 123 or 999. I think there are 120 3-digit numbers that meet the definition and 880 that don't.
I would use 3 nested for loops - one for each of the three digits, although it's possible with while loop(s) as well, if you prefer.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Each digit must be the range 0-9, so those are the limits for each loop (although you could optimise this a bit*). When you get a number (set of 3 digits) in the innermost loop that meets the requirements you print them. If you do the loops right the innermost one will execute 10x10x10 times, generating each number from 000 to 999 without any repetitions.

* since for all the numbers you are interested in n1 > n2 > n3, you can skip n1 = 0 or n1 = 1, and n2 = 0, because they cannot meet your requirement

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes. The clue is in "You'll want to do this using nested loops." Each loop requires its own loop variable, so your n1, n2, n3 will correspond to 3 nested loops. This won't use any arrays.