JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just read & write the HashMap as a single Object using a single read/write call on Object input/output streams. Easy & fast.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How about: sw1=true;sw2=false;
Those values only get changed at lines 59/60 if th>T1, so maybe that's never true (see previous post).
ps It's really hard to read complex if logic when the indentation is wrong. Get yourself a code editor that indents for you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm pretty certain you have to read and re-write the data from the insertion point to EOF. How big is the file? There's no problem with (say) 100Mb reading the whole thing into memory, modfying it, the re-writing it.
If your data is more structured than the example the there may be a smarter way to organise it. Eg if consists of records with known formats, and you want to insert a whole record, you can structure the file with each record holding a pointer to the next logical record. Then you can add the new record to the physical end of the file and just overwrite a couple of pointer values to insert it in the right logical position.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

th=spoofpkt/totalpkt;

because th is an int, and assuming spoofpkt < totalpkt, th will always be zero (integer division is always rounded down to an integer value). You could make th a float to hold fractional values.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You normally only need an ImageObserver when you are loading an image asynchronously and need to know when it's finished loading (eg in a web page). Once the Image is loaded you just need the Image itself (or a suitable public method in the class that "owns" the Image).

ps It's OK to pass null as the ImageObserver to getWidth/Height if you are confident the Image has finished loading.
int width = image.getWidth(null);


pps: Crazy Dieter - did you notice this zombie thread is a year and a half old when you tried to resurrect it? (And stupid me for not checking)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK. That tells you the problem is nothing to do with your Scanner.
It's always important to read carefully what the Exception messages say. They usually tell you exactly what the problem is and where. In this case:
It's a NumberFormatException. You can look that up in the API JavaDoc to find exactly what it means. In this case, tried to parse a String as an integer but the String did not have the right format for a number because it was empty ("").
It happened in the Integer.parseInt method which you called at line 14 of your main method of IP2HC_Inspect.
(No, I'm not psychic - all that is in the error message you posted.)

That should be enough info for you to be able to find your problem.

ps: Typed that before I saw your later post without the Exception. So now you enter two lines (and a blank line I presume?) and your program terminates without error. Not much I can do about that.
Put lots of print statements into your code so you can see which blocks of code are being executed and what the values of your variables are. If you do enough of these you will find your problem.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Since two scanners didn't fix it, roll back to having just one.
The code in your last post should run OK - what exactly happens when you run it?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why do you create two Scanners?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is there any digital exers with problems solving explanation you've came across and wanted to share?

I'm not the best person to ask about that, sorry. When I learned Java the only books were hand-printed on parchment scrolls, and I think they are no longer available except in museums!
I'm sure that someone else here can help with this very reasonable question. (Come on guys!)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi tracydo
Those of us who post here regularly always have great difficulty knowing how far to go in helping with homework questions. If you give someone a complete solution they will probably just copy/paste it and learn nothing (not to mention cheat). So we try to give enough info for the student to do a bit of research and find the answer for themselves, learning all the way. We do that through hints, keywords for Google searches, web references etc.
Sometimes we make it a bit too cryptic, in which case please don't be worried about asking for clarification. Our overall goal is to help people learn Java, as opposed to just helping them answer an exam question,
:-)
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Eclipse is a memory monster if you use a lot of hefty plugins, heck even without plugins...

I'm looking at just under 200Meg right now with a pretty large project in play (excluding the project's own run-time memory requirements, obviously). You can do serious development with Eclipse in a 1Gig machine under Win 7.
I've found CPU speed to be far more limiting of Eclipse performance than memory is.

I certainly echo the need for a decent source control system.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi forhacksf. Please be careful to help tracydo without actually doing her(?) homework for her - no complete solutions.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are passing the value 4 OK, but that's not the right way to get the returned value. Check out your course notes for an example of calling a method that has a return value.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Suggest you re-read my previous post:
Start with an empty String ("").
In the loop append all the names/scores/newline characters to it.
After the loop display it in your option pane.

You append something to a String with syntax like:
myString = myString + " some new text " + "\n";

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Start with an empty String (""). In the loop append all the names/scores/newline characters to it. After the loop display it in your option pane.
If that still isn't working for you, post the relevant part of your updated code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could concatenate all the names & grades into one String, with \n chars after each line, then display that String

names[1]+ " " + grades[1] + "\n" + names[2]+ " " + grades[2] + "\n" + ... etc (but build it in a loop, obviously)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

