202 Posted Topics

Member Avatar for TahoeSands

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 …

Member Avatar for Ezzaral
0
82
Member Avatar for sciprog1
Member Avatar for sciprog1
0
239
Member Avatar for fahadyousaf

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.

Member Avatar for kramerd
0
239
Member Avatar for Jonil

1. move line 19 to before line 13. 2. move lines 21-28 to in between lines 16 & 17.

Member Avatar for kramerd
0
158
Member Avatar for bibiki

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.

Member Avatar for kramerd
0
202
Member Avatar for Transcendent

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 …

Member Avatar for kramerd
0
228
Member Avatar for gedas
Member Avatar for gedas
0
97
Member Avatar for titan5

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, …

Member Avatar for afas87
0
4K
Member Avatar for LianaN

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 …

Member Avatar for kramerd
0
676
Member Avatar for LianaN
Member Avatar for rayden150

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 …

Member Avatar for kramerd
0
229
Member Avatar for sciprog1

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 …

Member Avatar for sciprog1
0
188
Member Avatar for sirlink99

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 …

Member Avatar for kramerd
0
153
Member Avatar for rayden150

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 …

Member Avatar for kramerd
0
112
Member Avatar for Zibo

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]

Member Avatar for Zibo
0
186
Member Avatar for divyakprabh

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.

Member Avatar for divyakprabh
0
130
Member Avatar for sirlink99

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]

Member Avatar for kramerd
0
216
Member Avatar for akinfemi

You need to look up the documentation for GImage. Where does this class come from?

Member Avatar for kramerd
0
109
Member Avatar for BLUEC0RE
Member Avatar for BLUEC0RE
0
142
Member Avatar for hwalsh

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]

Member Avatar for Overbooked
0
2K
Member Avatar for shakssage

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 …

Member Avatar for shakssage
0
1K
Member Avatar for lee.j.baxter

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

Member Avatar for kramerd
0
228
Member Avatar for hiks

I don't think anyone here knows what that string of words means. Can you describe what you are trying to do?

Member Avatar for kramerd
0
122
Member Avatar for orkuncanbay

[URL="http://quizstar.4teachers.org/"]This site[/URL] might be what you are looking for?

Member Avatar for orkuncanbay
0
185
Member Avatar for flyingcurry

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 …

Member Avatar for apines
0
177
Member Avatar for amit.hak50

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]

Member Avatar for apines
0
202
Member Avatar for rational_
Member Avatar for minimi
Member Avatar for intes77

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 …

Member Avatar for intes77
0
443
Member Avatar for jemimaloh

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, …

Member Avatar for jemimaloh
0
99
Member Avatar for 080346

Try [icode]setVisible(false);[/icode] to hide and [icode]setVisible(true);[/icode] to show.

Member Avatar for kramerd
0
88
Member Avatar for Iamthecheese

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 …

Member Avatar for kramerd
0
184
Member Avatar for BboyRodimus

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.

Member Avatar for kramerd
0
501
Member Avatar for Roy1287
Member Avatar for Chalandria

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 …

Member Avatar for Chalandria
0
165
Member Avatar for seekdestroy

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 …

Member Avatar for apines
0
13K
Member Avatar for CompSci_Guy

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 …

Member Avatar for Taywin
-1
1K
Member Avatar for Donnovan

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 …

Member Avatar for Donnovan
0
101
Member Avatar for Awesomeness

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.

Member Avatar for Awesomeness
0
112
Member Avatar for SomeNewGuy

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 …

Member Avatar for kramerd
0
113
Member Avatar for akinfemi

Solution: initialize "it" to the empty string: [icode]private static String it = "";[/icode]

Member Avatar for kramerd
0
83
Member Avatar for chmo

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 …

Member Avatar for masijade
0
378
Member Avatar for wowz

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.

Member Avatar for kramerd
0
181
Member Avatar for ZozOQ

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 …

Member Avatar for kramerd
0
192
Member Avatar for adaniel058

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 …

Member Avatar for kramerd
0
235
Member Avatar for Checkerboz

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 …

Member Avatar for Dhruv Gairola
0
167
Member Avatar for coco24

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 …

Member Avatar for kramerd
0
145
Member Avatar for Pushpasheela

Can you please be a little more specific? What is your code doing? What do you want it to do?

Member Avatar for kramerd
0
138
Member Avatar for Andy_Parr
Member Avatar for JamesCherrill
0
640
Member Avatar for triumphost
Member Avatar for kramerd
0
295

The End.