7,116 Posted Topics
Re: For re-usability it would be better to return the long value, rather than set a fixed named variable that's declared elsewhere? | |
Re: It would be simpler to convert the position references directly to array indexes - eg `pos.charAt(0) - 'a'` returns 0 if pos starts with 'a', 1 for 'b', 2 for 'c' and `pos.charAt(1) - '1'`similarly for the numeric part. Now you have the i,j values to index the array of … | |
Re: Problem is probably that because you are drawing the panel Java has no idea how big it should be. It's probably showing a preferred size of 0x0. It works in the center position because that gets all the available space after the other components have been positioned.Try setting a preferred … | |
Re: OK guys, that's enough repeating each other's posts. Tux4life made it perfectly clear the first time. Please don't just re-post the same answer without adding any new information. | |
Re: That whole approach to solving it is hideously over-complex (and badly coded as Tux points out). The only problem was that the original delimiter string omitted blank. Ie instead of `"!.,"` it needs to be `" !.,"` | |
Re: http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html | |
Re: You can't mix object I/O and imageIO in a single file like that. ImageIO writes a single image in the desired format (jpg, png etc). The API doc also says " If there is already a File present, its contents are discarded.", so it's stricly one image per file. ObjectStreams … | |
Re: > If the readLine() waits for an input what would be the most effective way of avoiding the alternating pattern read-write, and allow the program to function more like a chat room? To do that you need two threads. One loops waiting for the local user's readLine() and sending the … | |
Re: DataOutputStream outputs data in its raw binary form - eg always 4 bytes for an int PrintStream outputs data in a human-readable character format - so an int could be anything such as "0" or "-1234567" | |
Re: A log file is incredibly useful when things go wrong, provided it has been written to disk. So for me, waiting until the end to write it is not a good idea because a crash may prevent it being written. I would write all the records ditrectly to the file … | |
Re: The System.setOut and System.setErr methods redirect all console output to a print stream of your choice. | |
Re: > I feel it is a better practice to have only one class where you want to make the changes in No, not really. That will distort the class structure and force data items into one central class regardless of where they logically belong. Focus on words like "has a", … | |
Re: You could build a HashMap<string, Integer> with the word as the key and a count as value. For every word in the file, if it's already in the Map add one to the count, if it's not already in the Map add it with a count of one. When you've … | |
Re: alike234 Welcome to DaniWeb. Although your problem may be urgent to you, screaming for help *help* ***help*** isn't going to make it urgent for anyone here. You will get better results from a calm clear request (eg exactly what help do you need). Anyway - you posted a homework assignment, … | |
Re: If you move the code lines 12-17 into Skate's constructor then you can simply call `new Skate();` in your button's ActionListener | |
Re: Matt Two things you may have misunderstood... 1. This is not a "we do your homework" servce. Somebody may help you learn how to round your results, but nobody will just do it for you. 2. This is the Java forum. Java and JavaScript are not the same thing at … | |
Re: Look again at the loops where a value is being doubled or halved... ;) | |
Re: In this case the answer is trivial. Version 1 works, and version 2 doesn't. Your compiler will tell you the same thing. You can't cast from a String to an int. Check out the Java Language Spec section on casting to see the rules on what you can or cannot … | |
Re: Have a look at the Calendar API - there's a method that tells you the day of the week. | |
Re: In pseudo code it looks like: for i = 0 to 2 for j = 0 to 2 array[i][j] = the next character You have a number of ways to do "the next character", eg have a counter that tracks which is the next character, and increment it each time … | |
Re: exit(), not Exit(). Java is case-sensitive actionlisteners are for buttons etc, you seem to be trying to add one to a JFrame | |
Re: > converting date and time into milliseconds doesnt seem the solution Why not? Just get the time now and the time when you want the reminder, convert both to mSec, then take the difference between them - that's how many mSec you need to wait for the reminder. | |
Re: Is that a java.util.Timer or a javax.swing.Timer? Some timers run from the previous execution, others run from the previous scheduled time even if the execution was delayed. You want the second type. The way to get a fixed-rate animation when the CPU loading is high (eg slow computer) is to … | |
Re: Easiest way is to read the image file ito an ImageIcon, then simply use that in a JLabel http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html | |
Re: There were significant changes in Jav at version 1.5, so anything older than that is not a good idea. The changes from 1.5 to the current 1.7 are useful, but not earth-shattering. But for reasonsof security fixes you should download/install only the latest version form Oracle. The tutorials on the … | |
Re: All anyone can tell from what you've posted is that you try to access element 13 in an ArrayList (client) that has 12 elements. The reason for that lies somewhere in all the other code that we haven't seen. First, decide whether the index is wrong, or the client list … | |
Re: Current Java is 1.7 (also called Java 7, just to confuse everybody). What exactly are you referring to with Java 9 or 10? | |
Re: It woiuld be nice if uou could use that syntax in Java, but you can't. It's not part of thelanguage. `-13683360 <= rgb` evaluates to a boolean (true/false) and then `(true/false) <= -13683381` is a bad operand because you cant't use <= with a boolean. You need to break it … | |
Re: Start [here](http://docs.oracle.com/javase/tutorial/2d/images/index.html). | |
Re: Two possible approaches: 1. Make the currentRoom variable static and public, so other code can reference it as Game.currentRoom. - easy to do, but horrible misuse of O.O. practice. Not recommended! 2. Presumably there's some code in the Game class that creates new Inventory and Room instances. At that point … | |
Re: No 3.. interface A {void x();} interface B extends A {void y();} just try it. No 4. Depends on whether the class is defined as abstract or not (question is not clear) No 8. Java Language Spec says "This (multiple) interface inheritance allows objects to support (multiple) common behaviors without … | |
Re: I think you mean "ascending" - lowest values first | |
Re: There are a few ways to do this, but the easiest is probably the contains method: String s = "Hello from DaniWeb"; if (s.contains("from")) ... | |
Re: Hi Stultuske I think the OP's problem is a bit more interesting than that. Your solution only works if the desired length is a multiple of 3. As I understand it the requirement is y output - ------ 1 m 2 m/ 3 m// 4 m//m . ... 9 m//m//m// … | |
Re: It's called an anonymous inner class, it defines a new subclass of Handler and creates an instance of it. Google *Java anonymous inner class* for tutorials etc. | |
Re: Perhasps use Regex instances to define each of the variants/replacements you are looking for? You could place all the current Regex's in an ArrayList and loop thru them regardless of how nany there are. | |
Re: You haven't provided enough info for anyone to say what is the most appropriate solution - eg when and any are instances of A,B and C created and allowed to die? Maybe if you described what the problem really is that will help. [Here's](http://www.daniweb.com/software-development/java/threads/374909/inputoutput-with-multiple-forms) a discussion of one such real-life … | |
Re: Yet another post from crash bash that ignores the DaniWeb Member Rules, specifically "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules Start following the rules, or I'll start deleting your offending posts. | |
Re: I recently built a colliding multiple ball app to use in my tutorials, and found [this](http://www.gamedev.net/topic/627978-need-tips-on-collision-response-for-a-2d-ball-hitting-another-2d-ball-that-is-controlled-by-an-accelerometer/) web site. I adapted the code from there, and it looks pretty realistic to me. | |
Re: The "OO" way is to create a class for whatever it is you are entering and displaying. This class represents the data and logic for whatever it is, and is the true core of the application. Such classes are generally referred to as a "model". In your input form you … | |
Re: Apparently Intel processors from Ivy Bridge onwards have a hardware random number generator instruction that is as near quantum-mechanical noise random as you can be... http://software.intel.com/sites/default/files/m/d/4/1/d/8/441_Intel_R__DRNG_Software_Implementation_Guide_final_Aug7.pdf | |
Re: Add a node to what? The answer depends on what kind of data structure you are adding to. What have you tried so far? | |
Re: Your double(a) method isn't going to work without a return value. All java method parameters are passed by value - the parameter in the method is a copy of the original value. The "a" that you are manipulating in your method is just a copy of the "a" reference that … | |
Re: DaniWeb Member Rules (which you agreed to when you signed up) include: "Do not hijack old threads by posting a new question as a reply to an old one" http://www.daniweb.com/community/rules Please start your own new thread for your question | |
Re: Thta's not a whole program, it's just one class. That class will be combined with other classes to make a useful program. The other classes will then use the getters to access the Employee info. | |
Re: There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you. DaniWeb Member Rules (which you agreed to when you signed up) … | |
Re: Yes, keeping the variable private is a good idea, but stultuske's version is not thread safe, whereas the original version and the enum version are both thread safe. | |
Re: Can't you just clear the contents of rects? | |
Re: (Topic title changed to "classes" as requested) |
The End.