JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If all your instance variables are simple, you don't need to do anything, just code the class as "implements Serializable" and the default mechanism will handle it all

BestJewSinceJC commented: plus rep for the help to hazard +4
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, ignore that previous link, here's a MUCH better current version
http://java.sun.com/docs/books/tutorial/uiswing/dnd/dataflavor.html
it's part of the full tutorial on D&D but gives detailed instructions on how to make your class as transferable. It looks like that will then do what you want.

HazardTW commented: Very very helpful!!!! +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Take a look at the InetAddress class. You can use it to parse your text into an internal-form inet address
InetAddress.getByName("10.4.23.16")
then extract it as a byte array
byte[] bytes = InetAddress.getByName("10.4.23.16").getAddress();
It will then be easy to write the comparator using those four numeric bytes (four nested tests OR bit-shift them into a single int and compare that).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... aha! Maybe this explains it:
I just looked up some old code of mine that gets the Object behind a selected JList, and here's the relevant line:

list.getModel().getElementAt(i);

Using this approach to get the Object from the default model definitely returns the original Object, not its String representation.
Hazard: get your data object this way and forget about parsing display Strings!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Generally a very bad idea to build a dependency where a data class is dependent on a particular visual representation. Suppose your next project is to display the same info in HTML? Its normal for a GUI class to depend on the underlying data model, but not v.v.
Personally I see nothing wrong in extending a Swing component to make something customised for display or manipulation of a particular data type, but in that case I would subclass JButton in a new GUI class and have the associated Job as an instance variable, passed into the constructor.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe it's this:
The arg should be a [][] array - which is what the variable args contains.
The invoke method requires an array that contains all the parameters for the method being invoked. The init method has 1 parameter, so the invoke method should pass an array of 1 element, which, in turn, should be your [][] array args. Ie, you need to enclose your [][] args parameter in a new 1 element array.

devnar commented: Thanks, dude. +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'll do it for you. $50/hour, OK?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Does this seem like bad use of the name property of the JButton objects?

Yup, that's not good.
There is a proper way to associate a arbitrary values (eg month number) with a swing component. See these methods in JComponent:
putClientProperty(java.lang.Object, java.lang.Object)
Object getClientProperty(Object key)
eg

buttonJan.putClientProperty("month number", new Integer(1));

int n = (Integer) selectedButton.getClientProperty("month number");
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What do you know about the integers in the data? If they are uniformly distributed within a known range, I think I can suggest a way to get a very significantly faster result...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You may have a real problem here. I don't think you will find anything faster than a simple array of ints. I tried a quick test, and found execution time ~ 1 sec at 1/100 of your data size, ~1 min at 1/10. I didn't try the full size array, but I'd guess ~1 hour.
You could presumably halve this by multi-theading it and using >1 core, but that's not going to give you an order of magnitude improvement.

final int SIZE = 2100  /* 000 */ ;
int[] big = new int[SIZE];

long count = 0;
for (int i = 0 ; i < SIZE; i++) {
	int temp = big[i];
	for (int j=i+1 ; j< SIZE ; j++) {
		if (temp == big[j]) count++;
	}
}
System.out.println(count);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

con isn't initialised.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you rhink anyone will study nearly 200 lines of code and data, mostly unformatted and unindented, to find an unspecified error, which may possibly be in a part of the code that you have not posted, you are a great optimist.
Re-post, with all the code in code tags, and tell us what the exact text of the exception is (including the class/method/line number) and you may do better.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

String with a capital S. It's the name of a class - they always begin with a capital. Seems very unlikely that the compiler would change the capitalisation on its own! Duplicate file versions perhaps???

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

