JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry (how do I delete a post?)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Nobody is going to try to check this code until you indent it properly - it's just too hard to match up the {}.
And please tell us what the exact error message is, this isn't a quiz.
And class Items should be called Item - each instance represents exactlyy one item, not multiple items.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1. Create a class Person with name, phone etc and the associated accessors and validation.
2. Create a class PhoneBook that contains a Collection of Persons, with methods to search / add a new Person etc
3. Create a class Test with a public main(...) method to create some Pesons, add them to an instance of PhoneBook, test the searches.
4. Never, repeat never, post code without code tags.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

a is a divisor of b iff (b%a == 0)
I have no idea how (or why) you would do this recursively - you just need a loop to try all values of a from 1 to sqrt(b)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you import the movie (ps should be Movie) class in the second .java file?

Update: parallel post with javaAddict - he's right!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have a look at the methods that JButton inherits, such as setHorizontalAlignment(...)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So there's nothing wrong with your method.
When you call a method that says it "throws IllegalValue", the calling method must either catch that exception or declare that it too will throw it up to whatever called it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is the error message referring to this method's code or the method that calls it?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You should assume that all API methods are not thread safe unless the javadoc explicitly says they are. (Although in this particular case it's difficult to see what thread problems there could possibly be - the method has no side effects and doesn't update anything.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OKI. I have to go out now, so I'll be offline until tomorrow, but good luck anyway!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't understand what you are really doing with the calculation of two means then averaging them in that convergent loop, so I'm not in a good position to re-design your code. But... at a guess...
if a contains the number of pixels with value i, then the weighted average value of i is something like
sum(a * i) / sum(a)
at least this should give an answer in the range 0-255

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

My threshold is 264 on one of my test images, and 734 on another, and I have no idea how or why this is happening.

See my last post - the calculation of the means is wrong.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The values in hist can get arbitrarily large, based on the size of the image, so m1 and m2 can get arbitrarily large, so tnew and thus threashold ditto, thus array index error when threashold is upper bound of loop.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Suggests threashold has got > 255 - tho I can't see how (especially with the wrong value of count being used to divide m2). Try printing it to confirm?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Which line generates the array index exception?

ps: line 22 should read <= 255
(althought new int arrays are initialised to all zeros anyway)

pps Shouldn't you re-initialise count around line 42?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have you actually tried the first example? You may be surprised.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Check the API. setMargin doesn't take 2 ints, it takes an Insets instance.

http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/AbstractButton.html#setMargin%28java.awt.Insets%29

If you get a "no method..." error you should always check the API first.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The original Java AWT design was prett limited, so Swing was introduced with a far better architecture (and loads of other small improvements while they were at it).

So what's ReadyTo Program? I thought you were just using those words as simple English, sorry.

The SetMargin method overrides the insets, but I find it's hard to get the button default graqphics out of the way, so I always use JLabels to display graphics, you just have to listen for MouseClicked instead of ActionPerformed.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You don't say what the problem is, exactly, but you are mixing old-style AWT classes (eg Panel) with Swing classes (eg JButton). This is always dodgy. You should replace all the AWT ? classes with the swing J? equivalent.
Your buttons should resize to fit the image when you pack the window, although you will probably have to override the default insets to avoid blank space around the icon.
What do you know about Java 1.7.1 that we don't? 1.7 isn't out yet. (Current is 1.6u20).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I wonder what your (former) employers would have to say about you taking all the code you wrote for them and storing it for future use in other projects they're not getting paid for.

Leaving aside the exact legal nicities for the moment, all I can say is that in the >40 years since I started earning my living as a programmer it's never once come up as a problem.
Obviously I woudn't be able to re-use proprietary or trade secret algorithms etc, but the kind of code I'm talking about is generic . I also have been maybe lucky in that all my employers (except, obviously, the very first) and contracts have been smart enough to see that they gain more than they lose in terms of my productivity.
On the other hand, I've never worked for a firm of copyright lawyers, fortunately.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

. Unless you are exceptionally good at organization, keeping every code you write is going to take longer as far as reusability than rewriting certain things will.

Yes, well, maybe every was a bit heavy!
I always think about whether code I'm about to write has any potential for re-use and, if it seems possible, I write it as a library class for reuse. Over the years I've accumulated a real treasure-chest of useful code which, even if it's not exactly what I need, can often be extended (and thus the extensions saved for future re-use).
I'm a major fan of code reuse.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'd like to help more, but jwenting is right...
"the instance variable refuses to work" and
"I changed it and I'm still getting the same error"
just isn't enough info to work with.
Think about it: all you have told us that a changed version of the code (ie one we have no access to) has an instance variable that refuses to work. I can promise you that Java instance variables always work exactly as the language definition says they should, so presumably you mean "didn't do what I expected", but what was the unexpected behaviour?
We need exact error messages and line numbers and the exact version of the corresponding code please. If there's no error message we need to know exactly what you expected to happen, and exactly what actually happened.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The superclass is Bird, which doesn't have a constructor that just takes a name as the only parameter. (it's public Bird(String aName, String aBreed))

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I agree with the previous posters. Don't learn the API, learn to use the API JavaDoc and Google to find what you need when you need it. As you build up experience you'll get to know the most common APIs, and you'll be able to copy/paste from things you have already written and debugged for many more (so never throw away any working code you've written).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Variables are not static unless you declare them as "static". However, in this case the variable is (correctly) a public instance member, so you can refer to it from main via the instance (just like you call methods on the instance like marr.insert()) as marr.count1

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your print is in the merge method, which gets called repeatedly during the sort, so you get repeated prints.
You need to move the count variable out of the method so it retains its value from one call to the next, and print it only when the sort has finished.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I can't give you all the details, but in short: "yes".

