JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A quick question for mKorbel:
why three different PropertyChangeSupport objects, isn't the property name enough to distinguish the events? thanks.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

setForeground(someColor); works for me.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Use an instance of SimpleDateFormat to format a new Date()

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have you tried using a > to redirect the output messages from the compiler to a file where you can browse them all at your leisure?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

.class files are the compiled "executables" that can be executed by any Java Virtual Machion (like a .exe can be executed by an i86 machine). You package all the .class files for your application, along with any other resources it needs, into a "jar" - basically a zip file with a manifest file that describes its contents. If you have a JVM installed on your machine you can run the program in by simply double clicking the .jar file.
In Eclipse select your project, click "export..." from the File menu, then select Java/Runnable Jar File as the export type. You;ll get a wizard that collects the necessary info and creates the jar.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The main problem with shared variables is that when classA changes a value, classB doesn't know that it's changed. In your original code you had a loop that just kept re-reading the variable, but that's not something you can do in real life.

In real life you would chose one class to be the "owner" of the data. That class would have the variables private, and have public get/set methods for them.
When you instantiate the other classes you pass a ref to the "owner" class to they can call its get/set methods.
Finally, you implement a "listener" pattern in the owner class. This is just like all the event listeners in Swing - classB implements a callback method, and add itself as a listener to the owner class. As part of the set method, the owner class calls back all its listeners to let them know the new value.

Maybe that's all too much for this exercise, but if you are looking towards real-life techniques, I can supply more details and some useful code fragments.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi cOrRuPtG3n3t!x
Before taking out the loops and using thread join, and passing the values by return, it would be good to know what the point of this exercise is.
For example - maybe it's suppose to show the values being printed from the Display thread changing each time you enter new ones in the Logon thread. I'm not saying that is right - just saying that we don't know. But if that, or anything like it, is the case, then it calls for concurrent loops and shared variables rather than a return value.
Maybe the OP can clarify?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To square a number just multiply it by itself - eg 5 squared is 5*5

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"i want to..." Yes, I understand what you want. I'm telling you the answers
"when i did it.." Did what exactly?
"it says class,interface or enum expected? why this occur?" You have a syntax error - probably incorrect { or }

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Of course it does. That wasn't intended to be a complete statement. I was just posting some fragments of code you show you how to refer to a variable in another class.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To use instance variables from another class you need an instance of that class, eg

Point p = new Point(); // an instance of a point (x,y coordinates)
p.x // the x instance variable for Point p

To use static variables from another class you don't need an instance, just the class name, eg

Color.red // the public static variable red from the Color class
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's part of how Java works: every public class MUST be defined in a .java file whose name is the same as the name of the class. EG public class Poco MUST be defined in a file called Poco.java
"i declared them public isnt it enough??" No, it isn't. Check your lecture notes (or the web) for how to refer to another class's variables.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Aaarrgghh - just noticed the missing word in my post. What I should have said, of course, is Sorry, I have no expertise in java Audio

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

h and d are variables in the Poco class, so other classes can't just refer to them as h or d without any qualification. Check your lecture notes (or the web) for how to refer to another class's variables.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Those error messages contain valuable information that you aren't sharing with us.
What are the exact error messages and which line(s) do they refer to?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

By analogy with interfaces like Comparator, I would interpret this as follows:
Create a class (eg "BalanceFilter") that implements Filter, and in its accept(...) method only accepts accounts with balances > some arbitrary threshold value. Then in the DataSet class instantiate a BalanceFilter with threshold value of 1000, and use that instance to filter out the low-balance accounts.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry, I have expertise in java Audio - but at least you have a message now! ;)
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

On line 19 you have the colour for each circle. Now see if that is "red". You already have some hints on how to compare Strings.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

