202 Posted Topics
Re: As JamesCherrill says, a JLabel should work. But you can also draw rectangles and strings with your Graphics object. You can paint both whatever color you choose and position them wherever you choose. Look up fillRect and drawString in the documentation for the Graphics class. Note that you can base … | |
Re: You posted your server code twice, and didn't post your client code. Please fix. | |
Re: 1. Please post your code inside code tags. 2. remove [ICODE]while (true)[/ICODE] from actionPerformed in ButtonListener. 3. add [ICODE]cnic.requestFocus();[/ICODE] to the end of your ClearField method. | |
Re: 1. move line 19 to before line 13. 2. move lines 21-28 to in between lines 16 & 17. | |
Re: Actually, JFrame extends Frame from awt, not JComponent from swing. So I don't think paintComponent will work on the frame. It will probably work on a JPanel though. | |
Re: The constructor in your Employee class takes a String (first name), a String (last name) and a double (monthly salary). But in your test program you are trying to create an Employee object using 3 Strings. The error message tells you that Java cannot find a constructor for Employee that … | |
Re: On line 28, put an else and read the next 2 lines from the input file. | |
Re: I don't believe an array in Java can be larger than MAX_INT elements because arrays are indexed by ints. Of course you could use a linked list or some other structure that doesn't rely on indices, but if you absolutely must have an array, you could create your own class, … | |
Re: The documentation for ArrayStoreException says [code] Thrown to indicate that an attempt has been made to store the wrong type of object into an array of objects. For example, the following code generates an ArrayStoreException: Object x[] = new String[3]; x[0] = new Integer(0); [/code] So are you trying to … | |
Re: try [icode]popupmenu1.getSubElements().length;[/icode]. | |
Re: You can also use html format with a JLabel like this: [code] String text = "<html><pre>"; text += "*********<br>"; text += "* *<br>"; text += "* *<br>"; text += "* *<br>"; text += "* *<br>"; text += "* *<br>"; text += "*********<br>"; JLabel label = new JLabel(text); [/code] Note that … | |
Re: 1. Create a panel for the buttons: [CODE] JPanel buttonPanel = new JPanel(); [/CODE] 2. Add your buttons to the buttonPanel 3. Give the frame a border layout: [CODE] m.setLayout(new BorderLayout()); [/CODE] 4. Add the label to the center of the frame: [CODE] m.add(r, BorderLayout.CENTER); [/CODE] 5. Add the buttons … | |
Re: You can create a Timer object (from the swing package, not the util package). You give it a delay (in milliseconds) and an ActionListener, and then you start the timer. After that, every time the timer goes off, the actionPerformed method in the ActionListener is called. So to make your … | |
Re: There are many ways to do this. For example: 1. Serialize the class that stores the data 2. Write out a text file with your data 3. Write out an XML file with your data 4. Write out a properties file 5. Save data as preferences (OS specific) If you … | |
Re: This doesn't answer your question directly, but as an alternative, you can have the JVM load the classes from your jar file using [CODE] java -Djava.ext.dirs=lib\swing.jar; <your class here> [/CODE] | |
Re: I don't know if it applies, but [URL="http://wiki.apache.org/tomcat/HowTo#I.27m_encountering_classloader_problems_when_using_JNI_under_Tomcat"]this link[/URL] might help you. | |
Re: Not sure this is what you are looking for, but here are a couple links that might help. [URL="http://www.exampledepot.com/egs/java.applet/LoadImageApplet.html"]http://www.exampledepot.com/egs/java.applet/LoadImageApplet.html[/URL] [URL="http://www.realapplets.com/tutorial/ImageExample.html"]http://www.realapplets.com/tutorial/ImageExample.html[/URL] | |
Re: You need to look up the documentation for GImage. Where does this class come from? | |
Re: Perhaps this will work? [CODE] if (ob1.getClass() == ob2.getClass()) ... [/CODE] | |
Re: The problem is in printA, you declare the grade array list, which hides the member variable of the same name. Remove this line: [CODE] ArrayList<Integer> grade = new ArrayList<Integer>(); [/CODE] | |
Re: You can do simple animation in Java by using a [URL="http://download.oracle.com/javase/6/docs/api/javax/swing/Timer.html"]Timer[/URL] object (from the swing package, not the util package). You give it a delay (in milliseconds) and an ActionListener, and then you start the timer. After that, every time the timer goes off, the actionPerformed method in the ActionListener … | |
Re: Here are some links. [URL="http://download.oracle.com/javase/tutorial/uiswing/dnd/intro.html"]http://download.oracle.com/javase/tutorial/uiswing/dnd/intro.html[/URL] [URL="http://download.oracle.com/javase/tutorial/uiswing/examples/dnd/index.html"]http://download.oracle.com/javase/tutorial/uiswing/examples/dnd/index.html[/URL] [URL="http://www.javaworld.com/javaworld/jw-03-1999/jw-03-dragndrop.html"]http://www.javaworld.com/javaworld/jw-03-1999/jw-03-dragndrop.html[/URL] By the way, I used the following search terms in Google to find these. java drag and drop tutorial | |
Re: I don't think anyone here knows what that string of words means. Can you describe what you are trying to do? | |
Re: [URL="http://quizstar.4teachers.org/"]This site[/URL] might be what you are looking for? | |
Re: You have a misplaced semicolon at the end of line 21. That means the loop body does nothing, and then after the loop executes, you print the last element of the array and the value of i (which is 5 after the loop executes). I'm guessing that's why your loops … | |
Re: Datatype "int" in Java uses 4 bytes, range -2,147,483,648 to 2,147,483,647, Datatype "long" uses 8, range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. [URL="http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html"](source)[/URL] | |
Re: As the assignment says, you need to use inheritance. | |
Re: Your code looks very confused. Can you explain what you are trying to do? | |
Re: First, if you need more than one char (e.g. "05"), you cannot store this in a char variable because char can only store a single character (e.g. '0'). So your Month, Day and Year variables should be String instead. Second, char in Java can be interpreted as a number, since … | |
Re: The problem is you are doing integer division, which will truncate rather than round as you expect. In Java, [icode]5/2 = 2[/icode] and [icode]2/5 = 0[/icode]. To fix this problem, you need to make one of the operands in the division a floating point type (either float or double). Again, … | |
Re: Try [icode]setVisible(false);[/icode] to hide and [icode]setVisible(true);[/icode] to show. | |
Re: I'm not positive about all the intricacies of templates in Java, but I believe since you have [icode]<T extends Comparable<T>>[/icode] in your class declaration, you can assume that the class for item implements the Comparable interface. That means you can call compareTo, which returns an int, which can be compared … | |
Re: Line 35 in main says [CODE] double min = findMin(NumArray, 0, NumArray.length); [/CODE] Then in [icode]findMin[/icode], line 54 says [CODE] else if ... < NumArray[endIndex]) [/CODE] Remember in Java that array indices go from 0 to length-1. So you can't access [icode]NumArray[[B]endIndex[/B]])[/icode]. You are beyond the bounds of the array. | |
Re: I think since you started the thread, you have to mark it solved. | |
Re: The instructions seem pretty clear to me, so I'm not sure what you're having problems with. Reread the part about what your action listeners need to do and try to do those steps in each of your action listeners. Also note the instructions are very explicit about what belongs in … | |
Re: There's a for loop in Java that lets you go over each element in a collection. It looks something like this: [code] for (<datatype> <variable> : <collection>) { // do something here with <variable> } [/code] A more concrete example. Say you have an ArrayList called myList, and it stores … | |
Re: You are being asked to generate an array of strings. The input variable times tells you how many strings to generate using the grammar. Assuming the generate method you wrote correctly generates a single string using the grammar, then keep that method as a helper, and implement the method asked … | |
Re: If you want to insert a node into the middle of a linked list, you need a loop that moves through the list and a counter that increments at each move. When you have moved through the correct number of nodes, then you need to insert the new node in … | |
Re: I don't think Math.max is what you need to solve this problem. It seems to me that at each level you just want to add 1 to maxDepth. | |
Re: 1. You can use a do...while loop, rather than a while loop so you check the condition at the end of the loop instead of at the beginning. 2. You should put everything from the prompt to enter the website on inside the loop. 3. Think about what the condition … | |
Re: Solution: initialize "it" to the empty string: [icode]private static String it = "";[/icode] | |
Re: You should probably create a class to represent a band that has a name and a description. Then you can use substring on the name part, and you should be comparing the substring to the user input. For example, say the user input is in a string called answer. Then … | |
Re: Stack overflow usually means you have an infinite recursion. Try stepping through the code in a debugger, or putting in some print statements so you can see where the recursion is not stopping. Hint: each recursive call should make the problem simpler so eventually the algorithm termindates. | |
Re: BufferedReader's readLine() method is a blocking call, so it looks like your program is working as intended by Java, if not by you. When you call readLine(), your program is supposed to wait until there is a line to read from the input stream. If you don't want the program … | |
Re: Without seeing your Contact class and your input file I can't know for sure, but it could be that your problem has to do with reading a string vs. reading a line from the file. Right now your read loop looks something like this: - Check if the file has … | |
Re: As stokes1900 is saying, you need a main method, not a main class. You can put a main method in your Bankaccount class, or better, you can write another class to test the Bankaccount that has a main. Did the author of the book you're reading provide something like BankAccountTester … | |
Re: When you call a method like [icode]canvas.drawOval(100, 50, 200, 200);[/icode], the x and y coordinates are offset from (0,0). In other words, this method will draw an oval with the top left corner of its bounding box 100 pixels to the right and 50 pixels down from the top left … | |
Re: Can you please be a little more specific? What is your code doing? What do you want it to do? | |
Re: Sorry, I only saw the 1st page of this thread. Please ignore my previous post. | |
Re: That is not Java code you posted, it is JavaScript. Try posting your question in the JavaScript forum. |
The End.