JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you have MSN messenger or Steam Friends where I can chat with you?

Sorry, no, I don't do chat.
Also consider that people come here to learn and to contribute. By taking a topic offline we deny then that chance.
Finally, I would encourage you to start a new thread for each separate topic and give it a good descriptive name so people can find it and refer to it later. Be proud to be part of the making of a repository of problems & solutions.
regards
James
ps: glad you got the FPS thing working OK.

~s.o.s~ commented: Wise words indeed. +29
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... do you think that it could be the arrayList?

Maybe - that's a part of the code I don't have. But what you say sounds credible for why the old bean info is still there.

I still think that if values[0] is OK and values[1] isn't then values has exactly 1 element. If it's returned from a split then the String being split has only 1 value. If said String comes from a readLine then... etc etc

KirkPatrick commented: Thank you for the help on this problem. Mostly thank you for your time as its a valuable resource +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your code is executing on the Swing (event dispatch) thread, so all screen updates are held up until your method returns. That's why there's no screen update when you sleep. It's only after that method completes that the screen is updated.
Solution is to use a Swing Timer http://www.j2ee.me/docs/books/tutorial/uiswing/misc/timer.html
In your method set the green colour, then start a swing timer for 1 second that turns the colour back to grey when the timer expires. Your method returns immediately, the green change is drawn, then 1 sec later the timer expires and the change to grey is implemented.

Ezzaral commented: Good suggestion. +24
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Create a parent class Daniweb, with one method "help me with my homework" which takes two parameters: problemDefinition and whatIDidSoFar.
If the second parameter is null, throw a NoHelpWithoutEffort Exception

javaAddict commented: I will honestly implement that +7
peter_budo commented: I do not want to be sarcastic, but you got that one right +19
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Re Nodes. Yes, more than just an int, I think this should be a proper class. In particular, I suspect it will be useful to have each Node hold a list of the Edges that connect to it. That way you will be able to navigate from Node to Node via the Edges. You can easily populate that list from the Edge constructor, provided that the Nodes are created before the Edges.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Open the file into a FileInputStream, read (say) 1024 bytes at a time, send them over the Socket connection. At the other end read the incoming bytes from the socket and write them toa FileOutputStream. Wrap the whole process in a simple protocol for requesting a file and hey presto!

bharatshivram commented: thanx.. +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

throws appears as part of the declaration of a method. It tells you that when you call that method the named Exception may be thrown by that method, and that you need to handle it in some way.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If Pr.class is inside of C:\mylib, the classpath should be c:\ As you have it now, its looking for mylib.classwhatever inside C:\mylib - ie 1 too many mylibs.

freelancelote commented: Just what I needed. Thanks +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe you can use the java.awt.Robot class. This was intended for automating tests of a GUI, and allows you to post mouse and keyboard events directly onto the host operating system's event queue.
http://java.sun.com/j2se/1.6.0/docs/api/java/awt/Robot.html

Majestics commented: Great Help +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

My pleasure. J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

InputStream, as the Java API doc makes very clear, is an abstract class; it's definition is incomplete and you cannot instantiate it with new. It's purpose in life is to define a standard set of operations that any byte-oriented input stream should implement. As also explained in the API doc, it has a number of subclasses that you can instantiate, including one that is based on a byte[] array. So, you can declare is as an InputStream reference variable, but you have to instantiate one of its subclasses to get a real input stream to use as its value.
Finally, it's the input stream you need to close, not your integer.
oh, and ps, read the API doc for InputStream.read() to find out what it returns (hint: it's not a byte array) and what it does when it reaches end-of-file (hint: it doesn't return null).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

THis capability was added to Java in the latest version (1.6, aka Java 6).
http://blogs.sun.com/CoreJavaTechTips/entry/getting_to_know_system_tray

BestJewSinceJC commented: resourcefulness = + +5
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi, I'm back! AFIK the rule is that the numbers are padded with leading blanks to a fixed total width, so they all line up in columns, right-aligned.
1. The rule, therefore the code, is the same for all columns except the first - there's no need to replicate all those code fragments.
2. Suppose the desired width is 5 chars. You stick 5 chars on the front OK, but the you need to substring the last 5 chars. So substring(1) isn't going to work. The substring need to start 5 chars before the end of the string. You're going to need the length() method (as I said before). Try writing down a couple of examples on a piece of paper and see if you can work out the correct sunstring expression before trying to code it.
(Hi, BJSJC!)

