7,116 Posted Topics
Re: That looks pretty random to me. Were you expecting a perfect flat line (equal occurrences of each value)? - because that would NOT be random! And as dmanw100 said - Random has a method for random ints in a range | |
Re: If you do a System.exit your program will terminate immediately and any unflushed buffers will be discarded, and any system resources you are holding may not be released. You should use try/catch/finally to ensure files and closed and resources released, and ideally allow your program to terminate normally by finishing … | |
Re: No, the size is the size. You can just return it, regardless of whether it's zero or more. The [ICODE]return 0;[/ICODE] is in there because the compiler will generate an error if that method doesn't return something. When you put in the correct code you can discard the [ICODE]return 0;[/ICODE] | |
Re: Maybe you can use [I]!getHireDate().equals("");[/I] because that value seems to be set during a hire, and cleared on a return? | |
Re: You can use a MouseListener to run your code when the mouse enters or leaves the frame, but I'm not sure whether that will work when the frame is hidden - you may need to have a transparent <something> in the place of the frame when it's hidden so that … | |
Re: Yes, they are constants in the Color class. They look like this: [ICODE]public final static Color gray = new Color(128, 128, 128);[/ICODE] You can use reflection to loop through all the variables in the class and select those which are public static final Colors - this code does that and … | |
Re: [QUOTE=warlord902;1733570]Means unless we are updating or modifying something there is no need to make such methods synchronous?[/QUOTE] This will be true most of the time, but if you are accessing more than one value in such a method you may get inconsistent values for them when another thread modifies the … | |
Re: [QUOTE]int[] arrNumbers = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};[/QUOTE] ie arrNumbers [i] == i+1 really? | |
Re: The join statement won't be executed until "some heavy work" is finished anyway, so the timeout won't be useful. I think you need to start a second thread (or just a Timer) that waits for [I]timeout milliseconds[/I], and use that to terminate your work thread if necessary. | |
Re: You can't do drawing in Swing like that, it's not how it works. Create and use a subclass of JPanel and override its paintComponent method. When Swing needs to display your panel it will call your paintComponent, passing the correct Graphics object (actually an instance of Graphics2D) for you to … | |
Re: How is update called - do you use a javax.swing.Timer? | |
Re: A bubble sort just needs to compare and maybe swap two consecutive members of the list a few times. Forget the sort for a minute, and write a method to compare two consecutive members of your DLL. Now write a method to swap two consecutive members of your DLL. Now … | |
Re: [QUOTE=cOrRuPtG3n3t!x;1733782]why are you using this [icode]if (counter % 3 = 2){ }[/icode] i dont get the '% 3' and to be honest this must be the first time ive seen such an if statement[/QUOTE] Me too, but not because of the %, but because it's not Java. It won't compile … | |
Re: Those code fragments don't make any sense strung together like that - I assume you have just posted the bits you think are relevant. Anyway, B has int alarmId = A.getalarmId(); so class A must have a getalarmId() method, and that's how 'alarmId' gets passed from class A to class … | |
Re: As always, it's hard to beat the official Sun/Oracle documentation for Java [url]http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html[/url] | |
Re: @karthi.k.s: Please don't give people solutions to their homework. All it teaches them is how to cheat. Help them learn to develop their own solutions. And if you do post some code, set a good example by following normal Java naming and indentation conventions. | |
Re: Without a long look at there whole thing it's hard to be very specific, but in general: If you divide your application into smaller and smaller components (classes, methods etc) then each of those components becomes simpler and easier to understand (which is good) until eventually you reach a point … | |
Re: I suspect there is no way in pure Java to prevent it, but you could have a WindowStateListener and immediately restore it to normal when it's minimized. On the other hand if you are choosing to ignore the user's decision to minimize your window, then you should have a very … | |
Re: [url]http://www.bank-holidays.com[/url] have a comprehensive database of world-wide public holidays. You get free access to view current info, but if this is a real app you can get the data in machine-readable form for a very reasonable price: [QUOTE]Receive your data in Excel format, with customized presentation, and including update alerts … | |
Re: That's what happens when you print an object that doesn't have its own toString() method defined. It's the class name followed by its hash code. To print the contents of an array, convert it to a String by using [B]Arrays.toString(list)[/B] | |
Re: 1. Print out both those values after they are input so you can see exactly what values you are trying to use. 2. In your catch blocks don't just print "there was a problem", use ex.printStackTrace(); to see all the info related to the problem. ps: The server name may … | |
Re: You have code to split out the RGB values from each pixel, so now you need some similar code to combine RGB values into a single int pixel. Between splitting them and re-combining them you can set r, g, and/or b to zero. Or, you can use bi.getRaster().getDataBuffer(); to get … | |
| |
Re: Don't confuse string variables with Strings. In C terms, a String variable is a pointer, and its initial value is null. You can only create a string via [I]new String(some parameters)[/I] or as a String literal [I]"some string"[/I]. In both cases the size of the string is known when it … | |
Re: If your tabs are all different then there's no point doing anything other than simple JPanels. If they all conform to certain style or content standards (eg a background image, or certain controls always in the same place) then its worth creating a subclass of JPanel with all the common … | |
Re: This is the forum for the Java programming language, which isn't the same thing as the JavaScript scripting language. You'll find the JavaScript forum here: [url]http://www.daniweb.com/web-development/javascript-dhtml-ajax/117[/url] | |
Re: According to [url]http://compilers.iecc.com/comparch/article/01-03-037[/url] it's LL(1), recursive descent | |
![]() | Re: To clarify: You have a JFrame with a JPanel subclass that displays a menu. When one of the menu items is selected you want to display another JPanel subclass that contains your board (and this replaces the menu panel?). If so, I don't see the need for anything more than … ![]() |
Re: The general consensus here is that beginners should stay with the simple command prompt applications (code editor, javac, java) until they have a solid base of understanding of Java. IDEs such as Netbeans or Eclipse provide a toolset that gives experienced users a huge increase in productivity, but if you … | |
Re: It would go a lot better if you started your Timer! | |
Re: [QUOTE=David Kroukamp;1730160]... in.read() method returns a string ...[/QUOTE] Absolutely wrong. You are advising a beginner here, so it's essential that you get your facts right. It's unacceptable to create this kind of confusion. You should check your code and your facts before posting. You should also read the previous entries … | |
![]() | Re: The problem may be in the Boat class - did you declare colour and length as static by any chance? ![]() |
Re: Hi David, welcome to DaniWeb. I know your intentions were good, but we're here to help beginners build their own Java expertise. By posting complete pieces of code you run the risk that people will copy/paste without fully understanding, thus learning nothing (except maybe that it's easier to cheat than … | |
Re: These posts are confusing variables and Objects. Remember that variables are either primitives (ints etc, not Objects) or reference variables (contain a reference to an Object); a variable is NOT an Object. Object's toString() is not defined to return anything related to the address of the object, nor does it … | |
Re: Is writing [B]what [/B]one thing many times? Please try to explain exactly and precisely what is happening. You create your FilWriter in append mode (second parameter is [I]true[/I]), so every time you run the application you get another copy of the data added to your file. | |
Re: I guess you'll have to write a small method that splits the String into its components, retrieves the actual Objects represented by those sub-strings, then start with an empty TreePath and use pathByAddingChild(Object child) to add all those objects to build the fill path. It's only the step of retrieving … | |
Re: Sorry, this is nothing to do with copy constructors. You create an array and give it a size (30), and initially all those elements are null. You have a method to populate the array with data, but unless you call that 30 times, there will still be null elements in … | |
Re: Every time you read a line you call displayText, in which you create and add a new TextArea. You should create the frame etc with a single text area when the application starts, and just add the String to that existing text area in displayText. | |
Re: Short answer: Java is very widely used in commercial and corporate applications. It runs at least as fast as any other serious programming language except hand-tuned C code. | |
Re: what exactly were the "last modifications"? because that's where we need to concentrate. | |
Re: return printer(s); calls printer(s) again, which executes down to the last line where it executes return printer(s); etc infinitely | |
Re: That's an extraordinary question to ask like that. If you were a complete beginner you would get a flood of replies introducing you to Google. But you seem to be in a programme for a Master's degree, so no excuses. This is on a par with someone doing a Master's … | |
Re: Anything(eg arrays) you create in your Java app is lost when the app terminates. To save data for later use you need to write it to a file or a database. Probably the easiest is to write in in text form (same as printing) to a text file. Google will … | |
Re: The first code fragment you posted will definitely throw an NPE if it executes - do you have a try with an empty catch somewhere? Your inner loop has i++ where it should have j++ so it would loop infinitely if you ever managed to execute it. The fact that … | |
Re: Are you certain that the file is being broken into long lines, or is it possible that whatever viewer/editor you are using to look at the file is displaying it like that? If you read the file back into your Java program one line at a time, are the descriptions … | |
Re: What is the point of the "Spelling" class? It's just an ArrayList, with some stuff for the "length" (current size) that is, as SasseMan said, totally redundant. Your main problem comes because you have two ArrayLists of words, and updating one doesn't update the other. Fix this by not having … | |
Re: If you are just selecting 5 random elements from a collection of 26 then frankly you are wasting your time worrying about efficiency, either for CPU or memory. Maybe with optimal coding you could save a microsecond of CPU, and a few hundred bytes of temporary memory. Unless you plan … | |
Re: It is apparently possible by using JNA to hook the native Windows mouse events... [url]http://stackoverflow.com/questions/3590226/working-example-of-jna-mouse-hook[/url] Please report back if you have any success with this. | |
Re: You test for 'e' as a consonant. Did you mean 'w'? | |
Re: [QUOTE=zeroliken;1725523]use .equals() when comparing strings rather than == try to read this link for more info [URL="http://www.ensta-paristech.fr/~diam/java/online/notes-java/data/expressions/22compareobjects.html"]Java: ==,.equals()[/URL][/QUOTE] Good advice, yes, but in this case the code is comparing chars, not Strings [CODE]char oo = xx.next().charAt(0); if (oo == 'y')...{[/CODE] so .equals cannot be used in this situation. Maybe the … |
The End.