MxDev: I guess English isn't your first language? The verb "demand" is the wrong word to use in this situation, and appears to be very rude. Eg, a master would "demand" something from his servant.
"manners" are the rules of good/polite behaviour.
If you said "can someone please tell me the correct order..." that would be OK.
To answer your question, I think you should start with OO A&D, which will include learning UML because that's the language of OO analysis & design. Then move on to a few Design Patterns. Don't attempt to learn a whole book-full of patterns; these are things you look up when you need them

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The "break" on line 16 is outside any catch, so it terminates the list of catches associated with the previous try. So the catch on line 18 hasn't got a try to match to.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A default constructor is one that takes no parameters and sets the initial values for the class.

Not exactly. Constructors can have arguments, or no arguments. If you do not create any constructors, the compiler gives you a "default" constructor which is a no-args constructor that simply calls the superclasses' no-args constructor.
Any constructor that you define explicitly is, by definition, not a "default constructor".

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

kvprajapati commented: Great explanation +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... I don't know how substring reacts if the end index is smaller than the start index..

API doc states:

Throws: IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's annoying, but you can't use a primitive type (int/char/boolean etc) with generics.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

quuba's suggestion is OK, it will work, but it ties the external representation of the button text to the internal functions of the code, which is not ideal as a programming technique. (What happens when you do the Japanese version?)
If you want to do this the "professional" way, all JComponents support a "Client Property" collection where you can store anything you want as a property if the component:

seats[i].putClientProperty("index", new Integer(i));
...
public void actionPerformed(ActionEvent ae){
JButton theButton = (JButton) ae.getSource();
int index = (Integer) theButton.getClientProperty("index");

What's so good about this is that you can have any number of properties, and they can be strings, URLs, Files, anything that you want to associate with the button.

javaAddict commented: It's good to learn new things +4
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Move the declaration of au outside the action performed method, because now it exists only within that method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

FYI:
"Boolean.TRUE" is valid Java, but "true" is also valid, and what most people would write.
This code also makes the very common mistake of redundantly using an if test to set a boolean. So it could be written

@Override
 public boolean equals(Person inPerson) {
   return  name.equals( inPerson.getName() ) &&  ssn.equals( inPerson.getSsn() );
 } // end of equals method
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How about uisng skip(<length of file> - 32) then reading 32 bytes?
ps for reading binary data you should consider FileInputStream rather than FileReader, which is optimised for characters in some defuakt character encoding.

fareast87 commented: simple but great! +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Because you have imported the packages, you can just call any of the public methods in those packages. Try it!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Are you sure you want to close you input stream every time you read a line from it?

Flanderbland commented: It worked! +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have you tried setHeaderValue("..."); on your new TableColumn?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

line 4 looks the wrong way round - java syntax is
variable = formula; You have formula = variable;

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

PoNoN1=N1+"(POSITIVE)";

You declared PoNoN1 as int, but you probably wanted String.

ps: Java convention is the start all variable names with a lower case letter.

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

Looks good to me. If it gives the right answers, thats OK.

shroomiin commented: thanks for helping a beginner +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Main class defines getter for these Strings:
public String getDefaultFileLocation() { return defaultLocn; }

Main class instatiates an instance of a subclass, passing itself as a parameter:
SubClass sub = new SubClass(this);

SubClass keeps a copy in the constructor:
public SubClass(MainClass main) {
this.main = main);
}

SubClass methods can then query the Strngs from main:
File f = new File(main.getDefaultFileLocation());

KirkPatrick commented: I appreciate your willingness to help bud, thank you +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why the lengthy switch rather than something like

result = "023456789ABCDEF".charAt(remainder) + result;

javaAddict commented: Ha, that was funny. Not to mention that he posted his code twice +9
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... and your question is?

majestic0110 commented: Good question! +5
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There might be a flaw in that strategy, but none that I can think of off the top of my head. If so, someone will be sure to tear it apart though.

No, that's exactly the right strategy. Just needs to be re-cast into formal Java code.

balumohan2 commented: hi please reply for my doubt +0
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