After you have filled your array of Circles you can loop through that array and use your getColour() method to get the colour of each Circle. Test if that is red, and increment a counter if it is.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
try {
  // your code that could cause an exception to be thrown
} catch (Exception e) { // catch any Exception that may be thrown
  // your code to display an error message
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just by you can type in a new message there's a "mark this thread solved" link - just click it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your class directory structure must exactly match your package structure. If you have no package spec then you should not have any directories for the class files, they should just be "loose" in the jar.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, now what is the package statement at the start of the source code for KortBord?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Can this possibly have anything to do with the package thingy?

Yes. Your class file has to be in a directory structure that exactly follows the package structure

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Can you print the contents of the manifest file and the jar and post the results here?
jar tf kort.jar

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When debugging never NEVER NEVER have an empty catch block! There are many reasons why the code in your try block may fail, and for most of them you will get an Exception that describes exactly what went wrong, and exactly where in the code.
change

catch (java.io.IOException z) //catching the IO exception
{ // Pretend it didn't happen. Ignore the error message. Discard the debug info
}

to

catch (Exception z) //catching any exception, checked or unchecked
{ 
   z.printStackTrace(); // display the error message and all debugging info.
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Two more things to check:
is the class file in a folder called "src" in the jar?
is all the capitalisation correct (file names in a jar are case-sensitive)?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, sorry, misunderstood what you initially said about remove. Nulling the last element after shifting down makes perfect sense if you don't allow null values.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your algorithm for add seems equivalent to just maintaining a size, unless the definition of your implementation allows null values to be added (like java.util.ArrayList does).
The algorithm for remove is valid, but could be really expensive if you have to create a new array and copy all the contents every time. Much slicker to null out the extra element ( or size-- )

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is the OP's code, so he can do what he wants, but the "normal" implementation is that "size" refers to the current contents (number of added objects - number of removed objects). So initially the capacity is 1024 (length of the backing array), but the size is 0 (the array list contains zero objects). Add an object and the size becomes 1 and the capacity remains 1024. Add another 1023 objects and the size becomes 1024. Add yet one more object and the size becomes 1025, but internally the array will have been resized and the capacity will be some larger value, eg 2048.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In a classic array list (eg java.util.ArrayList) you have a size which is the number of objects actually stored in the list at any time (initial value 0), and a capacity, which is the length of the private array that's used to hold the list (initial value is an arbitrary "big enough"). Capacity only increases when the array overflows (size > capacity) and you have to allocate a new bigger one.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's called teamwork. :)

ps Torf: While we're at it, if (x == 1) It's always dangerous to rely on an exact equals with a floating-point value. You can never be certain that x isn't 0.99999999999 after a calculation whose exact result should be 1.0. It's particularly dangerous in this case because you are relying on it to terminate a recursive algorithm. Far far safer to code that as if (x <= 1)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you want to use classes like JOptionPane from the javax.swing package then either
1. Use its fully qualified name javax.swing.JOptionPane or
2. import the class (or package) at the beginning of your program so you can use the class name without qualification

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

^ that's right. I've done quite a lot of that to provide remote interfaces to what would otherwize be just local Swing applications. You can simply write an HTML file like you would write any other text file, taking care with Java escape chars.
What's a bit more interesting is how are you going to get that HTML served up - you;ll be working with some kind of web server, or you can do it all in native Java with a Socket listening for and responding to HTML requests (Java SE) or use the inbuilt classes in Java EE.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are responding to keyPressed, which happens when the user presses a key (duh!). But the input to the text field doesn't happen until the key is released and a valid character has been typed - so that's why you don't see the latest char in the getText. (Ps Even worse if it's (eg) an upper case character, because you'll get keyPressed events for the shift key AND the letter key before the text field is updated.)
Much better to implement your method in keyTyped, which is triggered when a character has been typed, and which automatically handles things like the shift key or alt-gr.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {  
   while (...
     ...
     Thread.sleep(...

You simply can't do that in Swing, or rather you can, but it doesn't work.
Everything to do with Swing (eg painting the screen, running actionPerformed methods) happens on a single thread - the "Event Dispatch Thread", or "EDT", or "Swing thread".
That means that once your actionPerformed method starts NOTHING else will happen in Swing, including no screen updates, until your method finishes. You can update stuff and loop and sleep as much as you like, but none of that will affect what's on the screen until your method has terminated.
If you want to do stuff in steps over a period of time the this is the right way:
In your actionPerformed start a javax.swing.Timer, and return. Every time the timer fires you can update whatever needs updating and return. Inbetween the timer firings Swing will be free to update the screen.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Adding to a file in a jar is a more complex problem. Would it make sense to hold an initial/default list in the jar, but put each user's additions into a separate file in the user's home dir?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You would normally use the classloader's getResourceAsStream method - which has the advantage of immediately giving you an open InputStream on the file in the current jar. You'll find the doc in the usual places, but briefly:
in the code of a class that was loaded from the same jar...

InputStream in = this.getClass().getResourceAsStream("/myTextFile.txt");

If the file is in a folder within the jar then that would be "/myDirectory/myTextFile.txt" When developing your code this also works outside a jar - as long as the file is in the same place relative to where the .class file was loaded from.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi Norm.
Watch out for this OP - already in trouble with Peter Budo for not showing any effort, and is starting to troll other people's posts. J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Around lines 60 and 228 the initialisation loops stop one short, and leave the last element of each array null.

for(int i=0; i < 12; i++) { // initialises the first 12 elements of 13
   rankArray[i] = new Rank(i);
for(int i=0; i < 3; i++) {        // initialises the first 3 elements of 4
  suitArray[i] = new Suit(i);

I think stultuske was wrong in this individual case. The problem is not that you were accessing non-existant array elements, it's just that you failed to inialise them all earlier.
With 13 ranks and 4 suits your loops should all look like these:

for (int rank=0; rank < 13; rank++) ...
for (int suit=0; suit < 4; suit++) ...
Goldfinch commented: Your solution worked beautifully +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You just need to cast the Object that's returned. String isn't a primitive so there's no boxing involved
String s = (String) btn.getClientProperty ("myString");

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Methods declared in an interface are automatically public and abstract, so the method definition in the class that implements must be declared public, as default access is more restricted

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry, I don't know why manually setting the size would have that effect :(
The invalidate() calls should force the layout manager to re-do the layout, and the buttons should get a size from the images, so I think you just hit the limits of my knowledge in this particular direction. :(:(
Maybe one of the smarter people here can shed some light on this... please?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There is no one answer to that. Every bank has its own savings accounts with different conditions and limits.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I can confirm that its possible to add buttons to a visible panel.
You could try invalidate() on the JFrame after calling it for the panel.
Java's understanding of paths may not exactly match yours, so I would still take 30 secs to use the file exists test to be absolutely certain...
(new File(path)).exists()

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You may need to let the layout manager know that you need it to update the layout after you have added the buttons - try calling invalidate() on your panel after adding the buttons.
The other thing is that icons on jLables and jButtons are notorious because if there is any problem with the icon file name/path etc you get no errors or exceptions, you just get a blank label/button.
Use the exists() method of the File class with the path/name of the file to confirm that your program can find eachfile.

Skeldave commented: Very helpful person +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Math.power ends up in a native method to do the actual calculation, so its a reasonable bet that's its very efficient indeed. Either way. memory really doesn't come into it.
Unless your idea of "a lot" runs into millions in this case, I wouldn't waste another millisec worrying about speed or memory for Math,power.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To be honest, I'm no expert on SAX, but I#m having a quiet afternoon, and nobody else is answering, so...

I found a number of notes like this one re SAX:

The characters method can be called multiple times for a single tag, and you have to collect the characters across the multiple calls rather than expecting them all to arrive at once.

You code seems to assume a single callback, because it resets the bgenomeSequence flag on the first callback. I think you should only reset bgenomeSequence when you get the corresponding endElement call, and allow for multiple characters callbacks inbetween.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Does it continue after the quer : or is that the end of the output? Is it possible that it's just running in Order(n^2) or worse time, and it will work eventually?

Arrays and String etc in Java are limited by the VM memory size - but if you were running out of memory you should get an Exception.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What do lines 51/52 really look like?
".. results nothing as an output" Nothing as in "", or null, or absolutely nothing happens (in which case is the CPU busy or idle)?