7,116 Posted Topics
Re: DaniWeb Member Rules include: "Do not hijack old threads by posting a new question as a reply to an old one" [url]http://www.daniweb.com/forums/faq.php?faq=daniweb_policies[/url] Start you own new thread, and post your code in code tags. | |
Re: To square a number just multiply it by itself - eg 5 squared is 5*5 | |
Re: [QUOTE=aanders5;1753090]I need to have the bombs in an array for the engine itself, but I also need to make sure the button themselves are set with a bomb object so that GUI lines up with the user.[/QUOTE] That's good - proper separation of GUI and engine/model. You can use JComponent's … | |
Re: When debugging never NEVER [I][B]NEVER [/B][/I]have an empty catch block! There are many reasons why the code in your try block may fail, and for most of them you will get an Exception that describes exactly what went wrong, and exactly where in the code. change [CODE]catch (java.io.IOException z) //catching … | |
Re: Hi @117 This problem is from 2007, when Ezzaral solved it comprehensively. Do you really think the OP has waited four and a half years just in case you wanted to contribute? | |
Re: By analogy with interfaces like Comparator, I would interpret this as follows: Create a class (eg "BalanceFilter") that implements Filter, and in its accept(...) method only accepts accounts with balances > some arbitrary threshold value. Then in the DataSet class instantiate a BalanceFilter with threshold value of 1000, and use … | |
Re: After you have filled your array of Circles you can loop through that array and use your getColour() method to get the colour of each Circle. Test if that is red, and increment a counter if it is. | |
Re: You are responding to keyPressed, which happens when the user presses a key (duh!). But the input to the text field doesn't happen until the key is [I]released [/I] and a valid character has been typed - so that's why you don't see the latest char in the getText. (Ps … | |
Re: [CODE]try { // your code that could cause an exception to be thrown } catch (Exception e) { // catch any Exception that may be thrown // your code to display an error message }[/CODE] | |
Re: Two more things to check: is the class file in a folder called "src" in the jar? is all the capitalisation correct (file names in a jar are case-sensitive)? | |
Re: You can run batch jobs as at the command prompt frim Java by using ProcessBuilder (Google for examples and details), but you may get a far better solution all round by embedding a JavaScript script in your Java program. Check out scripting language support in Java (Java 1.6 or later). | |
Re: In a classic array list (eg java.util.ArrayList) you have a [I]size [/I]which is the number of objects actually stored in the list at any time (initial value 0), and a [I]capacity[/I], which is the length of the private array that's used to hold the list (initial value is an arbitrary … | |
Re: [QUOTE=steven8579;1752096]i get what you're saying. This is what i'm trying to do. The first while loop should read all nums in the array from the left to the right and stop where the element is supposed to be inserted. The condition should be that index < numElements and number is … | |
Re: If you want to use classes like JOptionPane from the javax.swing package then either 1. Use its fully qualified name javax.swing.JOptionPane or 2. import the class (or package) at the beginning of your program so you can use the class name without qualification | |
Re: ^ that's right. I've done quite a lot of that to provide remote interfaces to what would otherwize be just local Swing applications. You can simply write an HTML file like you would write any other text file, taking care with Java escape chars. What's a bit more interesting is … | |
Re: [CODE]void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { while (... ... Thread.sleep(...[/CODE] You simply can't do that in Swing, or rather you can, but it doesn't work. Everything to do with Swing (eg painting the screen, running actionPerformed methods) happens on a single thread - the "Event Dispatch Thread", or "EDT", or "Swing thread". … | |
Re: Quick answer: an instance variable is any variable declared in a class but not inside any block (eg method), and not declared static. I don't understand your second question - what did you want the main to do? | |
Re: Are you certain that you are using matching streams and encoding for the read and the write? Is the user name the very first thing sent over the socket? | |
Re: Do you have any exceptions thrown? Do 100% of your catch blocks printStackTrace()? | |
Re: Hi Norm. Watch out for this OP - already in trouble with Peter Budo for not showing any effort, and is starting to troll other people's posts. J | |
Re: You would normally use the classloader's [ICODE]getResourceAsStream [/ICODE]method - which has the advantage of immediately giving you an open InputStream on the file in the current jar. You'll find the doc in the usual places, but briefly: in the code of a class that was loaded from the same jar... … | |
Re: Around lines 60 and 228 the initialisation loops stop one short, and leave the last element of each array null. [CODE]for(int i=0; i < 12; i++) { // initialises the first 12 elements of 13 rankArray[i] = new Rank(i); for(int i=0; i < 3; i++) { // initialises the first … | |
Re: new GroceryList(); looks for a constructor with no parameters, but the only constructor you have defined is public GroceryList(String name, int quantity, double unitPrice) | |
Re: You just need to cast the Object that's returned. String isn't a primitive so there's no boxing involved String s = (String) btn.getClientProperty ("myString"); | |
Re: Methods declared in an interface are automatically public and abstract, so the method definition in the class that implements must be declared public, as default access is more restricted | |
Re: I didn't trace thru all that code, but I notice you've ported a file name from Windows to Linux. Apart from the obvious working directory differences, you are also moving from a case-insensitive environment to a case-sensitive one. Maybe that's a problem? ps [CODE]boolean exists = file.exists(); if (!exists) { … | |
Re: You may need to let the layout manager know that you need it to update the layout after you have added the buttons - try calling invalidate() on your panel after adding the buttons. The other thing is that icons on jLables and jButtons are notorious because if there is … | |
Re: That depends on the bank, but in general: A savings account pays interest, and can never have a negative balance A current account may or may not pay some interest, and may allow negative balances. A current account is used for day-to-day transactions using cheques or debit cards or on-line … | |
Re: Small suggestion re cOrRuPtG3n3t!x's code posted above: in both catch blocks add an [ICODE]e.printStackTrace();[/ICODE] so that if something goes wrong you will know what the problem was. | |
Re: Do you mean the text field didn't show up, or it did show up but the image was missing? If you paint a small colored rectangle instead of the image does that work? | |
Re: I looked at your files, now I don't understand your question! [QUOTE]how do I create a file with a list of all the words that can be accessed by an user input to verify if the word exists?[/QUOTE] You already have that file [QUOTE]I dont know how to create or … | |
Re: I hate to rain on your parade, but there's no such thing as an ASCII value of 147. The ANSI ASCII standard code is a 7 bit code, covering values 0 - 127. There are many many variants on 8 bit codes (code pages in DOS terms), which are consistent … | |
Re: What do lines 51/52 really look like? ".. results nothing as an output" Nothing as in "", or null, or absolutely nothing happens (in which case is the CPU busy or idle)? | |
Re: Math.power ends up in a native method to do the actual calculation, so its a reasonable bet that's its very efficient indeed. Either way. memory really doesn't come into it. Unless your idea of "a lot" runs into millions in this case, I wouldn't waste another millisec worrying about speed … | |
Re: "http:\\www.google.com" In Java \ is a special character, used to start escape sequences in string literals. "\\" in a string literal is only a single \ character in the String itself. | |
Re: The inherited paint method from JTextField is where the actual text is painted into the field. Because you have setOpaque(false) the inherited paint will not attempt to draw any background, so it will just paint the text over the image you painted in your code. If you didn't call super.paint … | |
Re: [CODE]static String test=null; public Card() { setValue();//if we dont call this our value wont be set } public static void setValue() {//set value test="of"; }[/CODE] Why such ridiculous contortions? Why not just [CODE]static String test="of";[/CODE] | |
Re: GroceryList extends ArrayList<GroceryItemOrder> so super(name,quantity,unitPrice); tries to find a constructor in the superclass (ie ArrayList) that takes those 3 params, and there isn't one. | |
Re: You need to create three objects to represent the three moving shapes (using a new class that you have to define). Each object must implement the Animate interface. Your main animation class can then call each object's [I]move [/I]method to move it (eg on a Timer), and your main paintComponent … | |
Re: "NOT ( ( b ) AND ( a )) ... This formula is terminated has AND is the root" Are you sure? I would expect the resulting tree to look like this: [ICODE] NOT / \ / \ (null) AND / \ / \ a b[/ICODE] | |
Re: I think he's talking about Steganography [URL="http://en.wikipedia.org/wiki/Steganography"]http://en.wikipedia.org/wiki/Steganography[/URL] | |
Re: For general data you could use an ordinary zip file [url]http://java.sun.com/developer/technicalArticles/Programming/compression/[/url] | |
Re: By matching the number and types of the parameters in the call to those in the constructor's definition (just like any overloaded method call) | |
Re: An abstract class can declare ordinary variables. An interface can only declare final static "variables" (AKA constants) | |
Re: Use a javax,swing.Timer to run the necessary code at the appropriate intervals? | |
Re: It means the application and/or its databases are somewhere on the Internet ("in the cloud"), and all you have on your computer is some kind of front-end to access it (maybe even just a web browser). | |
Re: Yes, the param for split is Regex, and $ is a special char in regular expressions. You have to escape it with a backslash to use it as a literal $ | |
Re: This seems a stupidly designed Java exercise to me - let's do some cunning logic but no if tests? - but hey ho. There must be mathematical formulae (using the ceil function) that evaluate to 1 if a variable is larger/smaller than some reference variable, and zero otherwise. So if … | |
Re: [CODE]b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if(table.getSelectedRow()<0) // help required to implement this logic!! { JOptionPane.showInternalMessageDialog(rootPane, "Please select a row from the table first!"); ...[/CODE] At a quick look what you've got seems OK. What exactly is the problem with the code you posted? | |
Re: JComboBox allows you to pass a list of objects to its constructor, and uses those for its data values (calling their toString methods to display them). But for historical reasons the list has to be in a Vector, not an ArrayList. If you change your ArrayList to a Vector (no … |
The End.