7,116 Posted Topics
Re: The normal pattern with a base clas and another that depnds on it (eg model & view) goes like this: [CODE]public static void Main(..) { Sudoku theGame = new Sudoku (); SudokuValidator v = new SudokuValidator(theGame);[/CODE] ... then in the constructor for SudokuValidator you take the instance of Suduku as … | |
Re: The API doc for HashSet shows it to be a subclass of Set, and the API doc for Set says "More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2)" So there's your answer. The implementation uses the equals(...) method of your objects to see if … | |
Re: Create ObjectOutputStream / ObjectInputStream on the socket's streams and use writeObject / readObject to transfer an Image object | |
Re: AbstractTableModel is an abstract class, you can't create an instance of it, nor does it define methods for removing rows. Maybe you are thinking of DefaultTableModel - which implements AbstractTableModel and has methods for adding & removing rows. See the API doc for details | |
Re: Before you ask DaniWeb you should ask the Java compiler. Try compiling your code - it's a [I]lot [/I]faster :) When you compile you'll get a load of error messages. Read them very carefully because most will tell you exactly what's wrong with your code. If you still don't understand … | |
Re: Assuming you haven't relied on static variables you can just dispose() your window(s) and create new ones by re-executing the existing startup code ![]() | |
Re: [QUOTE=thines01;1759011]Only one module can contain main() and there can only be ONE main().[/QUOTE] Just for the record: any or every class in your program can have a [ICODE]public static void main(String[] args)[/ICODE] method. It's up to you which one you run when you start the program. Like many other people … | |
![]() | Re: you read the menu choice int from the scanner, but this leaves the newline delimiter unread. Your next read is likely to return "" - ie everything before the next newline. Flush the newline after reading the int. |
Re: There are (as mKorbel said) a number of ways to do this, but in my personal opinion the easiest way is to subclass JPanel and override paintComponent to draw the image directly into the panel. Once you've done that all the rest of using the window (layout manager, adding conponents) … | |
Re: You can open a file in append mode if that's all you need. | |
Re: That's a very detailed specification that tells you pretty much everything you need to know. This shouldn't be too hard if you just start and then work incrementally through the spec implementing what it says. Start with the "process table" and a couple of queues (use the standard classes from … | |
Re: putClientProperty / getClientProperty methods inherited from JComponent allow you to associate anything you want with any JComponent. | |
Re: I googled ThreadPoolExecutor and immediately found loads of tutorials and examples for the use of this class. If your Google is broken I can forward some of them to you :-/ | |
Re: You can write a Date object by using the SimpleDateFormat class with a format specification that describes exactly how you want it formatted. See the Java API documentation for details. Inputting "any date format" is a much bigger problem - is there any limit or system to the range of … | |
Re: [CODE]String blink = new String(chunk); System.out.print(blink[/CODE]); Doesn't that mean that you have every line of console output in the String blinbk before it's written to the console? | |
Re: Come on now Zaad! You have been here long enough to know that you should always include the line number when you post an error message! But presumably it's line 35/6 - is that URI valid? Does the file exist? | |
Re: First, you could check that the letters are being transferred correctly from your Runtime exec, and if so, how they have been encoded. Try printing the string with its UniCode numerical values, eg [CODE]String s = (the string you get from exec) for (int i=0; i<s.length();i++) System.out.println(s.charAt(i) + " = … | |
Re: All you need to perform the assignment before the test is an extra set of (). ie [ICODE]while ( (ch=br.read()) != '%')[/ICODE] However, you still have a problem because [ICODE]br.read()[/ICODE] returns an int not a char. You can't assign an int (32 bit) to a char (16 bit), although you … | |
Re: SasseMan is right. The only code in your paint method should be actual painting code - roughly speaking that's just the lines that use the Graphics object g, as in super(g) or g.draw... All the stuff about layout manager or adding components (choice, button, radio group, etc) belong in your … | |
Re: Ditto. Maybe you're creating something for each connection or transaction and failing to null all the references to it/them (eg adding them to a List that's not cleared). | |
Re: The problem is most likely in the code where you call the individual animation methods. Can you post that code as well? What thread do you run those calls on? If it's in an actionPerformed or anything like that you have blocked the Swing Event Dispatch Thread (EDT) - Google … | |
Re: 1. Post your code in code code tags so we can read it easily 2. If you have an error tell us what it is! - Exact complete error message(s) including the line number(s) | |
Re: true abd false are boolean values and are not a valid values for a String variable. What exactly do you mean when you refer to a String as true or false? | |
Re: The regex is [ICODE][.:|][/ICODE] (ie any of the three chars in the []) EXCEPT that . and | are special chars in regex and need to be escaped with a \ to indicate that you want to use them literally, ie [ICODE][\.:\|][/ICODE] Next problem is that \ is a special … | |
Re: Set the column width to be wide enough, then place the whole table in a JScrollPane so it scrolls horizontally. See this: [url]http://stackoverflow.com/questions/2452694/jtable-horizontal-scrollbar-in-java[/url] | |
Re: Do you just want to display the result rounded down to 2 dec places, or do you need to perform the calculation and round down that result to2 dec places before doing anything else (eg storing or printing it) ![]() | |
Re: [QUOTE=BlackStar0703;1756153]... does that not mean that in more sophisticated programs there would be hundreds of classes, making it pretty unorganised?[/QUOTE] Yes there will be hundreds of classes, but no. that's not necessarily unorganised, especially compared to the alternative of having all that code but not organised into classes. OO isn't … | |
Re: I can't read the text in the attachments, but anyway... XML is the generalised markup language - HTML is one form/subset of XML. There's all the info you could possibly want on the web, at every level from complete noob to ultimate expert, so I'm not going to try to … | |
Re: ^ yes. And why setISBN? A book's ISBN never changes. Declare it final and require it as a parameter in the constructor(s). Finally DaniWeb Member Rules include: "Do not ask anyone (member or moderator) for help by email or PM" [url]http://www.daniweb.com/forums/faq.php?faq=daniweb_policies[/url] post your questions in the forum so others can … | |
Re: Just get some squared paper and draw the triangle you want on it, then look and see what the coordinates of the corners are, and feed those into lines 7.8.9 of your code. | |
Re: Layout managers are pretty fickle about using or ignoring your component's sizes. You could try setMinimumSize for your panel as well as setSize. | |
Re: If you start the player playing in its own thread, as correctly advised by cOrRuPtG3n3t!x, then I see no reason why you can't just call ap.stop() directly from the Swing thread (eg in a button's action listener) - no need for flag variables etc. (If you can't call stop() from … | |
Re: The code that zeroliken quoted is your problem. Each time you loop with a new value of i you overwrite all the values from the previous pass of the loop. The correct way to do the sieve algorithm is to start with the isPrime array set to all true, then … | |
![]() | Re: Start here: [url]http://www.daniweb.com/software-development/java/threads/99132[/url] |
Re: Duplicate of existing thread [url]http://www.daniweb.com/software-development/java/threads/411255[/url] | |
Re: .class files are the compiled "executables" that can be executed by any Java Virtual Machion (like a .exe can be executed by an i86 machine). You package all the .class files for your application, along with any other resources it needs, into a "jar" - basically a zip file with … | |
Re: The problem is when you run convert for the first time it initialises its variables, including [ICODE]public static float seconds = conv.sec;//THIS COLLECTS THE DATA FROM SEC[/ICODE] but because that var is static the initialisation is done once only, and any subsequent changes to conv.sec are not copied over. In … | |
Re: I think Norm's onto something there. This is from the JComboBox API doc: [QUOTE]public void addItemListener(ItemListener aListener) Adds an ItemListener. aListener will receive one or two ItemEvents when the selected item changes.[/QUOTE] A quick print inside the itemStateChanged method will confirm or refute this. | |
Re: setForeground(someColor); works for me. | |
Re: On line 8 did you put the name of a real zip file? | |
Re: You're going to have to read and re-write all the file starting at the "abc" line and moving everything down by the length of the line. Not a pretty process. If the file's small enough to fit into memory you can simplify the code by reading it all into an … | |
Re: Have you tried using a > to redirect the output messages from the compiler to a file where you can browse them all at your leisure? | |
Re: or, more simply: [CODE] private boolean getBoolean(){ return expression1 && expresssion2 && expression3 ; }[/CODE] | |
Re: [QUOTE=Zhoot;1754235]One way is to sum all the numbers of the row/column/section. If the sum is 45, it's probably correct.[/QUOTE] Unfortunately that's nowhere near sensitive enough - eg the sum of nine fives is also 45. But it does inspire an idea for an improved version... how about summing the [I]squares … ![]() | |
Re: It doesn't help that there is no single universal definition of OOP, but I would say that if you just have static methods and don't declare any classes (other than the one the main method is in) and never use the "new" keyword, then your code has nothing "Object Oriented" … | |
Re: Those error messages don't match the code (look at the line numbers). Please re-post one or both so we have consistent info to look at. | |
Re: There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in doing your homework for you. DaniWeb Member Rules include: "Do provide evidence of having done some work yourself if posting … | |
Re: Those error messages contain valuable information that you aren't sharing with us. What are the exact error messages and which line(s) do they refer to? | |
Re: If the user input 5 you print the 5, then subtract 1, then print the result (4), then subtract another 1 and print 3 etc... until you get down to 0 You;ll have to write the code yourself - but here's an outline of what you need: [CODE]ask the user … |
The End.