JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Not enough code to tell, but looks like a mis-matched bracket shortly before the line where you get the error.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I answered this in my previous post (and in my post on your duplicate thread).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... and put line 5 outside the loop!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Wrong fix (see previous post). By putting in the extra { you have (1) recalculated the average every time you add one number (10 times), rather than waiting to the end, and (2) left the declaration of average inside the unnecessary {} brackets, so it no longer exists when you try to use it in the next loop.
The error in line 25 is because you calculate a floating point value using sum, the assign that to an integer, thus losing any decimal places. In fact, since the raw data is int, sum can also be int, but average should probably be float.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe not. The loop in lines 22/23 is a single statement loop. The calculation of the average on line 25 should be outside the loop, so the error is the superfluous } on line 18.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

static java methods is a bit slower than default methods .!

That's interesting. Do you have a source for that information?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's common practice in the Java API to make "utility" methods static, so that makes it OK for me.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Probably one too many } brackets. Repost code with code=java tags and corect indentation.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So ,it is all about convert the string into char

Not exactly. charAt is about extracting a particular single char from a String.
The chars in a Java String are numbered from 0 to (length of String -1).
charAt(n) gives you the char in position n in the String.
So if the String is "Hello", charAt(0) is 'H', charAt(1) is "e", charAt(4) is 'o'.

You need to extract a single char in this case because you can't do a switch on a String value.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

...But the programmer in his mind that the firt (implicit "this") point to an instance of the MainPagePanel not to the inner class MapLabel .

Ah, OK, now I see the point you are making. Thanks

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

But writing the instruction:
addMouseListener(this);
in the inner class MapLabel means that the implicite (ommited optional"this") point to the same variable "this" the parammetre of the method addMousListner.

Yes, but so what? I don't understand what point you are trying to make.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What do you mean by that? Do you think it is wrong?

No, there's nothing wrong with it all. It's definitely not ambiguous!

addMouseListener(this);

calls the addMouseListener method on the current object - the thing called "this".

this.addMouseListener(this);

just makes that fact explicit, but the first "this" is unnecessary.

People don't normally code the "this" in this.someMethod, but there are times when you may want to do that to draw a reader's attention to what you are doing.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Employee[] empArr = new Employee[5];
...
for( i = 0; i < empArr.length; i++ )
...
empArr[i].setEid( in.nextInt());

You create an array of 5 elements that can be used to hold Employees, but this does not populate the array with actual Employees. So when you try to use empArr[0] there's nothing there and you get a null pointer exception.
A quick empArr = new Employee(); at the start of the loop will fix it, but the more usual approach is to write a constructor that takes all the mandatory values so you can create an Employee with something like
new Employee(eid, firstName, lastName)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The ArrayList holds CD objects. You get at the value etc by using the methods that you should have for each cd, eg

