7,116 Posted Topics
Re: Lines 2,3,4 also suspect, the array references will only be executed if the array index is negative and therefore out of bounds. 6,7 seem to take xy coords in the range 1024,768 and scale them to fit the actual size of the current component. They also invert them so the … | |
Re: It's easy to split up a string into an array of strings, using (eg) a blank as a delimiter [CODE]String s = "abc 123"; String[] parts = s.split(" "); // now parts[0] = "abc", parts[1] = "123"[/CODE] To convert the score from String to int you can use the Integer.parseInt … | |
Re: If you are on version 6 Java you can directly call methods written in scripting languages such as javascript [url]http://www.javabeat.net/articles/13-introduction-to-java-60-new-features-parti-2.html[/url] This could be a good format for user-defined algorithms because (a) the syntax is simple and (b) you can call them, in source code form, directly from your Java code … | |
Re: Results is an array, and you can't append to an array with +=, that just works for numbers and simple Strings. You need to keep track of how many elements of the array you have already used so that you can put the new String into the next available empty … | |
Re: Where is button defined. Is there more than one? | |
Re: Have a look at the java.util.Random class in the API. You can use this to select random letters etc from your arrays. | |
Re: Or: Write a method to convert a date (int yyyy, int mm, int dd) to the number of days after Jan 1st 1900 (or some other convenient earliest date) - something along the lines of[CODE]int daysAfterJan1st1900(int yyyy, int mm, int dd) { return (yyyy - 1900)*365 + (something for leap … | |
Re: Separate the mortgage logic & calculations from the user interface. Put them in their own class, with its own variables, and provide public methods that the user interface can call to set the variables and get the calculated mortgage figures. Now you have 2 classes; put each one in its … | |
Re: lines 92-98 the editing has got screwed up here - Object source = e.getSource(); needs to inside ActionPerformed | |
Re: Extra } at end of line 36? Adopt a standard for where you put your { and } and stick to it to avoid this kind of problem. | |
Re: Suggest you try testing "image" to see if it's null just before line 19. There are often problems with file names & default directories when reading images (or any other files). ps: I don't understand why you have so many JPanels, a lot of them have only 1 component in … | |
Re: I'm finding it hard to understand exactly what you are trying to achieve here. F contains a HashTable; in P you want to perform a lookup on that HashTable - is that right? If so, you can: 1. Make the HashTable public in F so P can access it directly … | |
Re: In the time it took to create that post you could have typed [B][I]how to read image file using io stream in java[/I][/B] into Google and immediately got a load of examples | |
Re: Never - that is NEVER - use sleep anywhere near Swing. Your while(true) loop runs on the EDT and never returns, thus blocking everything. For that kind of timing use a javax.swing.timer Use it to call your button changing method every x millisecs. In that method just change the icon … | |
Re: You can terminate a Java program immediately by executing System.exit(0); You can do this, for example, if the user types in 'N'. If you have open files or network connections etc you should close those first, but in this case there's no such tidy-up needed, so keep it simple. | |
Re: What are the line numbers of those 5 errors, or do you expect us to guess? "cannot fond symbol" usually means a mis-typed name, or trying to use a variable outside its scope. | |
Re: [CODE]17. if(order.length > 0){ 18. out.println(order[1].getPhoneType()); 19. }[/CODE] If order is of length 1 this code will always give an NPE (arrays are zero-based) Was it intended to be a loop?, as in [CODE]for (int i = 0; i < order.length; i++ ) { out.println(order[i].getPhoneType()); }[/CODE] | |
Re: This is not enough informtion for anyone to be able to help you. Please post the code where the error happens (in code tags) and the exact complete error message. | |
Re: One small suggestion: This code will crash and burn horribly if presented with parameters like (3,2) or, more subtly, (-2,-3). A simple replacement of the == on line 4 with a >= will protect against these nastys, as will the even simpler replacement of lines 4,5 with if (n1>n2) return … | |
Re: Why not just build the string userName + " " + password + "\n" and use indexOf to see if that complete String is present in the textarea | |
Re: Unless there's some other code somewhere else, this code creates an Account object and updates it IN MEMORY. When the program exits, all that info is lost, so next time you run it you are back to square 1 again. To keep the account info from one run to the … | |
Re: Lines 60-62 In the loop you remove 1 char from endstring with the intention of adding it to begstring on for the call on line 62 line. Problem is that you remove the char THEN you try to get it by using charAt, but it's too late, you've already removed … | |
Re: Extra }; after return year; Missing () after public Movies Please post code in code tags next time. | |
Re: An enum is just like a class that has a number of instances defined at compile time. You can think of it as if Fishes is a class, with exactly two instances. BURI and AMNON are like two public static final variables that hold references to the two instances. Lines … | |
Re: [QUOTE]Why am i getting this error? [/QUOTE] What error [B][I]exactly[/I][/B]? | |
Re: Hi there! Welcome to DaniWeb You'll find lots of people here ready to help you with your Java problems, just remember to do as much as you can before posting a question, and keep your questions as specific and precise as you can. If you have an error, post ALL … | |
Re: Not as such, but in Java you use packages and sub-packages to group classes that share things within the package, but not outside it. Have a look at Java's four scope options - private, (default), protected, public. | |
Re: Place an ex.printStackTrace() in EVERY catch clause. Never ever ever do what you do in lines 45/46 if you want any chance finding bugs. When posting here always post the full text of the exception stackTrace, and make sure we have a listing of the code lines it refers to. | |
Re: So what did the compiler show you? Do you want us to guess? I guess [B]work? this Will[/B] do I win the cigar? (Although anyone who deliberately defines their own public class with the same name as a java.util class deserves any and all trouble they get) | |
Re: No, don't bother. If desPanel is not available then that revised line 12 won't work either. | |
Re: JFrame has a paintComponent too. You can use this to paint whatever you want as the background for that JFrame. Check that everything inside the JFrame has setOpaque(false) if any controls are obscuring the background. | |
Re: Very possible. In fact the Java API has all the things you need to do this without too much trouble. Have a look at he Server Socket and the Socket classes. Basically you open a ServerSocket on an arbitrary port the server, the client then opens a Socket connection to … | |
Re: You asked this (and I answered it) in your previous post: An easy way is to create it when you build the window at the start, but make it invisible (setVisible(false)). Then when you want it to appear make it visible and pack() your window again. | |
Re: Do you want the second text field to appear only when needed? An easy way is to create it when you build the window at the start, but make it invisible (setVisible(false)). Then when you want it to appear make it visible and pack() your window again. | |
Re: Hello again NewOrder. It looks like you just drove Norm away again. I've had a chance to re-charge my batteries, so I'll give this a quick try. 1. Going to "ArrayList<object>" won't help. 2. Do you just want to search on the student's name? If so, this is the key … | |
Re: You can convert the number to a String then extract every char that is one of '1', '3' etc from that String. | |
Re: You already asked the same question in your previous thread. Please do not double-post. You teacher is being silly. You cannot overload pop() with no parameters, and there is no parameter needed for a pop. Serena5 already gave you good advice [QUOTE]have two methods: int popInt() and float popFloat()[/QUOTE] | |
Re: [QUOTE]Can you suggest some smaller problems that help me to be familiar with this class so that i can implement this in my project. [/QUOTE] Firstly, that's the right question. So, create a small graphic image file (use any paint program you like),, maybe 10x10 pixels, with a small block … | |
Re: [QUOTE]replace the name of the method: public void paintComponen(Graphics g) by public void paint(Graphics g) [/QUOTE] Unless you have some special reason, this is not a good idea. Sun's doc makes it clear that you should always override paintComponent rather than paint unless there's a specific reason not to [url]http://java.sun.com/products/jfc/tsc/articles/painting/#callbacks[/url] | |
Re: Not sure what your problem is here - just use ImagePanel instead of JPanel as the container for all your components. You'll have to make sure they are all setOpaque(false) for the image to show through. You can adjust the image size to fit the panel by calling getScaledInstance(...) on … | |
Re: I haven't seen an example of how JScrollPane works when it has no contents - maybe that's your problem? Try it with something in it, even a humble JLabel with a short text should be enough. [CODE]JScrollPane scroll = new JScrollPane(new JLabel("Hello")); add(scroll);[/CODE] ps the getContentPane() has been redundant since … | |
Re: How about a HashMap<String, ArrayList<String>> ? Hashmap has photo name as key, list of keywords as value. Get list of keywords for a photo is trivial, list of photos for a keyword is easy using contains(keyword) on each of the keyword lists in a loop. | |
Re: All your methods and variables must be inside a class. On line 20 you have the } that ends the class definition, so everything after that is NOT in a class. Once you have closed a class definition with its final } the only things can can follow are a … | |
Re: w and h look dangerous - suggest you make them local and set them explicitly from the img itself at the start of this method. I'd print them out here as well, just in case. | |
Re: kramerd: that is [I][U]so [/U][/I]neat. Thanks for making my day! J | |
Re: What do you mean, exactly, by randomise? To put an image in a JLabel create your image as an ImageIcon, then use JLabel's setIcon method. The API doc has all the details. | |
Re: These are methods of the String class. Yoou will find all the reference material for all the Java classes on Oracle's web site. Here's String to get you started. [url]http://download-llnw.oracle.com/javase/6/docs/api/java/lang/String.html[/url] | |
Re: Exactly which line is giving the NPE? Is it in getAppComboBox() - where's that code? |
The End.