7,116 Posted Topics
Re: Did you [ICODE] import java.util.Calendar;[/ICODE] ? | |
Re: If it's redlined the import then Eclipse can't find that class - check your classpaths and project settings to ensure the class is findable. The "cannot be resolved" error follows on from this one. | |
Re: You can't do a switch on a char array. The Language Refeence says: The type of the Expression must be char, byte, short, int, Character, Byte, Short, Integer, or an enum type. THere was a recent thread here about doing a switch on String values - look it up. ps: … | |
Re: Make each screen an independent JPanel and use a common "data" object to hold all the values that are displayed or entered via the panels. The panels use the data objects get methods to retrieve the info to display in their constructors, and the set methods to update the object … | |
Re: Your int DAY_OF_WEEK is just the "code" value used in Calendar to refer to the day-of-week field. You then need to get that particular field from your Calendar using the get(int field) method. ps: using a switch like that will work, but it's a pretty horrible way to do it. … | |
Re: [QUOTE=NP-complete;1232739]a Every class implements those two anyway. [/QUOTE] Sorry, but that's wrong. Object, for a start, implements neither. Although many popular classes implement either or both, there are many important classes that don't. | |
![]() | Re: 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) ![]() |
Re: 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, … | |
Re: I don't have time to spell this out right now, but here's the short version. You need to create your own change Listener - just like the slider defines an interface and allows you to add listeners with that interface, and calls ithem when the slider changes - you do … | |
Re: The "final" keyword is essential here. The compiler knows that the value assigned to the variable can not be changed, so its value can be used in the inner class even after the method has terminated. | |
Re: "Proper" way: Use the GregorianCalendar class (and the methods it inherits from Calendar) to get the year/month/day/hour/minute as required so you can test for equality at whatever level of precision you need. "Quick & dirty" way: get the time in millisecs for each date, subtract one from the other and … | |
Re: Exactly what error message do you get on exactly which line? Also: you carefully test for temp == null just before attempting temp.info - null pointer perhaps? | |
Re: You would typically have mutliple JFrames and chain from one to the other, BUT not pass all the info down the chain. Use the MVC pattern and keep all the info in a "model" class (or classes) that the GUI can call via standard get(...)/set(...) or add(...) methods. Each piece … | |
Re: jwenting is right, and you are wrong about not being able to use it in your dialogbox. But anyway, you can check if something is null like this: [CODE]if (resultset == null) { System.out.println("No records found"); } else { // do whatever it is you wanted to do with the … | |
Re: Looks like you have an extra dot between import and java. "Identifier means a name, such as java.text or String, or i "Identifier expected" means you have some piece of punctuation such as ;{(. etc where you should have an identifier. | |
Re: Just put them in a new class : [CODE]public class Serialiser { public static byte[] serializeObj(Object obj) // etc [/CODE] then call them from any other class like this: [CODE] byte[] bytes = Serialiser.serialiseObj(myObject);[/CODE] | |
Re: Use the ProcessBuilder class to run the (free) XXMKLINK program? | |
Re: Did you import the movie (ps should be Movie) class in the second .java file? Update: parallel post with javaAddict - he's right! | |
Re: [QUOTE=lich;1226799]can you please provide me a sample code. about the timer and the timer runs out[/QUOTE] There's lots of examples on the web. Why do you think someone should write a new one just for you? Google is your friend. | |
Re: I guess you've seen this? [url]http://code.google.com/apis/maps/documentation/mapsdata/developers_guide_java.html[/url] | |
Re: Have a look at the methods that JButton inherits, such as setHorizontalAlignment(...) | |
Re: Is the error message referring to this method's code or the method that calls it? | |
Re: You create a new instance with something like: Circle c = new Circle(2.0); | |
Re: Sorry guys - I may be a bit geriatric but I don't need 1/2 inch high lettering just to compensate for the garish colours. And please reinstate the poster's reputation and solved thread count info on posts - it's the only easy way to see whether that person knows what … | |
Re: When reading files from a jar the file name is case-sensitive, "sentence" != "Sentence". You could double check that. | |
Re: 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 … | |
Re: Yoiu may find these useful: [url]http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html#getPackage%28%29[/url] [url]http://www.javaworld.com/javaworld/javatips/jw-javatip113.html[/url] | |
Re: Your processWindowEvents won't be called because you have not enabled window events nor registered a listener. See: [url]http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Window.html#processWindowEvent%28java.awt.event.WindowEvent%29[/url] | |
Re: Every java program needs a "main" method. Where's yours? | |
Re: [QUOTE=moutanna;1215788]This is olso wrong: [CODE] SecurityAlarm[] alarm = (new FireAlarm("kitchen", 120.0), new EntryAlarm("rear entrance",10), new COAlarm("furnace room", 130) ); [/CODE] the is no constructur in the SecurityAlarm superclass. Hope it helps.[/QUOTE] moutanna: why do you think the SecurityAlarm class needs an explicit constructor? | |
Re: Before asking here you could have looked up "Creation of New Class Instances" in the Java Language Specification. | |
Re: In principal: yes, although the absence/presence of a "throws" declaration in the method signatures determines whether the Exception is propogated. | |
Re: Instead of the tortuous [CODE] return Double.longBitsToDouble(0x7ff8000000000000L); //0x7ff8000000000000L is the Java constant for NaN (Not-a-Number[/CODE]) why not use the simple and clear [CODE]return Double.NaN;[/CODE] | |
Re: You are heading in a decent enough direction (there's too much code (eg collection of student names) in main that should be in the Grades class, but don't worry about that yet) - have you tried executing your code? There's enough here to try a run and (probably) generate some … | |
Re: 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)) | |
Re: Line 12 you are looking for a String "Song 1" in the ArrayList, but the ArrayList contains Track objects. (Ditto line 7 of final code). ps Java 1.5 enhanced for-each loop: [CODE]int i = 0; while (i < tracks.size()) { if (tracks.get(i).getRating() == Track.MAXIMUM_RATING) maxRatingTracks.add(tracks.get(i)); i++; }[/CODE] becomes: [CODE] for … | |
Re: Use a LinkedBlockingQueue for the server - you'll find examples on the web. | |
![]() | Re: Without access to the source of that class (see above) you can still just try coding a for-each on it and see if it compiles! |
Re: 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.) | |
Re: You could try Googling "type object pattern". I did, and got a load of hits (of which the fifth was this very thread!). | |
Re: 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? | |
Re: The setText method replaces any existing text, so you only see the result of your very last setText. Try append(...) instead. | |
![]() | Re: Interesting conversation, may I join in please? BJSJC: your statement about "only one thread" in posts #4 and #6 is wrong, there's also the EDT, as you note later. moutanna's post #7 is very misleading. The listener method is NOT called "inside the button"; the method is running on the … |
Re: You could use instanceOf to see which subclass each Question is, then cast the Question to that subclass. after which you can access the subclass methods | |
Re: Maybe bad naming? safeOpen seems to mean safeLocked in some of the methods, but is used redundantly for the inherited open variable in others. (And the unlock method needs to check the combination before unlocking.) | |
Re: You often get "stream corrupted" during debugging when a previous test crashes part way thru and the socket/stream is left open and part-written or part-read. It's worth checking that there are no instances of the JVM still running from failed tests before starting the next test. ps: You shouldn't have … | |
Re: I agree. Define an oject that corresponds to a single row of the data table (with instance variables of the appropriate type for each field) the read the table into an ArrayList of those objects. | |
Re: elSifa: please share your solution with us - I for one would certainly like to know the answer! |
The End.