int value = 0;
for (CD cd : CD.getAllCDs()) {
    value += cd.getValue();
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Its often a good idea in a class like this to create a static Collection that holds all the instances that have been created. This allows you to loop through all the instances counting, totalling value, searching for particular artists etc. Something like

private static ArrayList<CD> allCDs = new ArrayList etc
public static  ArrayList<CD> gatAllCDs() {
   return allCDs;
}
// then, in the constructor...
allCDs.add(this);
// then, from anywhere else...
for (CD cd : CD.getAllCDs()) {
  // do whatever with each cd
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... "\n" is platform specific and is not always guaranteed to get the effect you wanted.

Just in case this matters: you can use

System.getProperty("line.separator");

to get the line separator string appropriate to the current platform.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just before starting the search, create a "global" int depth = 0;
Increment it in the "down" method and decrement it in the "up" method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Of the various options proposed so far, the best to start with is quuba's to override the inherited toString() method in your class. As well as allowing you to simply say System.out.println(a); and get the expected rseult, this will also work if, for example, you want to display the value in a GUI.

toString() is a method defined in Object, and which all objects therefore inherit. Many methods in the Java API call toString, eg prrintln(...) The inherited method just returns a String containing the class name and the object reference - not very useful. It's a recommended practice to supply your own public toString() method for any class you write that returns a more informative Sttring - it's up to you to decide what info you want to see for your class. You'll see that the majority of the classes in the Java API do exactly that.

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

Looks like your input data has a value that is not one of your enum constants. Try printing str.substring(4,6) immediately before the switch.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

array_of_rooms.room_status = 0;

should be

array_of_rooms.room_status = 0;

ie you index the array of rooms, not the status, which is not an array!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Suggest you remove the main(...) in MyArrayList in case you're running that one by mistake?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Suggest you close this thread, and if you have a new question, start a new thread with a suitable title so people can see what's relevant or interesting.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

RMI lets you call remote methods, and return whatever the method returns (need not be void).
http://java.sun.com/javase/6/docs/technotes/guides/rmi/hello/hello-world.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't know if they are the best possible solution, but I do know that Sockets work very well for that kind of thing. You can pass objects as you suggested, but I don't think that will include the links to an actual open on-screen window. Rather than pass the object you may be better off adding the necessary interface methods to the jar and using RMI to call them.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please clarify:
Do you want to start the program in the jar, the start a second program that accesses objects from the jar program
or
do you want to write one program that includes and uses the classes in the jar
?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

[short version]: Java applets can't access the local file system without special permissions. Your applet should load any files you need from the server.

tux4life commented: Good post :) +19
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry James,
Like I said I am not getting this very good. I have trouble knowing what the statements, arrays, components, etc, etc mean. I really appreciate your help however. Thank you very much!

Don't worry! We all started from the same point. Stick with it and it will get easier. You soon get to know what the most common messages mean - in this case "illegal start of expression" usually means that there's an error immediately before where it says, ie it's saying "I didn't expect you to start another statement just yet". In your case, that was because you had finished the previous code (by adding a semicolon) too early.
ps Sorry if I referred to you as "he" when if it should have been "she". It's hard to know who you're dealing with behind an internet ID :-)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

sry but jamesCherril was wrong, you didnt need that extra semi-colon, i cant solve your over problem though, im not sure what public void init() is or does...