FWIW I've used Eclipse for quite a few years now and am very happy with it. If I need something that's not in the basic package then there's bound to be a plugin for it. There's a bit of a learning curve over how files in the IDE relate to the OS file system when setting up a project, but once you get that it's easy.
I know this was said before but it bears repeating: if you're serious about this have a look at job ads in your preferred area and see which IDEs are most commonly listed in the skills pre-requisites. You'll probably see Eclipse and NetBeans (in that order).

ps: In IBM sites there's a strong push to use SWT rather than Swing for Windows GUIs. SWT vs Swing is outside the scope of this thread, but if SWT is important to you then Eclipse is the natural and obvious choice.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I still think it is my comparison making going against itself but I don't know how to fix that.

Yes, that's the problem.
You loop thru all the balls taking one at a time and comparing it with... itself. (Rectangles r and p are always identical.)
You need to compare two different balls, which should instinctively suggest that you need two loops.
Remember also that if you've compared 1 with 2, the there's no need to compare 2 with 1.
So the comparisons you need to do look like this:
1 vs 2, 1 vs 3, 1 vs 4 ... 1 vs n
2 vs 3, 2 vs 4 ... 2 vs n
...
n-1 vs n
I'll leave you to think about how to code those loops.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What are the symptoms you are getting? - you don't actually describe the problem anywhere.
Does your animation loop actually call the method to test for collisions after calling move?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you call a method you have to supply parameters that exactly match the parameters listed in the method declaration.
Now look at your declaration of the findBiggest method, then look at your attempted call to that method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

String diverName = fileLine.substring(0,fileLine.indexOf("-"));
String strScore = fileLine.substring(fileLine.indexOf("-")+2, fileLine.length());

Guess what happens if there is no "-" in any particular line. ;-)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to return a variable that holds an array of Rectanges. Rectangle[] isn't a variable. Think now - what is the variable that holds your array of Rectangles?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If the things are in any kind of Collection you can use addAll(Collection c),
If it''s an array you can use Arrays.toList(...) to convert the array to a List that you can pass to addAll

but is there a way to add things into arraylist iteratively one by one?

That is exactly what your code is doing!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's "solved" then?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Its the same as int except that it holds very much larger numbers
For int, from -2147483648 to 2147483647, inclusive
For long, from -9223372036854775808 to 9223372036854775807, inclusive
You use it whenever you want an integer value that may be bigger than the largest int

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java variables come in 2 flavours, primitives (eg int, char, byte, float, boolean - all lower case names) and reference variables (which you can think of as pointers).
All variables of array or Object types are reference variables. So, in your code message_one and message_two are reference variables of type String, or string pointers. The memory for those pointers is part of sscanner's memory. Initially they are both null (refer to nothing).
"Hello!" and "World!" are two new instances of the String class whose memory is allocated in the heap. Your two variables are then set to refer to these two instances. ie
message_one -> "Hello!"
message_two -> "World!"

You then execute
message_two = message_one;
which copies the value (the reference or pointer value) of message_one to message_two. After which
message_one -> "Hello!"
message_two -> "Hello!"

There are now no remaining references to the "World!" object, so it will be garbage collected and its memory released.
Finally you execute
message_one = scan.nextLine();
scan.nextLine() creates a new String object containing the user input, and message_one's value (the reference or pointer value) is set to refer to that new String, so you now have
message_one -> "This is a test sentence."
message_two -> "Hello!"

\007 commented: Thanks! +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

As a general rule of OO design, you shouldn't have one class getting involved with the internals of another. It entangles them to the point where you dare not change one for fear of breaking the other - exactly the opposite of how it should be.
Without details of your exact requirement, I would say identify what adding the button is for, in architecture terms, and create a public method in class A to do that eg: if it's there to allow the user to Save under some circumstances you would have public void setSaveEnabled(boolean enable){ make button visible/invisible} Then in class B you can call that without knowing anything about what GUI controls class has or how it organises them. That's "encapsulation" the way it should be.

ps: You asked about object destruction - this happens as part of garbage collection in Java. As long as an instance of either class has a reference, direct or indirect, to the object it will not be garbage collected. It's a kind of "don't worry about it, it just works" thing. My objections to doing what you described are not that it won't work, because it will. It's just anti-encapsulation.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Glad to help! Mark this thread "solved" now?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Catching the Exceptions when the socket closes (for whatever reason) is an ordinary thing to do. If the loop is inside the try clause then the catch will be outside the loop, thus exiting it. After the catch clause execution falls thru to the end of the run() method, and the Thread terminates normally.
It's often hard for people to make the mental change of gear between c++ and Java. I'm not going to argue here that either is better, but they do have different idioms and assumptions to catch out the unwary convert.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

