7,116 Posted Topics
Re: Have you actually tried the first example? You may be surprised. | |
Re: BREAK appears to be a valid label [url]http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#78993[/url] and the break with a label also seems valid [url]http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#6842[/url] I just ran them thru Eclipse (Java 1.6u20) and they generated no errors, although the label does seem completely redundant in this case. What exactly was the error message and exactly which … | |
Re: 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 … | |
Re: It means what it says. addAll requires a parameter that is a Collection of Words, and you have passed a single String. | |
Re: Google the Java Event Dispatch Thread and read about Swing threads. Your repaint() calls won't do anything until your event method completes, even if it sleeps in the meantime.. | |
Re: 1. code tags 2. indentation. 3. full error message and line number | |
Re: Look at the suggested code. It's calling a method, passing a question, two answers, and a last param showing which answer is correct. You need to create the method with those 4 parameters so it shows the Q and the A's, gets the reply, and finally returns true or false … | |
Re: Try putting a few print staements to see if: the keylistener is being called the appropriate if test bocks are being executed the new vlue of y is correct the new value of y is being used in the paintPaddle method. My guess? paintPaddle isn't being called - you should … | |
Re: 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? [CODE] interface I<T extends Event> { T dosomething(T t); } class Event2 extends Event { public Event2(Object arg0, int arg1, Object arg2) { super(arg0, arg1, … | |
Re: 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. | |
Re: Walk thru your loop by hand looking at the values and the result of the while test. What happens when you reach the end of the array? | |
Re: 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 … | |
Re: [QUOTE=k2k;1196184]it was the variable type mismatch thing.. i m surprised that the compiler didn't catch it... still a bit confused but it is fixed. [/QUOTE] Thgere was nothing for the compiler to "catch". Your code is valid, but just didn't do what you wanted. The equals(Object) method is defined on … | |
Re: If there's a getHeight() method then there's probably a setHeight(int h) as well. | |
Re: That's probably as easy as it gets - provided that you created an 8x8 array of panels, and do all the processing in nested loops. | |
Re: 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. | |
Re: Use client properties. All swing components allow you to associate any number of values with any component. [url]http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JComponent.html#putClientProperty%28java.lang.Object,%20java.lang.Object%29[/url] | |
Re: showSchools or showUsers??? | |
Re: BJSJC: You're looking at sql.date. java.util.Date says Date() Allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond. | |
Re: What excatly do you want to achieve? It looks like you want the two threads to alternate (each method waits for the other method to execute exactly once before it runs, regardless of the threading) - in which case I don't think you'll get a much better solution than your … | |
Re: Suggest you remove the main(...) in MyArrayList in case you're running that one by mistake? | |
Re: [CODE]class MyClass { public MyClass() { // default constructor defined explicitly } public MyClass (int i) { // parametised constructor } }[/CODE] | |
Re: Read the API for Thread's constructor - your parameter should be an object that implements Runnable, which MergeSorter doesn't. | |
Re: Yes, Observer is the way to go. Java API uses it all the time - just look at all the "Listener" interfaces and methods in Swing for a start. You'll find loads of details and samples on the web. | |
Re: [QUOTE=dickersonka;737879][code] public boolean isEmply(){ if(top == -1){ return true; } else { return false; } } [/code] [/QUOTE] or even... [CODE]public boolean isEmpty { return top == -1; }[/CODE] | |
Re: 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. | |
Re: Looks like you should use index and value parameters to set the appropriate element of the projects array to the appropriate value, as in projects[index] = value; | |
Re: You have declared two text areas with the same name. | |
Re: I presume both pix are in the jar? Check the file name case - they are case-sensitive in jars but not in the windows file system. | |
Re: 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 … | |
Re: When your teacher said "introspection " the Java word is "Reflection", which you can Google if you want. Having said that, you do NOT want to use Reflection for this. What Ezzaral says is exactly right - use a HashMap<String><Player> | |
Re: You can redirect System.out to a PrintStream of your own choice, so you could redirect to a byte array output stream from which you can check everything. | |
Re: The File class is "An abstract representation of file and directory pathnames." (Java API ref). Just because you have an an abstract representation of a file name, that doesn't mean you necessarily have an actual file on disk. The actual file will appear when you open some kind of output … | |
Re: 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. | |
Re: 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. | |
Re: Here's the root of your problem: [CODE]class HeathProblem extends Patient [/CODE] A Health Problem is NOT a kind of patient. A health problem does not have a home address or a phone number! It's a thing that a patient an have zero or more of. So I would expect to … | |
Re: Somebody somewhere is going to have to loop thru the pixels to find differences. Are you sure it's too time consuming? If you haven't tried it, I would not jump to conclusions about performance. You'll simply be comparing two arrays of ints in a tiny loop - that's about as … | |
Re: The question seems ambiguous to me. Any Java interface can contain many methods. What this more probably refers to is illustrated in this example: You have an interface Vehicle that declares a void drive(int speed) method. class Car implements Vehicle { void drive.... etc so does class Speedboat implements Vehicle … | |
Re: [url]http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html[/url] (What an amazing thing Google is) | |
Re: I used the following standard solution: [CODE]ims = new MemoryImageSource(width,height, pixels, 0, width);[/CODE] (where the width/height vars define the image size and pixels is a simple int array of PixelGrabber-type data then: [CODE]Image im = Toolkit.getDefaultToolkit().createImage(ims);[/CODE] It seemed to me that this was fast enough to be be negligeable compared … | |
Re: All you would need to do is loop thru all the files in the dir, then, in that loop, read thru each file until either you match the text or reach EOF. What data structures would you need? | |
Re: This is a very common thing to want to do. You will have no problem finding example solutions on the web (if you look). | |
Re: I'm curious. Why return a String rather than the boolean? | |
Re: A few quick observations: Class names: should begin with a capital letter and shouldn't be plural when they represent a single instance of something. Eg use Account rather than accounts. An Account is not a kind of Customer, so it shouldn't extend that class. Do you need personName and companyName? … | |
Re: Easy. Just open a PrintStream to the .txt file and use print(...) to print the details and the lines one at a time. [url]http://java.sun.com/j2se/1.5.0/docs/api/java/io/PrintStream.html[/url] | |
Re: [QUOTE=BestJewSinceJC;1113793]To force a singleton I suppose you could simply use a getInstance method and refuse to return an instance if one already exists. I *think* you could enforce this by instantiating a private constructor [/QUOTE] Yes, that's the standard solution. The static getInstance method uses the private constructor to create … | |
Re: Switched from JBuilder to Eclipse a few years ago and never looked back. |
The End.