7,116 Posted Topics
Re: DaniWeb Member Rules (which you agreed to when you signed up) include: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules Post what you have done so far and someone will help you from there. | |
Re: KeyListeners are always problematical, particularly in respect of which component has the keyboard focus. The answer is don't use them. Oracle's own tutorials recommend key bindings instead: http://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html | |
Re: `72: nextStudent++;` You have the code to update nextStudent correctly, but there ate two related problems that prevent that working as you expect: 1. Every time you enter your actionPerformed the first thing you do is to set nextStudent back to 0 2. You declare nextStudent inside the actionPerformed method, … | |
I'm curious. Why is so much code in this forum formatted like this [CODE]if (something) { do something } else { do another thing }[/CODE] rather than [CODE]if (something) { do something } else { do another thing }[/CODE] The first version is harder to read and takes up more … | |
Re: The original question seems flawed. As you say, square and circle each require one numeric parameter, triangles and rectangles both need two, so there's no way to distinguish those method signatures without resorting to highly artifical solutions like the one you show. Are you certain that you were not asked … | |
Re: > When we assigned ls to o, didn't Object o become an array? Don't lose track of the difference between objects and **reference** variables. Nothing you can do in Java will change the actual type of an object. ALl you can change is what references are known to refer to. … | |
Re: Yes, you already said that in your first post. The code you have posted in not valid Java. It won't compile, and therefore cannot be executed. So how about posting the actual code that gave you the error? | |
Re: Hello alastair That was a very clear and helpful post, but it did spoon-feed the OP a lot of code. There's always a danger that someone will copy/paste those blocks without understanding how they work, and thus learn nothing. If you use pseudo-code to illustrate the logic then the OP … | |
Re: If you are using ordinary random numbers then its hard to see how you can possibly decode the resulting randomised content. Maybe what is intended is that you use the seed value to seed the random number generator. The Java Random class guarantees that "If two instances of Random are … | |
Re: Without actual error message(s), the code in question, and a listing of the jar contents it's very hard to identify where you have gone wrong! One likely area is that some classes are missing from the jar, or are not in the correct folders within the jar, but the error … | |
Re: When you pass a value (primitive or reference) to a method Java creates a copy of that value, and that's what you are accessing inside the method. (Note that the value of a reference variable is a reference, not the object that is referred to, so only the reference is … | |
Re: dansm88 Please don't just ask people to give you code. If yuo have a Java question, or there's some aspect of Java you want to learn about, please start your own thread and explain what you have done already. | |
Re: The NPE message tells you the exact line where it happened. Unfortunately the message you posted doesn't match the code you posted, so we can't see which line is the problem. Print the variables or methods that are used on that line to see which is null. Then use more … | |
Re: It looks like you created the transform OK, but missed the bit where you associate the AffineTransform with Graphics, as in `g.transform(tx);`, before drawing. Once you have that working you will be able to see how different transforms affect your image. I suggest just starting with one at a time, … | |
Re: You have defined the ArrayList as an ArrayList of Orders. That means the only thing you can add to that list is an Order. You can't add a String (line 18) and you can't add nothing (line 19). You didn't post the code for the Order class, but presumably it … | |
Re: You can do it easily in Eclipse. Select your project then go to File -> Export... -> Runnable jar file That takes you into a Wizard that will help you create a runnable jar file. You can double-click the jar file on the desktop to run your program (assuming Java … | |
Re: Maybe OR those conditions rather than ANDing them? | |
Re: for(int i = 0; i < cookies.length; **i++**){ for(CookieFlavors c : CookieFlavors.values()){ cookies[**i++**] = new Cookie(c); You increment i twice on some passes of this loop, so some indexes get skipped and are left as null. | |
Re: You increment count by 2 on each loop, so its values go 0, 2, 4, 6, 0, 2 ... that's a four value cycle ps you have a redundntt loop lines 41/50 - flad g is always set false, so its only ever executed once. pps `while (flag == true)` … | |
Re: Macify looks interesting as a packaged solution: http://simplericity.com/2007/10/02/1191336060000.html or here's a load of info for doing it yourself: http://alvinalexander.com/apple/mac/java-mac-native-look/ ... lots of other info is at the end of a very small Google query. In either case you can use the same jar for both environments, and you can compile … | |
Re: The default font for a JLabel is porportionally-spaced, so , for example an "i" or a space (" ") will be lot narrower than an "M" or a "W". If you want all characters (including " ") to be the same space specify a fixed-width font for your JLabel, eg … | |
Re: Lines 14-16 create the Vector of column names from the result set (did you write that code yourself, or just copy it?). If you want some other name(s), put them into the Vector instead of the current value(s). | |
Re: The "other person" is not helping you. Line extends Point makes no sense. A Line is not a "kind of" Point. The Line class makes no use of the variables or methods it inherits. It's just wrong. Your Line class, with two Point instance variables to define its ends makes … | |
Re: Vectors own methods are synchronised on the Vector instance, so if you call add on a Vector from one thread while another thread is executing a remove yhou should be OK. Vetor knows nothing about your callMethod method, so it can do nothing about synchronising that. It does not / … | |
Re: > How many Pixels are copied when the Picture is mirrored along the vertical line through its middle? Isn't the answer just "all of them" (H*W)? Or am I missing something? | |
Re: The easiest way to to decide on classes is to go back to the English description of the domain. Being English I have no idea about baseball, but if *Stats* are things that a *Player* ***has***, then the obvious implementation is that Stats are a class and a Player has … | |
Re: Since you're a bit past the beginner stage, how about Netbeans? It's the one that the Oracle Java tutorials use. http://docs.oracle.com/javase/tutorial/uiswing/learn/index.html | |
Re: Put a load of print statements into your code, printing the values of the key variables at each stage so you can see where it's going wrong, eg at line 23 print command and name, when adding entries to the directry print them, so you know for certain what's in … | |
Re: When reading the file how do you know how many scores there are for each student? | |
Re: Your listener will be called once for each key, so you can't look fr both keys in just one call. You need to create one or more variables outside the listener that you can use to keep track of what keys have already been pressed | |
Re: Graphics2D (the actual class of the Graphics you draw on) supports a huge set of transforms that modify how subsequent draw operations work. So, for eaxmple the g.rotate method causes all subsequent draws to be rotated by the specified angle. Similarly you can set a scale transform that scales subsequent … | |
Re: DaniWeb Member Rules (which you agreed to when you signed up) include: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules Post what you have done so far and someone will help you from there. | |
Re: I have to disagree with Taywn. This is absolutely an integer problem that needs an integer solution. The positions are described as in the middle of a 1 foot section, but that's irrelevant. YOu don't need to know where the step comes to the nearest inch. There are only 7 … | |
Re: DaniWeb Member Rules (which you agreed to when you signed up) include: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules | |
Re: That looks like you're setting that cell before you create the GUI, and when you create the GUI you set a new model. Try setting the cell *after* creating the GUI | |
Re: java.lang.NullPointerException at AppletMetodos.actionPerformed(AppletMetodos.java:96) One of the values on line 96 is null (ie not initialised). Print all the variables used on that line to see which one is null, then you can back-track to find out why. The array "user" would be the prime suspect... | |
Re: Don't confuse methods and variables. The compiled code for all methods will be loaded along with the class some time prior to the class's first use. The memory for static variables ditto. The memory for instance variables is allocated when a new instance is created. All this is true of … | |
Re: indexOf for ArrayLists looks for the search object in the ArrayList. The search object is the String "Java". There is no object in the ArrayList that is equal to the String "Java". You will have to loop thru the ArrayList testing each String in turn to see if it contains … | |
Re: You need to import the Scanner class. ps DaniWeb Member Rules 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: It's really hard to understand your requirement, but is this what you mean (pseudocode)?... valuesToSkip = new ArrayList<Integer> for (r ... if (valuesToSkip.contains(r)) continue; ... valuesToSkip.add(anotherValueThatYouWantToSkipNextTime) | |
Re: The Java Language Spec section 12,5 is the definitive refernce on instance initialisation, but briefly, in simple cases like that there's no difference. In your first example the initialisation of the int happens after all superclass constructors have been called but before the remainder of the constructor executes. It's possible … | |
Re: Debugging by re-reading your code and thinking hard is very ineffective. Put a load of print statements into your code, printing the values of the key variables at each stage so you can see where it's going wrong. | |
Re: What exactly is the question? You can clear a text field by simply setting its text to "", but remember that will create another call to your DocumentEvent listener, which you may need to handle. | |
Re: Loop with an index variable that starts from 2, but then when you increment it test if it is >= (length of the array), in which case set it back to 0. | |
Re: 1. You can't assess "efficiency" unless you have a reasonable list of the various ways in which the data needs to be accessed and a rough count of how often each of those will happen. Do you need to find the priority for a given operator? Do you need a … | |
Re: They could ask you about sorting arrays - various algorithms and their advantages/disadvatages | |
Re: If it completes one pass thru the data without having swapped any elements, then the list is sorted, so all you need is a simple boolean for that. | |
Re: You need public accessor methods such as getName, getID that simply return the values of those private variables. That way you allow other classes to get the values in a controlled way, but not to change or corrupt them. Similarly you can create public setID etc methods if you want … | |
Re: A grid layout is just an algorithm for placing GUI objects in a container. The "cells" are just an abstract geometrical concept, so there's no meaningful way to "mainipulate" them. What you can do is create a 5x5 array of some real objects, eg JButton[5][5] or JLabel[5][5], then use the … | |
Re: Case 1 every element is an Integer or a subclass of Integer. All subclasses of Integer are Integers (can be cast to Integer), so the implicit cast to Integer is OK Case 2 every element is an Integer or a superclass of Integer. Not all superclasses of Integer are Integers … |
The End.