As far as I remember (not at desk now) when the Socket connection closes the read throws an Exception, so you just have to handle that tidily. It's common practice to have a "disconnecting now" messsage that either end can send to the other so the receiving end can exit its read loop and close without throwing any Exceptions

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's weird. Can you post more of the code? Are yo getting any Exceptions thrown?

ps Are you continuing to try to read after the client has closed the socket or stream from it's end?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It goes like this (in outline - details all omitted)...

BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
while (true) {
  String message=in.readLine(); 
  System.out.println("Client: received message: " + message);
}

That all goes in the run() method for a class that extends Thread (eg "ClientHandler").

while (true) {
  Socket socket = server.accept();
  new ClientHandler(socket).start();
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Normally, as each client connects, you start a new Thread to handle I/O from that one client. You end up with one thread waiting for new connections, plus 1 thread per client waiting for I/O (plus threads for GUI etc).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's a standard way to do this:
1. Change the WebCrawler constructor to take an instance of CrawlAnalyseGUI as a parameter - so line 15 will read
final WebCrawler crawler = new WebCrawler(this);
Now the webcrawler has a reference to the GUI.
2. Add a public method to CrawlAnalyseGUI that can be used to update the GUI with progress from the crawler - mabe something like
public void updateProgress(int toDo, int done) {
// update JLabels etc
}

3. In the WebCrawler, whenever there is progress to report, call updateProgress on the GUI instance (as passed to its constructor).
4. Sit back, watch it work perfectly, feel smug.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's not the way to make in simple in a GUI. Look at JOptionPane

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Can't say without the whole picture. But like I said before, update the queries and calculations in a method (whatever class it may be in) from the Timer, and update the contents of the JPanel (by querying the previously-retrieved data & calcs) in the paintComponent. You should only need to set up the JPanel once.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

AFAICS you have a text area in which you put the complete text of a menu. You then get that complete text back into a String, then try to parse the whole thing as a single integer. Obviously it's not just an integer, so Exception.
This is more than just a coding problem. Your design follows the pattern for a command line interface, but that's not going to work in a GUI. You need to prompt the user, wait for a response, then deal with the user's input. Have a look at JOptionPane for a good way to handle user input.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Where's the code that updates the data from the database?
Your structure should be:
timer actionPerformed updates data objects and calls repaint() for the GUI
paintComponent(...) does the minimum needed to keep the GUI in step with the data objects.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Excellent. Mark thi one solved now?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

String rel = yr+Intyrs;

yr is a String, so the + sign is treated as String concatenation, and Intyrs is converted to String and concatenated onto yr.
For this to work you need to + two ints.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

java.util.Calendar allows you to add days, or months, or years, just like you asked. But if you have to do this yourself, then yes, just add 5 to the year part and leave the month and day alone*

* unless, of course, the start date is 2012-02-29

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I would pass the PrintWriter as a parameter to all the WriteData methods. So it's created and closed in the same place as the loop (eg your Main program).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have a look at BitSet. It holds long strings of bits, fully packed at 64 bits per 8 bytes, and can be written/read to/from files as a single Object using Object input/output streams.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

From the EditorPane you can get its EditorKit, and from that you can get the Document itself.
You can add a DocumentListener to the Document to be notified of all changes the user makes. Send those via the Socket connection. At the other end you can insert (or remove) the changes in the other Document.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please let us know how you get on - especially if you find a way to get it under Win L&F
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry, that's not something I've tried. I guess you'll just have to keep experimenting, unless anyone else has a better idea...?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I've never tried this, but the nodes in JTree are rendered by default using JLabels.
You can put multi-line text in a JLabel by using simple HTML, so maybe you can use HTML to get multi-line nodes? Try a node with text like this:
<HTML>line 1a<BR>line1b<?HTML>
you never know...

Just tried it - it works.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Interesting how one idea sparks another...
Maybe you can wrap the app inside a wrapper program that takes keystrokes & mouse clicks and passes them directly to the original app (so the app continues to work like beofore), but also keeps a log of all those on an external log file. So if things crash you can use the same wrapper program to re-play the keystrokes and mouse clicks from the file to re-instate the pre-crash situation?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hmmmm. It looks to me like you are on mission impossible here. IMHO it needs to be re-implemented. Sorry, I have no more ideas.

If I'm monitoring DaniWeb for interesting new posts I use a neat Firefox addon called ReloadEvery http://reloadevery.mozdev.org/ and set it to refresh the page every 5 mins or so. Works a treat for me.

Majestics commented: Thanx..... +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK. Mark this thread as solved please.