- Strength to Increase Rep
- +6
- Strength to Decrease Rep
- -1
- Upvotes Received
- 53
- Posts with Upvotes
- 51
- Upvoting Members
- 29
- Downvotes Received
- 5
- Posts with Downvotes
- 5
- Downvoting Members
- 5
Re: Below is some code I took from a recent project with a JFileChooser. I hope this is what you mean. The class this was in extended JFrame. [CODE] private JFileChooser chooser = new JFileChooser (); //....// chooser.setDialogTitle ("myTitle"); chooser.setFileSelectionMode (JFileChooser.FILES_ONLY); chooser.setAcceptAllFileFilterUsed (true); chooser.setFileFilter (new ExtensionFileFilter (".txt", new String[] {"text" })); … | |
Re: What I can see from the picture, is that you need to clear your screen on a repaint(). Two ideas: - Call super.paint(g); in the first line of your paint method. This is the paint method of the super class, it might help. - Call a clearRect(0,0,getWidth(), getHeight());. This clears … | |
Re: Add this in the method you want to launch your JFrame in. [CODE]JFrame frame = new JFrame("Title"); frame.setDefaultClose(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.add(new JLabel("new window!"));[/CODE] | |
Re: The code looks good, is there any problem that we can help you with? | |
Re: What have you tried? Show some code, and what you need. We will NOT do any of your homework, just help you with the problems with it. | |
Re: Did you upload the .class file to the same directory as the HTML file? | |
Re: Please use code tags to display code on this forum, to make it more readable for the people that have to answer you. Also, please try to construct normal sentences, so we will be able to understand you. Ontopic: You can do exactly what you already showed. [CODE]boolean bool1 = … | |
Re: This sounds like a homework assignment, rather than a question. Post the following in this thread before anyone here will help you: - Your code - Your problem - What you have tried so far Thanks, we are not a homework factory here | |
Re: See the screenshot, I get a value of 147! No change in your code... PS, What do you mean by 'sometimes'? Usually programs give the same output, whether you run them once or 100 million times... | |
Re: [CODE] public class TestProg2{ public static void main(String args[]){ String filler1="Rank"; String filler2="Suit"; Card card = new Card(); System.out.println(card); } } class Card{ public String Card(){ String test="of"; return test; } public String toString () { return "This is the toString() method in the Card Class"; } }[/CODE] | |
Re: That is NOT an error of Java, you cannot instantiate an abstract class, because it is abstract! You shoul override it with another class, override the abstract methods in that class, and now you can create objects from that class! | |
| |
Re: I think you need to remove the extension of the ArrayList<>. [CODE] public class GroceryList { ArrayList<GroceryItemOrder> list = new ArrayList<GroceryItemOrder>(); public GroceryList(String name, int quantity, double unitPrice){ // do something nice with the parameters } public void add() { GroceryItemOrder tempGIO = new GroceryItemOrder(); // do init... list.add(tempGIO); } … | |
Re: Ah, overloaded constructors. A question from my side, how much does your child know about overloading? I'll try to explain: We have a class, Box, and we want to have three constructors for it, one for each possible way to make class. The first possibility is a box of which … | |
Re: Please use the CODE tags, to make the code readable. Your code looks OK, what's actually wrong with it? A tip for any future Java coding: Use Java naming conventions: Classes start with a capital letter (MyClassIsThis), and variables and methods start with a lowercase letter (myMethodIsHere, myVariablesName). | |
| |
Re: What is the OP asking: books or YouTube? Please! OT: Check this thread on SO: [url]http://stackoverflow.com/questions/477748/what-are-the-best-c-sharp-net-books[/url]. It should help you out. | |
Re: [CODE]Integer.toHexString(myInt)[/CODE] | |
Re: Please, use the following for your labels: [CODE] JLabel [] labels = new JLabel[20]; MyClass() { setLayout(new FlowLayout()); for (int i=0; i<labels.length; i++) { labels[i] = new JLabel (String.valueOf (i+1)); add(labels[i]); } }[/CODE] | |
Re: Try new Boolean(false). Notice the capital letter. boolean is a primitive type, while Boolean is an object. | |
Re: I'll give some steps (you are really going in the right direction): - loop from 2 to the user-entered number - within the loop, loop from the current number to the square root (what you are doing) - if the number is a prime: - print the prime using System.out.print(prime). … | |
Re: This is JavaScript, not Java. Please remove this thread, and move it to a JavaScript sub forum. | |
Re: You are using condensed for loops with your int arrays, which can be tricky. Ints are not objects but primitive types, so if you change it within the loop, the value in the array will NOT be changed. If you use [CODE]for(int j=0; j<students; j++)[/CODE] you can access and change … | |
Re: If you give an object in stead of a String in a method, the object's toString() method is called. In your example, this is happening in the line [CODE]System.out.println(b); // You pass an object instead of a String[/CODE]. What really is executed: [CODE]System.out.println(b.toString());[/CODE] | |
Re: I think the best solution is to: - make a class with: - four variables: x1, x2, y1 and y2. - keep a ArrayList<LineClass> of your generated lines - draw each line in the ArrayList on your JPanel using g.drawline(line.x1, line.y1, line.x2, line.y2) where line is the element of the … | |
Re: In class A: [CODE]void myMethod () { B b = new B(); b.theMethodOfB(); }[/CODE] This also works when B has overridden a method from A. See [URL="http://docs.oracle.com/javase/tutorial/java/IandI/override.html"]http://docs.oracle.com/javase/tutorial/java/IandI/override.html[/URL] for more info | |
Re: Why are you not using JPanels as tabs? You can just add those to the JTabbedPane, and add any components to each tab you want! | |
Re: @rotten: I think the best way to improve logic is doing it a lot. Keep making problems and solving problems, and you will find that the things you had problems with before, will be very easy. In my opinion books won't help, unless you don't understand a basic concept of … | |
Re: Why do you have the inner loop with c? You don't do anything with b, and all you will get Loop terminated 0-5 printed 6 times. What exactly do you want? |