7,116 Posted Topics
Re: http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html#renderer | |
Re: The Integer class has methods for converting ints to Strings in binary, octal, hex, or any arbitrary base. Ditto for converting any of those formats back to int. Check out the API docs for details. | |
Re: So where is your main method? | |
Re: It's time to go back to the requirenments statement. You have a linked list (but why do I suspect that you just copied that from somewhere without really understanding it???), which you can use for the list of Books for each Author, but now you need the Book and Author … | |
Re: WriteOnPanel is (correctly) an instance netrhod, so in your "other" class you need a reference to the instance of LabelStatus that you want to use when you call that method. Somewhere in your code you will create a new LabelStatus object, and you need to pass that into your "other" … | |
Re: I suspect that every threaded implementation could be replaced by a sufficiently cunning non-threaded version, so the question is "when are threads useful?" rather than "when are they necessary?". For your people running about it may make sense to have one thread for each person in that the code is … | |
Re: > a private class? maybe for inner classes, but I definitely wouldn't recommend it otherwise :) The all-important JLS section 8.1.1 says > The access modifiers protected and private (§6.6) pertain only to member classes within a directly enclosing class or enum declaration (§8.5). For example you may have a … | |
Re: Hover the mouse over the red line to see the compiler error message. | |
Re: Make each panel a new class that extends JPanel. Put all the code associated with that panel into that class. From your main window class just create instances of your classes and add them to the main GUI. | |
Re: Different types of data need different compression algorithms for the best results (eg sound -> mpeg, picture -> jpeg). But zip is a good all-round lossless algorithm that is fully supported by the Java API libraries. http://java.sun.com/developer/technicalArticles/Programming/compression/ | |
Maybe it's just me having a "senior moment", but we seem to have lost the facility where you could hover the mouse over a topic's title on the forum listing page and see the first line or two of the post. I used this all the time to get a … | |
Re: The trick to moving contents up an array is that you have to start at the end of the array and loop downwards back to the starting point. If you start at the insertiuon point and loop upwards you just keep duplicaing the value that was at the starting point. … | |
Re: String s1 = "Hello!"; String s2 = "Hi!"; // s1 might '==' s2, but !s1.equals(s2). No, in that example s1 cannot == s2. The == tests for s1 referring to exactly the same object as s2, whereas equals tests for two Strings containing the same sequence of letters. If s1 … | |
Re: This is probably easier than you think, but first, some clarification: Do you mean that the user logs in to your Java application or logs in to the mysql database, or both, in which case how are the two logins related? | |
| |
Re: Looks like those 2 buttons don't have their text set explicitly. maybe? | |
Re: Maybe you get the error because you try to create a second server socket the second time you click connect, but the port is still bound to the original server socket. Your code closes the (client) socket but not the server socket. Try creating just one server socket when the … | |
Re: Your second and third if tests should look like the first one `if(evt.getSource().equals(theAppropriateJBUtton)` then inside those if blocks you can test `bgColor` or `disabledText` as appropriate | |
Re: `string1 == string2` tests for those being exactly the same object (both have the saem memory address), which they're not in your case. The equals method for Strings tests if two Strings contain eactly the same sequence of letters - which is what you need. You'll find the documentation for … | |
Re: You overrode `paint` so you lost all the stuff that normally happens when a JFrame paints itself. Just start your method with a `super.paint(g)` to get all that stuff painted before you add your own drawing. | |
![]() | Re: You need to loop through the argument array and search for each element in turn. ![]() |
Re: In a loop, take each letter from the first word one at a time and see if it is present in the second word. If it is, add it to the list of common letters. | |
Re: Do you mean RGB (red-green-blue)? Anyway the default colours depend on the operating system and/or the Java look and feel that is in operation at any moment. | |
Re: Because all you need isn HTML link to run it in your browser? ps: Swing works in applets as well... | |
Re: `while (sent.charAt(count) != sent.charAt(sent.length()))` This is presumably to limit the loop to the length of the string, but will fail if the last letter is repeated somewhere else in the sring, eg for "abcb" the loop will terminate on the second letter ('b') because it matches the last letter (also … ![]() | |
Re: [url]http://en.wikipedia.org/wiki/String_interning[/url] I've never heard of a reason why you would force allocation of a new String object with [ICODE]new String("daniweb"[/ICODE] as opposed to allowing the compiler to intern it, and right now I can't think of a single reason why you would want to do that... | |
Re: pets is an array of Pets, so `pets[ 3 ].getAction(`) requires the getAction method to be defined for the class Pet, but it's not, it's only defined for GoldFish. I know that you know that ` pets[3]` contains a GoldFish, but that's not something the compiler can figure out. | |
Re: > void perform(){System.out.printIn(this.action); Yet another problem with code formatting - which hides the fact that you have typed printIn instead of println. Confused? I'm not suprised. Your version has an upper-case `I` for India where it should have a lower-case `l` for Lima. | |
Re: In the mouse click handler just create a [I]new AndGate()[/I] or whatever and [I]add [/I]it to the "canvas" (an ordinary [I]JPanel [/I]would do) at the mouse click coordinates (use absolute positioning and a null layout manager for the "canvas"). ps drag'n'drop really isn't that hard - certainly less hard than … | |
Re: Have a look athe dispose() method for your closing window - it closes the window and releases its resources, | |
Re: It really doesn't make a lot of sense to try to split this into two [I]classes [/I]like that, but two (or more) [I]methods [/I]would certainly help make the code easier to understand. Eg: You could create your two arrays in the main method, then pass them as parameters to an … | |
Re: Your diagnosis sounds probable to me. Rather than using invokeLater in the constructor, why not move that up to startGame() so all the startup code runs on the same (swing) thread? | |
Re: That looks OK, but as stultuske pointed out, it's horrible practice to ignore your IOExceptions - much better to catch them and print an understandable error message yourself. You could also use [ICODE]line.contains(keyword)[/ICODE] rather than [ICODE]line.indexOf(keyword) != -1[/ICODE] because it's simpler and clearer | |
Re: I assume you have variables for its position and velocity that you update at regular intervals (Swing Timer) - in which case just add a fixed amount to the (downwards) vertical velocity component on each update. This will result in the downwards speed increasing steadily - just like g. | |
Re: To close one frame and open another you just make the first one invisible (or dispose()) it, then make the second visible (or create new instance of it). If however you just want to pop up a (modal) dialog you would use one of the methods in the JOptionPane class | |
Re: [CODE]public Camera() { ... init(); } public void init() { ... inv = new Camera();[/CODE] When you create a new instance of Camera it calls the constructor, which calls init, which creates a new instance, which calls its constructor, which calls init ... | |
![]() | Re: It looks to me like you have correctly met the requirements of your exercise here. How it's going to work, and how it relates to the classes in the Java API - these are probably not relevant questions. But... Having an empty method in a superclass like that is pretty … |
Re: I wouldn't worry too much about an array, because all you do with that it turn it into a List on line 13. For a clean solution you could write a separate method that reads the file one line at a time and adds each line to an ArrayList. then … | |
Re: Is it a requirement that you use two hashmaps? Could you, for example, create class Result with instance variables name, points, time? | |
Re: Your loop calls move() to update positions etc, but Swing has no reason to update the screen. Call repaint() on your main window to request a screen refresh (which will use your latest values). Your paint method seems to be doing its own double buffering? If so, no need, because … | |
Re: Hi kolibrizas Your help, advice, and assistance are very welcome here. But please don't just post solutions to people's homework for them to copy & paste. All they learn from that is how to cheat. Give them guidance that allows them to learn how to do it for themselves. Thanks. | |
Re: If you don't want anyone to be able to change the mark just don't have a setMark method. If you want to be able to do it yourself, but not allow anyone else, make the method private. | |
Re: You declared MyClass inside MyOwnBM, and you didn't declare it static, so it's just like any other instance member - you can't refer to it without an instance of the MyOwnBM class. See [url]http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html[/url] Unless MyClass needs direct access to instance variables from MyOwnBM, just declare it static, or declare … | |
Re: Why do you have primaryPanel at all? CryptoMainMenu is a panel, so just do the layout and add the button directly on that. | |
Re: remove, not Remove - Java is case-sensitive. HashTable takes only objects for key and value - your code relies on auto- boxing/unboxing to convert between char and Character, int and Integer. Your int cast on line 6 is probably interfering with the auto-unboxing | |
Re: 1. Declare and initialise your ArrayList as as ArrayList of Games to avoid casting and possible errors [ICODE]ArrayList<Game> theDB = new ArrayList<Game>();[/ICODE] 2. htScore is already an int, so there's no need to use [ICODE]Integer.parseInt[/ICODE] - that's just for where the data is in a String. [ICODE] homesum += theDB.get(i).getHtScore();[/ICODE] … | |
Re: int[] myParrot = {1,2,3}; // simpler You can use Random to generate random numbers. I donlt kniw what you mean by "a given set of numbers" | |
Re: A class can have any number of constructors, but they must all have different parameter lists. | |
Re: I can't explain the logic, but the public method is the one that gets called initially (that's why it's public), and the private method is the "helper" (being private it can only be called from within the class). There's no reason why a recursive method can't be void. Recursive just … | |
Re: Small observation: The spec explicitly requires a two argument constructor (year and make). It assigns 0 to speed, but does not have speed as a parameter. |
The End.