JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Those 4 bytes are the extra int -1.

I think you need some way to limit yout read loop to just read the right number of bytes from the input stream (ie the total bytes value that you read at the beginning) to create the image. Eg create a byte array of the right size (like you do in the server) and read into that in one go.
(I'm having to make this up as I go along because personally I've never done it this way, I have always used ObjectOutputStream/ObjectInputStream or XML to send stuff like this over a Socket.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The "cleanest" way is to return -2 or -3 from checkGuess, then use a if test (or switch) to print the right message,eg

guessResult = checkGuess(randomGuess);
if (guessResult == -1) {
   System.out.println("Well done");
} else if (guessResult == -2) {
   System.out.println("Sorry, too big");
(etc)

(note: for such a simple case it may look like a lot of overhead to separate the checking of the guess from the printing of the message. Maybe in this case it is. But in real life things get more complicated, and breaking up the logic like this is the right way to go. Doing it now will help to create good habits.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What value should checkGuess return if the numbers are not equal? (Not -1, but what?). You left that bit out when posting the requirements.

Anyway, in your code you create Strings like "Greater than the guess" then try to parse that as an int value. That won't work because the string doesn't contain anything that looks like an int. parseInt only works for strings like "100" or "-99" or "0". If the string doesn't represent an integer value parseInt throws an error at runtime.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, that makes sense. You're right.
In that case... maybe some kind of buffer flushing issue? I see you flush() the stream, so it should be OK, but anyway...
Just for a test, try writing/reading another int (eg -1) immediately after the file so you can confirm that nothing is still left in a network buffer somewhere.
Maybo someone else has some ideas here... please?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How is the set method declared? should be something like

void setTVMode(TvMode newMode) { 
   mode = newMode;
}

... in which case your myTv.setTvMode(TvMode.HDMI); should be OK

If you still have a problem be sure to post the complete error message and the exact line of code it refers to.

ps There's no point making the set method public if the parameter type is private!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's a bit confusing...
The logic will be simpler and safer (and without repetitions) if you structure it as:

count = is.read(...
if count >= 0
    bos.write(buffer, 0, count);
else
    // end of file reached
    displayPic();

(plus the diagnostic prints etc).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

is.read(bytes) reads some number of bytes into the array, then returns an int with the number of bytes actually read. That value is assigned to the variable read. Depending on the type of stream that may be a complete array-full of bytes, or some smaller number, or even, in theory, zero.

When the read() is at end of file it (obviously) doesn't read any bytes into the array, and returns a value of -1 to indicate eof. Thw while test tests for a -1 being returned, and stops looping when that happens.

eg Suppose yo have 300 bytes in a file, and a buffer size of 255
First read reads 255 bytes, returns 255, loop continues
Second read reads remaining 45 brtes, returns 45, loop continues
Third read is now at eof, reads no bytes, returns -1. Loop exits

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 11: You forgot to declare the type of the parameter.
Line 13: That's not how to fix the <parameter with the same name as a variable> problem. Use this to refer to the variable, eg

this.mode = mode;

For what you are doing so far, I think you're right to use an enum. If you start to add a load of different data or behaviours to each of those states then there will come a time when making them classes (as Stutltuske suggests) will be the best thing to do.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, looks like not enough memory. Try stopping and closing everything that's not essential for Eclipse and see if it's a bit faster. But really you need a bigger PC to run eclipse well under windows

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I just spotted this, maybe it's your bug?
Line 24 - if sum == num your if test fails and you don't process the data - so that looks like you are ignoring the last block of each file (for the last block the total number of bytes read should == num, not < num)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What size do you want it to be? Eg If you have multiple buttons do you want them all to be the same size?
setPrefferedSize is a last resort really ,because you set the size in pixels the when someone runs yur code on a retina display it looks really silly...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

^ like he said.
Post the code you use to create and set the initial position of the button, so someone can give you the appropriate answer.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

write(int) is misleading - it takes an int but just writes the last 8 bits of that as a single byte. So your length gets truncated to 8 bits. Still - it's better than mixing stream types!
Why not go up 1 level to DataOutputStream/InputStream so you can use writeInt and readInt (as well as your existing byte array writes & reads)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm very suspicious about mixing printwriter and direct calls on an OutputStream. Try getting rid of the printwriter stuff and simply write the int file length as an int.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The client code above reads a single byte array from the socket then closes the socket. Obviously that's not going to read multiple objects! Is there some other code you have that at least tries to read multiple objects?

ps I have plenty of working systems that send mutiple objects over a socket connection - just keep the sockets and streams open.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Howmuch memory does your PC have? How much is free before you start Eclipse?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

One that's declared in the class, but not inside the definition of any method or constructor, and isn't static.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's just a restriction on inner class binding to local variables (just ask if you want he full explanation). Simply make your timer variable an ordinary instance variable and the inner class will be abse to use it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your file name looks wrong - too many back-slashes. YOu only need two backslashes in your String literal to represent a single backslash in the file path

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

start returns when it has executed all the code you put in it. It's Application.launch that never returns.

Where exactly did you put the code to start the Timer?
Did you try a print in the update() method to confirm unambiguously whether it's being called?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You still have exactly the same problems I described in my previous post:
tick() contains an infinite loop that just runs at 100% CPU usage
start() never finishes because it calls tick() which never returns.

tick() seems to be trying to scheduling regular updates - if so a loop is the worst way to do it. Better to use a Timer to schedule regular calls, or maybe there's something in JavaFX itself that's like a Swing Timer.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe because you never finish the start method? (It calls tick() which never returns).

Anyway, that while loop in tick() looks very wrong to me - depending on what update() does that's just going to melt the CPU.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Classes and instances are all allocated on a JVM heap. Parameters and local variables in methods are allocated on the stack.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's why its better to System.out.println("controller: " + controller); etc!

I just did a little test case, running from a main that starts with an Application.launch(...) and, just like it says in the doc, that doesn't return and the code after it doesn't get executed.

Maybe you should put the following code (lines 7-9) in your start method or init method?.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe that code is running off the Application.launch - before you initialise the game variable?

<update> Javadoc for launch...

public static void launch(java.lang.String... args)

Launch a standalone application. <snip>
The launch method does not return until the application has exited, either via a call to Platform.exit or all of the application windows have been closed.

which implies your game = new Game(); won't be executed, so you will get a NPE anytime a callback tries to use it.

ps System.out.println("Hello"); does work. Are you starting the application from the project level... it doesn't work properly if you just run the main class file

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Beuase all the methods are the same, there's just one copy in memory. That's loaded when the class is loaded ie sometime before you first use it. The same is true of static variables.
Memory for instances of classes is created when the instance is created - that's a few bytes for the instance, plus enough for each of the instance variables.
Exactly how much memory. and exactly how it is allocated is private to each implementation of the Java Virtual Machine (JVM).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why not just a scheduled clean-up that uses map.remove(key) to remove unwanted entries?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Standard procedure: print all the variables at that line to see which one is null. It could be controller, controller.totalGoldLabel, game, or the returned value from game.getTotalGold()

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You just created a new topic with exactly the same question and exectly the same error. If you persist in ignoring the DaniWeb rules you will get infracted - possibly leading to a ban.

Do not post the same question multiple times http://www.daniweb.com/community/rules

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You started a new thread for no apparent reason, and without marking this solved - we'll continue the discussion here.

Please read my previous post. Your latest code makes exactly the same mistake

s = 2+((int)Math.random());

To explain in more detail:

Math.random() returns a floating point number >=0.0, <1.0
If you cast that to an integer type it will lose any fractional parts, so
(int) Math.random() will ALWAYS be zero, and s will always be 2
You must multiply by 5000 FIRST. That gives you a floating point number >=0.0 <5000.0, which you can then convert safely to integer with the result >=0, <= 4999

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is from WikiPedia...

In 2007 Oracle announced, that for the upcoming release of Forms version 11, Jinitiator would no longer be needed and that users should migrate to the Sun Java plug-in. In January 2010, a product obsolescence desupport notice was posted saying that JInitiator would no longer be supported and that all users should upgrade. Since version 10.1.2.0.2 of Forms in 2010, Oracle began working closely with Sun to phase out Jinitiator to completely phase it out.

... and a quick scan of Oracle's web site and blogs confirms this information.

It seems to me that any effort you put into learning about jInitiator will be a complete waste of your time.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Looks like a problem in your use of Random for the sleeps - you cast the floating point random number to an integer (therefore always zero) before multiplying it by 5000.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That all looks like good progress to me. There may still be mistakes (I didn't study every line) but what you are doing with the constrcutor and passing the values looks right. Have you tried it yet? Never be afraid to try to compile and run your code.

In your run method you could print the name (the thread ID won't tell you anything useful), and don't forget to have a loop that does the print numCheers times.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The loop on line 17 looks suspicious. Why not loop all the way down the list?
Line 15; what's the initial value of game?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are looking at docs for JDK/JavaFX version 8, but using a version 7 implementation. There are many changes and enhancements in 8.
You can download a "developer preview" of JDK 8 (includes JavaFX 8) from the Oracle web site. We're only a month a way from full release of Java 8 and I've found the preview to be solid and totally useful for some months now. If you use NetBeans you may also want to download the NetBeans 8 Beta.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Something like that...
But your names and nums are in two array lists, so you need to pass the elements of those lists to each constructor

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Annoying? Absolutely not! Sensible questions, and good use made of the answers. Ideal.
Mark solved?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Although a layered pane has no layout manager by default, you can still assign a layout manager to the layered pane.
http://docs.oracle.com/javase/tutorial/uiswing/components/layeredpane.html#layout

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Other way round. You add the layered pane to your JFrame, then add everything to the layered pane so you can overlap things as required.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's getting a lot closer!

When you create a new instance of MyThread that instance needs to know (1) the country name and (2) how many times to cheer. Then it can use a loop to print the country name the right number of times.
That implies that MyThread needs two instance variables - countryName and numberOfCheers. You can then write a constructor that accepts values for both those variables. Then on line 56 where you create the new instance of MyThread you can pass in the country name and the number of cheers.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK people, let's just cool down a bit.

Fatima: I'm not sure how people can answer this thread. If anyone had any ideas for projects they will have added them to the long list in the Beginner's Projects thread. You rejected every single one of those. The requirements you posted are so very general that it's not clear why none of the listed projects will fit, but also they are so general that they don't point towards anything in particular.

Perhaps the best advice I can give is to think of some (non computer) activity or topic that really interests you, and build a project about that. For example I'm a very keen (but useless) guitar player, so I might do a project to organise and display all the sheet music I've scanned or copied from the web. Surely you have something that you personally would be keen on? Not only will you have a good understanding of the application, but you will find it a lot more interesting and rewarding - which will shine through in the final result.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That looks like you didn't enter an int value in response to the "Enter first coeffecient: " prompt.
???

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You just copy/pasted your assignment without even a moment taken to explain what help you need. That's highly disrepestectful to the many people who give their time to help others here.

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 helping you cheat or doing your homework for you.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

+1 for JLayeredPane - it's what it was designed for

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If there's absolutely nothing in the beginner's project thread that "satisfies your needs", then maybe you can explain what your needs are, so someone can make suitable suggestions.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This problem breaks down into two distinct stages:
1. Collect all the info from the user (10 names, 10 counts) and store those in two arrays...
then...
2. Using that info stored in the arrays, use a loop (see above) create and start 10 threads

You can't mix the user input and starting the threads because the user will take so long to type that any previous threads wil have finished long before you start the next one.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's your answer. You refer to a class TestScores on line 36, but nowhere do you have a definition of TestScores.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

First point: never say "gives me an exception". Alwyas say exactly what the exception is and which line its on.
Second: on line 43 you check if ts is null, but that's too late. If it's null then you wil get a null pointer exception on line 40

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you try
frame.getRootPane().setDefaultButton(goButton);
?