226 Posted Topics
Re: All of the methods in the code you posted are instance methods. The only kind of method that isn't an instance method is a static method and you can recognize that by the `static` keyword. In other words "instance method" just means ordinary method, so you don't need to worry … | |
Re: I don't know exactly why it doesn't work, but I can see some things which you are doing wrong. Your `clipper`s instance variables are being used like global variables to the algorithm instead of using them in a proper object-oriented way, and that just makes your algorithm hard to understand … | |
Re: I see what you are trying to do. You are trying to access the static members of `java.awt.Color` such as `Color.red` or `Color.blue` except that you are trying to do it with a String that contains the words `"red"` or `"blue"`. You cannot use the dot notation that way, and … | |
Re: You can only put `try`-`catch` blocks inside a method body. It is meaningless when placed directly inside a class definition and so the compiler is getting confused and giving you the wrong sort of error message. You probably want most of that stuff to be inside a `public static void … | |
Re: They have certainly chosen a hard way to make a sokoban game by using sprites to draw the grid instead of just laying it all out in an array. It's also awful how they setup `LEFT_COLLISION`, `RIGHT_COLLISION`, etc. as constants representing all four directions but then fail to use them … | |
Re: A boolean is true or false, not text, so there's really no hope for doing a comparison like `answer == true` or `answer == false`; since `answer` is a bit of text it will never be `true` or `false`. What you want is more like `answer == "yes"` because both … | |
Re: I don't know how far you would want to go with it, but if you must add new features to an enrollment system, then I would try to turn it into a fully featured web service that lets people see their classes, their grades, and send messages to other students … | |
Re: Exceptions are best used when something happens outside of the normal flow of your program. Without exceptions you would need to handle every possible situation that might occur when you write an algorithm, and then 90% of your algorithm would be devoted to handling events that happen 1% of the … | |
Re: The first thing your function does is call itself. That seems like it would go on forever and accomplish nothing unless there is something I'm missing. | |
Re: I've never been able to find a really good guide on the subject of drag and drop, but in my experience it all tends to come together pretty painlessly if you just start by making your Transferable, then a TransferHandler for each of your components that needs one. After that, … | |
Re: > I believe that the issue stems from the fact that i close the socket after each received packet, and create a brand new one. Surely you must be right about that. I can't imagine a good reason for closing the socket after each packet. You're practically asking to lose … | |
Re: for(int i = 1; i < arr.length - 1; i++){ for(int j = i + 1 ; i < arr.length-1; j++){ You are testing `i < arr.length - 1` in the inner loop when you probably want to be testing `j < arr.length - 1`. Except that you probably want … | |
Re: Exceptions which are not RuntimeExceptions must be handled explicitly. They cannot be ignored. A method where an Exception may occur can either declare it to be thrown, or catch it. You catch an exception by using something like: try { methodThatMightThrowExceptionA(); } catch(ExceptionA e) { whatIWantToDoIfExceptionAHappens(); } You know that … | |
Re: You can call `comboEmployer.addItem` at any time as long as you are in the event dispatch thread, and I'm sure you are in the event dispatch thread in your `SaveEmpButtonActionPerformed` method. So feel free to add employers immediately or at any time you feel the need, and you can always … | |
Re: In Java ints are represented using 32 bits, so 15 is represented as `0000 0000 0000 0000 0000 0000 0000 1111`, and the complement of that is `1111 1111 1111 1111 1111 1111 1111 0000` | |
Re: Your error message is saying you are trying to convert "Calculate Discount" into an number and that's exactly what you are doing, 3 times. p = ae.getActionCommand(); pf = Double.parseDouble(p); d = ae.getActionCommand(); df = Double.parseDouble(d); s = ae.getActionCommand(); sf = Double.parseDouble(s); You are calling `ae.getActionCommand()` three times as if … | |
Re: Of course what you really want is a 2D array to store the current state of the game, an `x` and `y` variable to store the current location of your little warehouse manager guy, a list of (x,y) target points for the boxes, a javax.swing.JPanel to draw everything, and a … | |
Re: I may be mistaken, but it looks like you are going left-to-right top-to-bottom updating each cell as you go. That's not how the game of life works. You are supposed to update all the cells at once. If you have two cells next to each other, call them A and … | |
Re: You haven't supplied enough information to make it possible for anyone to know. Whatever the problem is, it is not in the code you have shown us. Normally these sorts of problems can only be solved by spotting the problem in code that is supplied. The only other chance is … | |
Re: You can't really pass variables to methods or return variables. You can only pass and return the value of a variable. So `answer` isn't really returned, only the number it contains is returned. You need to use `addobj.add(fnum, snum)` as an expression to get the returned number, such as `System.out.println(addobj.add(fnum, … | |
Re: When you call `graphics2D.drawLine(oldX, oldY, currentX, currentY)` you will also want to add that to a list that records each line that is drawn, something like `history.add(new Line(oldX, oldY, currentX, currentY, graphics2D.getColor())`. Then when you want to send the image, you can just send the `history` list using a DataOutputStream. … | |
Re: s.read(b, offset, readAmount); offset += readAmount; `readAmount` is the maximum amount to read, not the amount that is actually read. The return value of `s.read(b, offset, readAmount)` is the amount actually read. You should also be checking for a return value of -1 which indicates the end of the stream. … | |
Re: if(pos[j].equals(d[i][j])) The value of `j` determines which of `a1`, `a2`, or `a3` you get when `i==0`. And `j` also determines which line of the input file you are on. It seems like you don't really want to use it for both purposes, so it is probably accidental. Notice especially that … | |
I have been struggling with the principles of creating a client-server design where the server maintains a data structure that multiple clients can view and manipulate with various restrictions on which client can access which parts of the structure. I don't know what to properly call a system like that, … | |
Re: You need to do some algebra. The algrebra is not very easy and I haven't worked it all out just now, but I can tell you the sort of thing you could to do to figure this problem out. First, you can forget about using the intersects() method. That's only … | |
I want to create a word processor. It seems like a useful project because I have strong feelings about how modern big word processors like MS Word and Open Office don't do things right, so my solution is to make one with more modest features but with the huge advantage … |
The End.