BestJewSinceJC commented: Hi to you too! And you gave a lot of good info in this thread :) +5
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If I understand right, your data volume looks like max 1 record per user per day, so there's no need for heavyweight database technogy. Java DB will probably be perfect here.
Deployment of the database comes in 2 main parts - installing the db software (trivial with Java DB, depends on licences etc for other databases), - and installing your empty/startup database, which mainly comes down to where to put it. System.getProperty("user.home" is a good start.
=======================================
Re software design. I don't mean this in any rude way, but your design, with the file IO calling the GUI, could certainly be improved. If you're interested in using this as a learning vehicle, and you're ready to take a quantum leap in your architectural skills, I'd be glad to help. If you have other priorities right now, that's OK too.
J.

~s.o.s~ commented: +rep for the sincere sentiment to help out a beginner. +28
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Either way, you could (should?) make the storage mechanism "pluggable" by defining an abstract class that handles all the store/retrieve operations and then implement flat file and/or SQL versions as required.

verruckt24 commented: You are right. +4
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi there. When I suggested the name/ConnectedClient Hashtable, I was thinking on to the scenario of multiple clients, and wanting to forward a message from one of them to just one of the others - hence the need to give each of them a login name by which they can be identified. If all you need now (and later?) is to send the message to all connected clients, you can simplify the Hashtable to a simple ArrayList or Vector containing the ConnectedClients, and just loop thru that calling the send method for each client.

It looks like there's a glitch in your sendMessage. When you call it you pass in the socket - which is the socket of the client who sent the message! You don't want the socket parameter; the instance implementing the sendMessage method should use it's own socket.

BestJewSinceJC commented: More good points +5
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1. 22/7 is a calculation using 2 integers, so it's performed in int arithmetic, giving the int result 3, which is then assigned to the long variable. Just making one of the values a floating poit number will force the calc into floating point, eg 22.0/7
2. When you calc the volume you pass in a radius & height, which are the same both times. The volume method should not need any parameters, it should use the values it already has.

AirmanTheGreat commented: Win +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java's not the best choice for this kind of thing.
Here's a script that does what you want:
http://www.interclasse.com/scripts/killpopup.php

ithelp commented: Thanks. ithelp +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi guys! Just saw this thread and had to join in!
For me, the key issue about separation of GUI and model is about good architecture. Sure, you can hard-code calls to the GUI in the model, and hard-code calls to the model in the GUI, but if you do both you just get one big ball of spaghetti and an inevitable decline into chaos.
IMHO GUI/model separation requires the use of Observer, no choice.
The point is that the model just implements an Observable interface, and has no knowledge of the GUI or anything else that may use it.
You can code, compile, and test, the model without the GUI, then you can safely put it in jar, and get on the the GUI as a separate task.
The project I'm currently doing enhancement work on has one model, but supports three user interfaces (local GUI, remote GUI, web browser). Because it had proper Observer architecture, adding the web browser interface required zero changes to the model or the GUI code. That's enough to convince me.
In response to the specific Q about lots of windows and selective updating: I think you should not try to split the Observable interface into sub-interfaces to meet a GUI requirement; that's just another way to entangle the two layers. Provide an Observable interface that's designed around the model and what can happen within it. Windows, or whatever, can register with the model if they want to …

Ezzaral commented: All good info. +20
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here's why: when you create a subclass, and you write a subclass constructor, and in that constructor you do not have a call to the superclass constructor as the first statement, the Java compiler puts in a call to super() by default (in order to ensure that everything inherited from the superclass is initialised). In your superclass you have a constructor, but not a default constructor (ie public Employee() ).
I guess that when you create a work (ps should be Work) they should still have a name & number, because they are Employees, so maybe the constructor should be something like

public work(int sh, String nm, String num){
    super(nm, num);
    shift=sh;
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, you can do that, but what when you want to return a value of type T? If you define the result as Integer, that's OK, you can then do the same thing for Double, that's OK too, now you have overloaded methods that will work, but that's not what the OP was asking.

You can try this

public <T extends Number> T sum(Stack<T> stack) {
	Integer sum = 0;
	for (T num : stack){
		Integer n = (Integer) num;
		sum += n;
	}
	return (T) sum;
}

and hope that if <T> happens to be Double then the value won't overflow, or do the same thing with Double temp variables, and hope there's no rounding problems, and no runtime cast errors...

osjak commented: Helpful, thanks! +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

probably easiest to get the files directly, and loop thru them, as in

File files[] = directory.listFiles();
for (File f : files) {
   // do whatever you want with each  File f
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

JTable really is the right way to do this, so it's worth the one-time effort to learn about them!
Here's a quick sample of what you need to create a suitable table model (I haven't compiled this, so expect the odd typo, but it should be good enough to get you going right).
It has a constructor to which you pass your Adults array, as in new MyTableModel(MyArray); and the rest of the methods just implement the mandatory interface required for a TableModel

class MyTableModel extends AbstractTableModel {

    private String[] columnNames = {"Name", "Date ...

    private Adult[] data;

    public myDataModel(Adult[] a) { // pass in data array to constructor
	data = a;
    }


    public int getColumnCount() {
        return columnNames.length;
    }

    public int getRowCount() {
        return data.length;
    }

    public String getColumnName(int col) {
        return columnNames[col];
    }

    public Object getValueAt(int row, int col) {
        Adult a = data[row];
        switch (col) {
           case 0: return a.getName();
           case 1: return a.getDate();
           ...

        }
    }

    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

}
jackiejoe commented: Very helpful individual, patient and knowledgeable +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, break the problem down into small pieces and fix them one at a time. I suggest you leave the whole GUI thing alone until the server and client code are working. Hard-code calls to the server & client code, and use System.out to see what's happening. When it all works properly, add in the user interface.
If your server code is entering the while loop then the connection HAS been made, so you're doing well. You still probably have the problem I described in my last post - so either get the client vto send something to the server, or simplify the server so it sends a response without waiting for the client to send something.
OK, it's now time for pre-dinner drinks here in France, so I'm going to sign off until tomorrow. Good luck, and remember - one thing at a time!

Ezzaral commented: A lot of patient help in this thread. +19
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

NO don't give up now! You're almost there!
The exception is caused because previous test runs failed to close the socket properly and so it looks like it's still in use next time you try to open it. For as quick and dirty fix change the socket address to 5001, and keep changing it each time you get this problem. Fix it properly when your code is working a bit better. DON'T GIVE UP.

jasimp commented: Good advice. You have been very helpful in this thread. +9
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, no other answers, so I'll have a go.
This is coding on wild side! You use refection to break into private methods that are not part of the public API. Even if you get this to work now, there's no guarantee that it won't break in the very next minor Java update. Seems dangerous to me.
Anyway, try it without the HKEY_LOCAL_MACHINE\\ in your key, I think that's already implied by systemRoot.
If you want a safer way to approach this, you can use ProcessBuilder to run the command line registry tool reg.exe, and stick to published public APIs. I can let you have some sample code if you want to try it.

verruckt24 commented: Good you mention about the private methods. +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster


for(i=0;i< String (1234455....upto >=500 digits);i++)

This is insane. Even with a 19 digit number (long precision), and running 1 million loops per second, it will take more than a hundred thousand years to complete. At about 24 digits it will take a time greater than the lifetime of the entire universe so far (13.5 billion years). What exactly do you really want to do here?

Ezzaral commented: So you think the expectation is unreasonable? :) +18
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This will work the way you want if you put your loop in a different thread from the Swing event thread. Replace your call mp.RandomAnimation (); in actionPerformed
with

new Thread(
  new Runnable() {
	public void run() {
		mp.RandomAnimation ();
	}
  }
).start();
VernonDozier commented: Perfect. +11
Ezzaral commented: Bingo. +18
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So when the button is pressed, have the code above execute, and have the above code call tryMaze? Then where do I put the timer and stuff?

Yes, just that, you don't need the timers etc, this should be sufficient (assuming I typed it ok!). Now, when your method does its sleep(...) the Java Swing thread will be able to run and process window updates.

Oops- I did miss-type, missed the line with the Thread! This should be better

new Thread(
  new Runnable() {
	public void run() {
		// call your tryMaze here
	}
  }
).start();
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What thread does your findNext run on? Is it on the Swing thread (started in reponse to a user input)?
Real-time UI updates like this typically fail because the "worker" code is running on the Swing thread and thus blocks Swings normal UI activity until it finishes. Sleeping doesn't help in this case because its the Swing thread that is slept. You need to run findNext in a "worker" thread so the Swing thread can update the UI when you sleep the worker.
If all this is new to you, read http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html

verruckt24 commented: Good one. +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The error is right here as i pointed out before, in the main method
""output = (aParser.doParse(output)); // do the evaluation""
output = (aParser.doParse(output)); // do the evaluation
that line

Type mismatch: cannot convert from int to String

Well. you didn't give us the exact line before (unless I missed it).
Problem is that doParse returns an int and you're trying to assign it to a String variable. Either change the return type to String, or change "output" to int, or convert like Ezzaral says.

notuserfriendly commented: thanks +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's ok as it is, unless you find some reason to change it. Obviously the following code changes to

height[0] = h1; // etc

and the toString method returns

"Age= " + age + " heights= " +height[0]  ..... ;
stephen84s commented: Helpful +6