With multiple frames it's usually a good idea to have a separate controller class (instance) that has methods for opening frames, hiding frames, switching between frames etc. If that class creates and opens the frames it will have references to them that it can use for setting their visibility etc. If you pass the controller instance to each frame when it's created (as a parameter to the frame's constructor) then the frames can call the appropriate methods in the controller when buttons are pressed etc.

Ezzaral commented: Agreed +25
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

Separate class for the graph is OK.
This code
f.getContentPane().add(new ChartPanel(values, names, "Principle/Interest"));
is where you call your class to create the graph. You call it twice, and it looks like you only have data set up for the second call?
I suggest you add a some temporary print statements to the constructor of your graph class to display the values of the parameters that are passed. That way you can see if the problem is in the graph class, or in the way it's being called.

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

Despite previous post, arrays can also contain objects (depending on how they are declared) Object[] x = new Object[];.
arrays are a fixed-size list of members). They not have methods etc. All you can do is refer tp individual elements.

ArrayList is a Class. Instances of ArrayList can contain all kinds of objects (depending on how they are declared). They have a good number of public methods for adding/retrieving/removing elements, and are generally a lot more powerful than arrays. In particular they re-size automatically to fit whatever number of elements you put in them, and "close up the gap" when you remove elements from the middle. Vector is almost the same, but has the additional advantage of being synchronised, so they are much safer to use in multi-threaded programs.

harsh2327 commented: Thanks for pointing out my mistake +2
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

... I don't think that a get() is duplicate of valueOf. valueOf method return enum type and it throws an IllegalArgumentException, if the specified enum type has no constant with the specified name, or the specified class object does not represent an enum type.

Yes, I agree. Thanks for pointing that out. I'd fallen into the trap of confusing the enum values with the Colors themselves.

titosd: adatapost's solution really is better than mine, especially if the list of valid colors isn't going to change.

kvprajapati commented: There is no distance! +10
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

It says you are trying to add a String to an ArrayList of OneRow objects. You an only add a OneRow or a Collection of OneRows

KirkPatrick commented: browsing through some old posts and wanted to say thank you again for being helpful and patient +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Using "array[number]" you're refer to 1 single element in array , which has a position number-1 (since the array indexes are starting from 0).

I think this is a typo. Element [n] is in position n+1, not n-1.
ie Element [0] is in the first position, [1] is in the second position etc

Antenka commented: oh .. yeah .. thanks .. my bad :$ +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

writeObjectOverride: being protected shouldn't stop you overriding it. What errors do you get?

Have you looked at Externalizable? http://java.sun.com/j2se/1.3/docs/api/java/io/Externalizable.html looks like it may be what you are looking for?

Finally - so the default serialization writes a k or two of extra data. Is this really a problem, or just an itch you can't scratch? (ps: even a single int gets padded into a 1024 bye block)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I can't see the close in your posted code, but it sounds like that needs to be moved out of the loop as well.
As for leaving 1 copy - well, yes, maybe. But the open/close within the loop is definitely wrong, so fix that first & see what happens.
Maybe its writing a blank/empty line in its last pass???

KirkPatrick commented: Thank you, I'll keep this in mind for future use. Your help is much appreciated once again +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

n[] is new array, has nothing in it. So n has nothing in it for all values of i, so n.someFunction tries to call someFunction on a null value -> Exception.
Maybe initialise n to new Student1() before using it?

akulkarni commented: excellent for a newbie like me +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your ternary expr is almost there, just needs (1) brackets to get the order of evaluation right and (2) it has to be used in an assignment kind of way

for (j = y1 ; j != y2; j = j + ((y1 < y2) ? 1 : -1))

VernonDozier commented: I was playing around with that ternary operator earlier. I got close, but not quite. This makes sense now. +18
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's really no need for you to shout & scream like that. The only code you posted was a few loops and prints that didn't work anyway (in fact that's why you asked for help). You never posted a working version that would be useful to anyone else.
I'm sorry my help was not useful to you, if you had let me know I could have saved quite a bit of time. Goodbye.

VernonDozier commented: Well stated. +17