7,116 Posted Topics
Re: Beware the trap of confusing a reference variable (ob) with the object it happens to refer to at any particular time. How is ob declared? If its declared as type B then you shouldn't need to do anything. ob can refer to an object of class B or C, and … | |
Re: This info is already on the web. Start with [url]http://java.sun.com/docs/books/tutorial/2d/images/[/url] | |
Re: Because a Stack can contain any kind of Objects, of unlimited complexity, there's no sensible way to provide a generic "print" method that would work usefully for everything that could be in the stack. Hence all the previous advice saying that you have to loop thru all the elements in … | |
Re: TreeMaps are held sorted by key, so if you want to see the values sorted in some other order you need to get the values as a simple collection teams.values() and then use Collections.sort to sort it using a custom comparator that compares raceTeams by their names. | |
Re: You need a recursive solution | |
Re: There's not enough info to be sure, but at first sight it looks like you should have a class Fruit, with name, shape and colour as instance variables. As you read the two files you could create the instances. Displaying the three values together is now trivial - just pass … | |
Re: [QUOTE]is it possible to use try catch exception inside while loop?[/QUOTE] Yes. You often see this in cases where you want to re-try something that may fail (throw an Exception). | |
Re: It depends on why you are displaying the level - if it's to ensure the signal is loud enough, you can just pick a subset of the samples (say 10 / sec) and average them. If you're trying to avoid clipping you need to check every sample and keep the … | |
Re: Maybe s contains a zero-length String (""), so there is no char at (0) | |
Re: Create a parent class Daniweb, with one method "help me with my homework" which takes two parameters: problemDefinition and whatIDidSoFar. If the second parameter is null, throw a NoHelpWithoutEffort Exception | |
Re: If you are going to save session info in the HTML you should also set a timestamp and check for expiry. Otherwize someone could log in, then save a favourite. That favourite would then work weeks later without another login. | |
Re: 4. Only real difference is that Vector is synchronized, ie it's automatically safe to use in a multi-threaded app. ArrayList isn't. ps: You may not think you have a multi-threaded app, but if you use Swing, then you do. | |
Re: Looks like a font issue to me. Unicode is unicode, and there's no way you are going to stop Java using it, but different fonts display different subsets of it, and can be quite inconsistent once you get past 7F | |
Re: Despite what what you think, your code is NOT implementing dorien's algorithm. Check your second loop again. | |
Re: If the max value required is 2^31 this will fit in an int. 2^31+1 won't. | |
Re: Is the whole idea to avoid having a try/catch? In which case you can just put those around a wait() in a MakePause class and handle the exceptions there. Timers will start another task after a certain time, but not do the pause you want. | |
Re: You could lat the function set a public boolean when it's called, then you can check that later? | |
Re: Are you really sure that this is a problem? Processing buffers at the server will take negligible time compared to the transmission times to the clients. Unless you are using some kind of broadcast technology the data still has to be sent to each client, so where will you reduce … | |
Re: Is your method being called when you resize the component? Just setting the preferred size doesn't necessarily mean that the component [B]will [/B]be resized. Depending on what layout manager you are using you may need to set the minimum, maximum and preferred sizes to get the result you want. | |
Re: You'll probably have to read the file into the table when the app starts, and re-write the edited data back at the end. You can do direct-access in-place updates of a file, but it's not easy or particularly safe - not recommended. Where does the map come into it? | |
Re: You can use an anonymous inner class. Something like: [CODE] new Thread(){ public void run() { // some lines of code } }.start();[/CODE] | |
Re: Calendar is an abstract class, so it's designed and built to be extended (the concrete sub-class you normally use is GregorianCalendar). You should be able to have some fun extending it for a custom calendar, although the JavaDoc doesn't have enough info to tell if you can safely change things … | |
Re: One class for nodes(personName), one class for edges(node1, node2, weight) . Analysis class with methods to traverse the graph to find what you're looking for. Start with a really trivial case and work upwards. Just get stuck in and see how it goes. | |
Re: Read every line but ignore every other one - ie read/read/print/read/read/print etc | |
Re: You shouldn't try to call paintComponent like that, only in the context of overriding paint(...) or somesuch where you already have the Graphics context and Swing knows that you're doing it. If you want to force a repaint call repaint(). | |
Re: Whether you have an array, linked list, or any other kind of collection, you are only talking about the way the [B]references [/B]to the rooms are stored. Java references use no noticeable memory compared to the Objects themselves, so your friend should not worry. Chose your array/list etc based only … | |
Re: Stephen: just a quick aside - how did you get the java tags into your message without them being interpreted as java tags? | |
Re: If you can render the file into a Java window, then you can also print it. see [url]http://java.sun.com/docs/books/tutorial/2d/printing/[/url] So this come down to asking "what file types can you display on Java?" PDFs can be displayed using Adobe's own free Java pdfviewer. For MS word docs you'll need to search … | |
Re: What thread does your findNext run on? Is it on the Swing thread (started in reponse to a user input)? Real-time UI updates like this typically fail because the "worker" code is running on the Swing thread and thus blocks Swings normal UI activity until it finishes. Sleeping doesn't help … | |
Re: This may sound trivial, but... write Java programs! Pick areas of Java you are unfamiliar with and develop an app using them. You'll learn an awful lot that way, and it will be 100% useful stuff you're learning. | |
Re: [QUOTE=masijade;883176]P.S. Two full-fledged Frames in an application is [i]usually[/i] a mistake. Especially when one is opened as a result from the other. [i]Usually[/i] that "second" Frame should be a Dialog (i.e. extend JDialog rather than JFrame in the "second" Class).[/QUOTE] Very interesting. Why is that? | |
Re: [I]throws [/I]appears as part of the declaration of a method. It tells you that when you call that method the named Exception may be thrown by that method, and that you need to handle it in some way. | |
Re: Short version: If you refer to a class in a package, the JRE will search all the directories in the current classpath for a folder or jar with the same name as the package, then search in there for the class. So your classpath must reference the folder/directory that immediately … | |
Re: Your code looks 100% OK to me. If the magpie gets the right int "before the squirrel has put it", then this implies that things are working OK - otherwize the magpie would just get the previous int twice. Maybe when the magpie gets the int it should reset seq … | |
Re: Looks OK to me apart from nextInt being a method, and thus needing a pair of (). You should always try compiling before posting here, most Java error messages are pretty informative, and you should be able to fix many of the problems yourself. | |
Re: Small error in your thinking: you don't paint a layer - you just paint the things in the JLayeredPane and the "layers" determine which things get painted on top of which. So, you can simply add three things (eg JLabels) to the JLayeredPane, setting their depths appropriately, then override the … | |
Re: Also note that resource names in jars are case sensitive, windows file names are not. | |
Re: Maybe you can use the java.awt.Robot class. This was intended for automating tests of a GUI, and allows you to post mouse and keyboard events directly onto the host operating system's event queue. [url]http://java.sun.com/j2se/1.6.0/docs/api/java/awt/Robot.html[/url] | |
Re: Continuing from what Vernon said - to display an object (account) in a GUI you need a reference to that specific object, which typically comes from (a) a prior bit of GUI where you select an account or (b) the object itself if it decides it wants to be displayed. … | |
Re: You could use a server application at one end, client at the other. Transfer a load of (random?) data from one to the other and see how long it takes. Java has full support for making connections across a network, start with a look at Sockets and ServerSockets in the … | |
Re: Quite a few people have tackled the same task and discussed various problems and solutions relating to it here. Just look. | |
Re: A robust program won't break easily. It will check for and handle all kinds of user and other errors without crashing. A simple example: it may prompt the user to enter a number; a non-robust program will fail if the user enters "a", a robust program will diagnose the error … | |
Re: Apart from all the issues around accesors, the if statement fails because the thing in the brackets ater the "if" must evaluate to a boolean true/false. Your code[icode] if(!student.setCreditHrs(hrs))[/icode] will only work if setCreditHours returns a boolean value. | |
Re: You need to share with us the class and line number where the error is thrown | |
Re: In getSubTaught() you loop thru all the members of the array, regardless of how many have actually been populated. You only set element [0], so when the loop hits element [1] you get a null pointer. | |
Re: Post with [code=java] because the colour coding will help. At a quick glance looks like you missed the final } on the main method before starting the next method definition. (ps: getHandValue should be a method in the Hand class, don't you agree?). Please don't try to combine your classes … | |
Suns Java style rules specify that accessors should follow the getX/setX pattern, and most Java API mathods follow this... except for some very common exceptions such as: String length() enum name() [NB new to 1.5, not a legacy!] ArrayList size() etc It seems that there is another pattern operating here: … | |
Re: Do you mean prints nothing, or just "c:"? Because your code just seems to print the results of the listRoots. You do call listFiles, but you do nothing with it. |
The End.