202 Posted Topics
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 … |
The End.