7,116 Posted Topics
Re: You could add a layer instance variable to the cube class, then in the paintComponent (not paintComponents, not paint!) method sort the cubes on the layer variable before painting. Or Keep another list of cubes, this one in layer order. Shuffle the list when you want to change a cube's … | |
Re: That's just notepad showing its age. Use wordpad. Or a decent editor. | |
Re: Without knowing what you want to do with later, it's impossible to decide what is the best approach. However, my instinct is to create a PropertyNode class that has a List of properties (Strings?) as an instance variable. I would then read the whole file and create a map of … | |
Re: OK, so you had a problem, but you've fixed it, and now you have another error, but you haven't told us what it is. You have at least two sections of code, but we don't know how you fitted them together. So what you have to do is start again … | |
Re: Sorry, can't read that, it gives me a headache. | |
Re: Vector and ArrayList are almost identical (Vector methods are synchronised but ArrayLists are not). They each hold a simple ordered list of items. HashTable is a completely different thing; it maps keys to values. The decision whether to use Vector/ArrayList or HashTable depends on whether the data has to be … | |
Re: You have 2 arrays to fill up, but you only have one variable i to keep track of both - so if you have 4x econ they go into EconArray[0-3] then if there's a 1st it goes into FirstArray[4] not FirstArray[0]. You need two variables corresponding to the 2 arrays … | |
Re: Yes. Package the compiled .class files into an executable jar. When you double-click the jar the program will run. Just Google "executable jar" for the details | |
Re: You can get the source of the event from the ActionEvent itself eg e.getSource() - this will be the particular button that was pressed. | |
Re: This isn't very clear - but do you mean that those details are fields of a class you defined (eg Album) and when you print it you get some hex? If so, that's the default toString() method that your class has inherited from Object, and what you need to do … | |
Re: AFAIK external processes started using the ProcessBuilder class run independently of what you do with your Java app once they are started. | |
Re: The while on line 7 looks wrong to me. This is a recursive solution, it shouldn't need another loop. I would expect a simple if. You'll probably want a better print on line 32, since array is an array. | |
Re: Maybe don't do it at all, just use the existing Preferences class to do it for you | |
Re: Throw me a bone here - what EXACTLY is the error message you are getting? | |
Re: The language reference makes it clear that primitive types (int, boolean, char, float etc) are not Objects, so you may draw conclusions from that if you wish. | |
Re: So... it looks like the 2 parts to your system need to know about each other - or at least ButtonPanel needs to have access to the instance of GamePanel so it can call its methods. One way is to pass the instance of GamePanel to ButtonPanel in ButtonPanel's constructor. … | |
Re: 1. x=0; is an assignment statement that can only be used in a method or constructor, so you can't just have it in your class like that. You can use an initialiser as in int x = 1; 2. Making the object of the class dabba in the dabba class's … | |
Re: reads files images/img1.gif images/img2.gif images/img3.gif etc and uses them to create graphical icons that can be displayed in a JLabel | |
Re: Hi jackmaverick Not being able to do a switch on Strings is a well known shortcoming of Java and (at last!) its fixed in Java 7 - which will be out later this year. You can switch on a single char because a Java char is a numeric type (16 … | |
Re: [CODE=JAVA] String stamp = "2011-03-23 00:43:07"; SimpleDateFormat dfZone = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss z"); Date dZulu = dfZone.parse(stamp + " UTC"); System.out.println(dfZone.format(dZulu)); // uses UTC dfZone.setTimeZone(TimeZone.getDefault()); System.out.println(dfZone.format(dZulu)); // uses local time zone dfZone.setTimeZone(TimeZone.getTimeZone("PDT")); System.out.println(dfZone.format(dZulu)); // uses West Coast zone[/CODE] | |
Re: Convert the Strings to numbers, add them up, divide by the number of entries. | |
Re: Yup. [ICODE]System.in[/ICODE] is the console input stream. It's common practice to use this with the Scanner class to handle some basic parsing of the input... [CODE]Scanner sc = new Scanner(System.in); String s = sc.nextLine(); or... int i = sc.nextInt(); // etc etc - see API doc for details of all … | |
Re: There was a thread on exactly this problem here a few weeks ago - you should be able to track it down without too much problem. | |
Re: @dononelson has already given a good answer to this "iterate through your doubly-linked list and add each element to a java.util.LinkedList". Do you have methods in your DLL to (a) get the first element and (b) get the next element? (If not, your implementation is incomplete.) You can use those … | |
Re: In a fraction of the time it took to post that you could have Googled [ICODE]resultset swing table[/ICODE] and got any amount of sample code and discussions. | |
Re: The usual convention for compareTo is that it takes 1 param and compares that to the current object ("this"). | |
Re: [url]http://download.oracle.com/javase/tutorial/getStarted/cupojava/win32.html[/url] | |
Re: Windows: javaw -jar myJar.jar arg1 arg2 | |
Re: Your load code looks OK to me at a quick scan, but there's a big problem with what you do next. You create a new local variable FirstYears (NB should be firstYears), read the file into it, then end the method - at which point FirstYears goes out of scope … | |
Re: If your indentation is right then you increment fcnum inside 2 nested loops without ever resetting it, so its hardly surprising that it eventually gets >9 and is no longer a valid index for a 10 element array. | |
Re: You can download the source code for Java SE from the Oracle web site under the JRL (Java Research Licence*) - although there are restrictions if you live in country that's not on the approved list. [url]http://download.java.net/jdk6/source/[/url] * The JRL is a license that was created specifically for universities and … | |
Re: if(value !=null) value is an int, and can never be null. Only Object references can be null. | |
![]() | Re: The ArrayList class has a [ICODE]boolean contains(Object o);[/ICODE] method that returns true if the ArrayList already contains this Object, so you can use this for your [ICODE]if(newurl is not in visitedarray)[/ICODE] test. The test used to see if Object o is already in the ArrayList is o.equals(any element in the … |
Re: You can test the value (see previous post) and if it's out of range you can throw a new Exception [CODE]throw new Exception("value out of range");[/CODE] | |
Re: OK, we don't have the full picture here. You declare goodWords as a raw type - which gives a warning when compiled. Ditto your iterator. Line 5 has a case error, and doesn't compile. You then assign the return value of iterGoodWords.next(), which is type Object, to a String, which … | |
Re: How about something like... [CODE] public void mitosis() // duplicates all the cells in this Organism... ArrayList<Cell> temp = new ArrayList<Cell>(cells); // need temp copy of cells because cells will be modified in the loop cells.clear(); // We could just add 1 copy, but removing the originals and // adding … | |
Re: What version of Java are you using? It's OK with current versions of 1.6. | |
Re: First work out how you would do it by hand. Write down what that process is. Then finally translate it into Java code. | |
Re: [QUOTE]to keep DaniWeb a student-friendly place to learn, don't expect quick solutions to your homework. We'll help you get started and exchange algorithm ideas, but only if you show that you're willing to put in effort as well.[/QUOTE] So what have you done so far? | |
Re: [QUOTE]to keep DaniWeb a student-friendly place to learn, don't expect quick solutions to your homework. We'll help you get started and exchange algorithm ideas, but only if you show that you're willing to put in effort as well.[/QUOTE] So what have you done so far? | |
Re: Please show the code for DisplayWindow (or at least the constructor that is called on line 12), and the code for the FileTree constructor ditto. If either of those causes (directly or indirectly) a call to refresh() then this will happen before any value is assigned to window on line … | |
Re: int a[] (or int[] a ) defines a variable a that is a reference (like a pointer) to an array of ints. It's initial value is "null" - ie it does not contain an actual reference new int[5] allocates memory in the heap for an array of 5 ints so … | |
Re: Have a look at the KeyListener interface in the API doc - it allows you to respond to individual keys being pressed and/or released. | |
Re: No, it's not. What is it that you want to achieve? - there may be other ways to get the desired result. | |
Re: The error message (Exception) tells you exactly what kind of error it is, and exactly which line it happens on. Without that info its very hard to debug. Please post the full text of the error message | |
Re: Rather than Google, you first point of reference should be the JComboBox API documentation, where you will find the following... public int getSelectedIndex() ... Returns an integer specifying the currently selected list item, where 0 specifies the first item in the list; or -1 if no item is selected or … | |
Re: "Doesn't run" Do you mean when you try to execute it nothing happens? Or does it throw a runtime Exception? Or does it give a wrong result, and if so, what's the difference between the expected and actual result. But anyway, line 9 you lose all the text before the … | |
Re: [ICODE]static_cast< int >( 'A' );[/ICODE] This isn't part of the standard Java language or API, but it is valid C++ You can cast a char to int in Java with the following syntax [ICODE](int) someChar[/ICODE] eg [ICODE]System.out.println('A' + " = " + (int ) 'A' ); // prints A = … | |
Re: The principle is easy - on each "tick" of your clock add a small downwards increment to the Y velocity. This simulates the effect of gravity accelerating things downwards. Eg if you start with an upwards velocity it will slowly reduce to zero and then go negative. You may also … | |
Re: Making the buttons work has nothing to do with which LayoutManager you use. Regardless of layout you use an ActionListener to make a method that will execute when the button is clicked. Google ActionListener for loads and loads of examples of how to set this up. |
The End.