Sorry man, you really should read the post properly before telling someone they are wrong in public (even more so if you don't know the syntax of a method declaqration). I didn't suggest another ;, especially not where the OP then put it. If you read what I wrote carefully and match it to the code he posted there's only one way to interpret it.
ps That's James with a capital "J" and Cherrill with two "l"s

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No semicolon between public void init() and {

When I wrote that I expected that you would realise I was saying there should be no ; between the () and the {
ie it should read

public void init() { ...

Seemed clear enough to me...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

String s = "123";
int i = Integer.parseInt(s);

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No semicolon between public void init() and {

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You will have to maintain 3 variables in which you keep the number of things actually stored in each array. This is one of the many reasons why people tend to use ArrayLists rather than naked arays.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

(sorry, parallel posting with BJSJC, says same thing)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ps. Think about having an array (or ArrayList) of JLabels and a loop rather than repeating the same code 100 times

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your method calls need to be in some kind of method - maybe the constructor. You can't just have them lying around in the class definition like that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe I don't understand your problem... but public static methods on public Classes can be referenced from anywhere; you dont need to pass anything. In C you can just say A.getData(); or B.getData(); whenever you want.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In reposnse to a the buttons actionevent, get the curently selected row's number, add 1, selec that row. See JTable and DefaultListSelectionModel in the API.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

aThread.run();
is your problem. This calls the run method on the current thread.
You should use aThread.start(); twhich calls the run() method on a new thread

toucan commented: Astute diagnosis. +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This whole loop-with-a- sleep-in-it polling approach is a poor way to go, even if you get it to work. You want your thread to go into a wait state and wait passively until notified to exit the wait, which it should do without further dalay. Have a look at wait() and notify() - you'll find loads of info via Google.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

AFAIK this is a perfectly normal thing to do. If you just declare it, it will have the value null anyway, but the compiler will complain that it may be uninitialised. The runtime will throw a null pointer exception if your logic fails to initilaise it to a genuine reference before you try to use it.
Anyway, your problem was not caused by how it's initialised, it's caused by you declaring the variable in the wrong place. Its scope is limited to the block in which it's declared, so it goes out iof scope as soon as you leave the if block.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Try moving the declaration of x outside the if test;

abc x = null;
if(flag)
{
x = new abc();
}
...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

what's the difference between static inner classes and regular inner classes?
...
Also, can you even access an extended class's inner classes?
hmm...

http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html

Yes, you can

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What an interesting idea! I haven't tried this, but some questions need answering:
Ability is abstract, so you can't instantiate it. The inner classes are not static, so they need an instance of Ability. ?
Since each of the inner classes extend Ability, they each inherit the inner classes, so presumably you could do al kinds of unintended recursive things?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

sure, I am getting the error on this line code:
while([] counter <= 10);

What are you trying to achieve with the [] ?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

>The Java platform supports a simple, deterministic scheduling
>algorithm called fixed-priority scheduling

Any official links? AFAIK, the JVM specification makes no such claim and leaves the details entirely to the implementation. I personally would be rather cautious in accepting anything which isn't stated in the official docs/ vm specification.

Yes, I agree that you need to be careful where you get this kind of info from , and only Sun is definitive. Sadly, Sun give us almost nothing to go on, and the detailed scheduling algorithms have changed between pre 1.4.2, 1.4.2, and 1.5 (at least), and also vary between OSs.

The following quote is from http://java.sun.com/j2se/1.5.0/docs/guide/vm/thread-priorities.html and strictly applies to Solaris, but the message in this quote is surely a general statement of intent:

General Scheduling Issues: Priority, Yielding, and Monitor Fairness

The Thread.setPriority and Thread.yield methods are advisory. They constitute hints from the application to the JVM. Properly written, robust, platform-independent code can use setPriority() and yield() to optimize the performance of the application, but should not depend on these attributes for correctness. Likewise, no assumptions should be made about the order in which threads are granted ownership of a monitor or the order in which threads wake in response to the notify or notifyAll method. An excellent reference for these topics is Chapter 9, "Threads," in Joshua Bloch's book Effective Java Programming Language Guide.

The source I quoted in my previous post was (I thought) a reasonable summary of the situation (with …

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You may find the following useful - in summary: when threads of equal priority are scheduled the order is arbitrary (although round-robin scheduling gives them all a chance). Time slicing and multiple CPUs make this a lot less deterministic. In summary summary - you can't assume anything about the order of execution of threads of the same priority.

Thread Scheduling Summary

* Many computers have only one CPU, so threads must share it with other threads. The execution of multiple threads on a single CPU, in some order, is called scheduling. The Java platform supports a simple, deterministic scheduling algorithm called fixed-priority scheduling:
* Each thread has a numeric priority between MIN_PRIORITY and MAX_PRIORITY (constants defined in the Thread class). At any given time, when multiple threads are ready to be executed, the highest-priority thread is chosen for execution. Only when that thread stops or is suspended will a lower-priority thread start executing.
* When all the Runnable threads in the system have the same priority, the scheduler arbitrarily chooses one of them to run.
* The Java platform does not directly time slice. However, the system implementation of threads underlying the Thread class may support time slicing. Do not write code that relies on time slicing.
* A given thread may give up its right to execute at any time by calling the yield method. Threads can yield the CPU only to other threads of the same priority. Attempts to yield to a …

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Shouldn't be too hard, and you don't need JAI if you don't want to go there. You can use the Image class to get the image, then the PixelGrabber class to get an array of all the pixel values. Once you've got that you can shuffle it using simple array manipulations. Then you can create a BufferedImage from the shuffled array.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You'll need to pass the item to delete as a parameter. Loop thru the array until you hit that item, then continue thru the rest of the array moving each item down by 1 position. But, as stephen84 says, there are classes in theAPI that already do all that stuff, so why re-invent the wheel?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

YOur code looks better now. You don't need to return the File from the new method, just leave the return s void. And
read(new File(file.getAbsolutePath()))
is just a long way to say
read(file)
Now all the other GrabPixels stuff needs to be called from in here instead of being in the GrabPixels constructor.