7,116 Posted Topics
Re: Welcome to DaniWeb, and thanks for the sample code. Presumably you noticed that the OP "figured it out and submitted his homework" 10 months ago, so it's a bit late to help him! For future reference, if you are publishing code here, please do not link to an external site … | |
Re: DaniWeb Member Rules 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: Are you talking about the "model" for your game, or the "view" that displays it on the screen? "show" suggests a GUI solution, but linked list is something you would use in a amodel and has no GUI characteristics whatever. Maybe you can expand/clarify the requirements some more? | |
Re: The trick is to get the list box's ListModel (the ListModel maintains all the data that the list displays). That will give you an instance of DefaultListModel which has methods to clear the model, add elements to it etc. | |
Re: Because all your check boxes are in individual variables you will have to code a load of "if" tests to test each box to see if its checked and increment a count as required. It's an easy idea, but very tedious to code. If you put all your check boxes … | |
Re: Trying to get the Graphics and change it outside a paintComponent is always going to be dodgy. You don't know what else is doing anything to that Graphics (not to mention the double-buffering that swing does for you). Plus, it looks like you are getting the graphics for some component … | |
Re: Did you try casting a String to an Integer? I thought not! No, you can't cast String to Integer. You may also notice that the final print (line 18) prints "false". The real reason for no error is that there's no place where that error will be checked for. The … | |
Re: You could try calling *requestFocus* for window B to bring it to the front. Details are in the API doc as always. | |
Re: Are you sure you want to use UDP? An mp3 file would probably occupy many UDP packets. There's no guarantee that a packet will be delivered, nor any way to know you've missed one. Multiple packets may arrive in a different order than that in which they were sent, depending … | |
Re: I don't see any ambiguity in Q1 The two || cases don't fit the "if and only if" requirement because there are arrays for which they will evaluate true even when all the numbers are not be in ascending order (just two ascending will be sufficient). Case d is just … | |
Re: You need to create a Java Project first, then add classes to that. If you're not experienced in Java I strongly advise you NOT to try to learn Eclipse at the same time - you are super-imposing two very large learning curves. Just use a programmer's editor (eg notepad+) and … | |
Re: @methakon Your contributions to DaniWeb are very welcome, but please check the dates before responding to an old thread. @prem2 had his answer 2 years ago, so your answer is (1) not needed and (2) 2 years too late. Your first "helpful" link is for C#, not Java. | |
Re: Is [this](http://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html) the kind of thing you mean? | |
Re: The parameter is passed directly to your main method from whatever command prompt or IDE has started your program. [This link](http://netbeanside61.blogspot.fr/2009/02/using-command-line-arguments-in.html) shows how to pass and use such a parameter in netbeans. ps This is yet another good example of why most of us advise beginners to stay with an … | |
Re: [This](http://introcs.cs.princeton.edu/java/85application/jar/jar.html) explains how to do it | |
Re: If you have an error message you should ALWAYS post the complete text of the message when asking for help. Th exact wording of the message tells us a lot, including the line number inthe program it refers to. In the meantime, you haven't shown any code to initialise the … | |
Re: I don't understand your post. Can you explain in more detail what you want to know? | |
Re: You can use a ComponentListener, something like: myThing.addComponentListener(new ComponentListener() { @Override public void componentShown(ComponentEvent arg0) { System.out.println(arg0); } @Override public void componentHidden(ComponentEvent arg0) { System.out.println(arg0); } @Override public void componentMoved(ComponentEvent arg0) { // not interested } @Override public void componentResized(ComponentEvent arg0) { // not interested } }); | |
Re: When you detect a war (line 137) you could set a boolean to mean "previous game resulted in war". Then next time through you can check that boolean to whether to score double points (and reset the boolean) | |
Re: Exactly what help do you need? You know the drill... full text of any error messages, or a complete description of how the actual behaviour differs from the desired. | |
Re: NPE at which line? The message tells you that. Then look at that line to see which variable(s) could be null. Print it/them to confirm, then work backwards to find out why. (I'm finishing now for this evening, someone else will probably step in...) | |
Re: You declare cal inside the loop. A Java variable's scope is from the immediately preceeding { to the immediately following }, so cal is out of scope after you exit the loop. You could declare (and initialise) it before entering the loop | |
Re: Create a small array of operands (do you mean operators, or maybe operations?) and use a random int to select one element from the array. | |
Re: You only seem to have one boolean for "borrowed" whereas you need one boolean per book. You could use another ArrayList, like for the names etc. ps: In Java the "right" way to do this is to define a class called "Book" that has instance variables for name, borrowed etcetc, … | |
Re: Just an abstract class Soprt, and non-abstract sub-classes Basketball etc. for the data, and a MySports class as the driver? Yes, makes complete sense to me. | |
Re: your array "word" contains one entry for each word in the input. word.length tells you the nunber of entries in the array you can test that value to be >= 3 in an if test if that's not enough of a hint, get as far as you can and post … | |
Re: Please mark this "solved" so people don't waste time trying to help with it, and also so the problem & solution will be part of our knowledge base J | |
Re: Becuase of the way generics were implemented via erasure, creating a new object using the generic type cannot be done in the obvious way that anyone would like to do it. It's not good, but it is what it is. [This link](http://stackoverflow.com/questions/75175/create-instance-of-generic-type-in-java) has a good discussion of the various ways … | |
Re: Maybe there's an error when the code is run? But how would you know since you have told Java to discard any error messages and not to bother you with them? How many times have we said this in the Java forum... Never NEVER *NEVER* do this when writing new … | |
Re: > java.lang.ArrayIndexOutOfBoundsException: 10 > at Salary.Employee(Salary.java:41) This also tells you the problem is on line 41 of Salary.java | |
Re: Your question is so vague and general that there's no possible short answer. Start by studying this tutorial http://docs.oracle.com/javase/tutorial/uiswing/index.html ... then come back here with any specific questions. | |
Re: I'm no JUnit expert, but AFAIK it runs tests at the method level and doesn't have any facilities for testing individual loops etc inside a method. In other words, it treats the method being tested as a "black box" - it supplies data, runs the method, and checks that the … | |
Re: One small point: if ((some boolean expression) == true) is horribly redundant. It's sufficient, and clearer, just to say if (some boolean expression) | |
Re: Passing in a String for concatenation (if I understand our suggestion properly) won't work because String is immutable - you will have to create a new String but have no way to update the reference that was passed in. It would work ok with a StringBuilder. Returning a new String … | |
Re: Every parameter of every public method of every Java API class is documented in the API documentation, and learning to use it is an absolutely essential skill for Java prgrammers http://docs.oracle.com/javase/7/docs/api/ for drawLine it says > public abstract void drawLine(int x1, > int y1, > int x2, > int y2) … | |
| |
Re: Why did you post that uncommented program on a two-year-old thread??? | |
Re: At some stage you will need to tell the ATM which customer/account it is dealing with. You could just add that as a parameter to the deposit & withdraw methods. OR if one customer is likely to do a load of transactions you could have a logon method in ATM … | |
Re: amitie.boo If this is a project that have to submit to your teacher then you can't just copy code from this web site. That's called cheating. We don't help peaple cheat here. If you need any help with code *that you have written yourself* please start anther thread. This thread … | |
Re: You have an error at line 49.The } on line 48 closes the paint method, so the following lines are not part of any method. EXecutable statements like those must be inside a method. Don't worry about any runtime errors yet. Runtime results will be unpredictable and meaningless until you … | |
Re: This is fully described in the Java Language Specification section 15.16 "Cast Expressions". | |
Re: This always happens with floating point values. There is no exact binary fraction that corresponds to decimal .025 so you get the nearest binary value, which is nearer to .024999 You can use a formatting method (eg printf) to display the result rounded to the right number of decimal places. | |
Re: This is a good example of why variable and method names are important. With a method called "compareValues" it's totally unknown what returning true or false will mean. Change the name to allValuesAreDifferent and the fact that the logic has true and false the wrong way round jumps straight out … | |
Re: What *exactly* are the problems you are having (complete error messages, actual vs expected behaviour etc)? | |
Re: Use the angle to split the velocity into its horizontal and vertical components. For each tick of the clock keep the h constant, but add a small downwards increment to the vertical velocity (models the acceleration due to gravity). DIsplaying the results is stanbdrad stuff - you'll find what you … | |
Re: Declare and initialise the integer outside the method (but inside the class). That way each invocation of the method will use the same shared ineteger. | |
Re: When you call anything from an actionPeformed the whole of Swing (including GUI updates) will wait until your actionPerformed returns. This is because it's all done on one thread (Swing is not thread-safe). You need your actionPerformed to start a new thread for this code so it can return immediately. | |
Re: Don't put it in your Date class - that's got a clearly defined and very sensible scope now, so don't confuse it. You could call a simple JOptionPane from your main method then pass the input to the Date class. If you wanted to get more elegant you could create … | |
Re: Currency formats assume an input in dollars. To show cents you need a floating point value, not a long which is an integer type. Declare doublePayment as a double, and set it to 10.99 | |
Re: Underlined in red - presumably you are using an IDE? Which one? "Cannot fiond symbol" means you mistyped the name OR that code is outside the scope where the name is defined, probably the latter. Where are those variables defined - in another class? Inside another method? |
The End.