When you package your app into a .jar file you can also put any truetype fonts you need in the same jar (subject to copyright etc, of course). You then read the font file and create the font in your app with something like:

InputStream in = getClass().getResourceAsStream("myTruetypeFont.ttf");
Font myTruetypeFont= Font.createFont(Font.TRUETYPE_FONT, in);
in.close();

Hope this helps. Good luck!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If there's a getHeight() method then there's probably a setHeight(int h) as well.

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

I see no-one has replied to this (wonder why???), so I'll have a go.
Is the following the kind of thing you are looking for?

interface I<T extends Event> {
      T dosomething(T t);
   }
   
   class Event2 extends Event {

      public Event2(Object arg0, int arg1, Object arg2) {
         super(arg0, arg1, arg2);
      }
   }
   
   class C<T extends Event> extends PriorityQueue implements I<T> {

      @Override
      public T dosomething(Event t) {
         // TODO Auto-generated method stub
         return null;
      }
      
   }
    void test() {
       I<Event2> c = new C<Event2>();
       c.dosomething(new Event2(null, 0, null));
    }
kvprajapati commented: Helpful! +9
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The capitalisation was Iterator() vs iterator().
Comparable isn't too hard. For a quick start, you could just return the result of comparing the CrewMember's names (the String class implements Comparable already).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1. Check your capitalisation! Java is case sensitive.
2. To make the sort meaningful your CrewMewmber class needs to implement Comparable, otherwize there's no way to know what the correct sort order for CrewMembers is.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's often done that way, but ideally the constructor should also use the set() methods to store the parameter values, thus ensuring that any side effects are properly handled.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have declared two text areas with the same name.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The point about using the hashtable is that the synched method to add/retrieve the directory-specific lock object from the hashtable will take microseconds (the hashtable is only locked for the time it takes to check/update the hashtable then it is released), and there will be zero unnecessary locking of the FTP activities. The hashtable itself will not be locked during an FTP operation.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you have a variable representing the FTP server for any given operation, maybe you could synchronize the dir-making stuff on that object, thus only causing a thread wait when it really is necessary?
Or
Perhaps you could have a small class that just manages lock objects based on the fully-qualified directory name
public static synchronized Object getLockFor Directory(String directoryName)
{ have a hashmap<String><Object> of dir names and lock objects
return existing or new object as appropriate }

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, OK. You didn't show the code where you changed from 0.06 to 1.06, so I didn't know that you had done that!
Mark as solved now?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Add the Cards to the window, use a layeredpane to stack them and get the overlapping right
http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html
and position them absolutely
http://java.sun.com/docs/books/tutorial/uiswing/layout/none.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I've been gtrying to understand your code - which is quite weird.
Card extends JPanel, but you don't seem to add a Card to any visible container. Card just looks like a holder for the paint(...) method that you invoke from somewhere else to paint the card into a JPanel in the main window. It seems to me that the main window has card images drawn in it, but doesn't actually contain any Card objects. In which case no listeners will ever be called for a Card.
Maybe I have this all wrong, in which case I'm sorry and please ignore this.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do any of the other mouse methods get called? The API doc says

Due to platform-dependent Drag&Drop implementations, MOUSE_DRAGGED events may not be delivered during a native Drag&Drop operation.

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/MouseMotionListener.html#mouseDragged%28java.awt.event.MouseEvent%29

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 1 still not quite right - a raise in normally in addition to the current salary!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, had another look, try this idea for size:
Your listener class extends Card, but you add a new instance of that class as you listening instance. Althiough you call super.etc in that class, it doesn't extend any actual instance of a card, so that does nothing.
Perhaps you should move your mouse methods into the Card class, then change the constructor to
addMouseMotionListener(this);

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You should create a variable just to use as a synch object then if two pieces of code should not run concurrently, explicity synch them on that same variable. If there are two different situations where that applies you can have two variables (etc). Avoid having to synch on two variables simultaneously (avoids deadlocks). Keep it simple, keep it explicit. eg

Object dirLock = new Object(); // just for synching
...
synchronized(dirLock) {
   // mkdir code
}
...
synchronized(dirLock) {
   // chdir code
}

just don't call either fo these pieces of code from within the other!

musthafa.aj commented: clear +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Looks like raise is intended to be a % value, so you shouldn't just add that to the salary - you're only adding 1.5 to 6 cents in your current code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

MouseListener is a interface in the Java API, so it's not a good name to use for yours. It's worth changing it, just in case.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I agree. It's been fun, hasn't it?
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

@musthafa: OK, sorry. I';m afraid you're going to have to debug this one yourself - I have no free tine at the moment. Good luck.
@clawsy: I think that trying to decide PNG vs incremental RLE on the fly will be very difficult. I was suggesting that it may be good to use the PNG ImageIO method just for the initial image.That needs no transparency etc, and will give the starting Image and buffers that the incremental method can then continue with.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I just had a quick look... can't see where you start the delegate thread in the server!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I have that code incorporated into a much larger application, so it's not in the demo that I built earlier. However, the mouse/keyboard listeners are absolutely straightforward, as is the server thread. You should be able to do those yourself without my help!
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

sorry james can you send the solution with mouse event....

#O already did. It's the first code sample in post #92
Those are the methods for the mouse and keyboard listeners.

kvprajapati commented: Good stuff! James. +7