- 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
124 Posted Topics
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? | |
Re: Your code makes no sense. For example: - When you make a Main object, in the constuctor you make another one, and in that constructor you make another one: a never ending loop. I think you should first start thinking about what you want to code, and then start coding. … | |
Re: @olivia Please start your own thread. You probably mean NetBeans, with a GUI Builder. It's easy, but it doesnt teach you anything. You should look into AWT and Swing, and start building your own GUIs, it's not hard! | |
Re: Use some regex pattern to check the contents of the textbox: if it matches [^0-9,], you have a non-numerical input. | |
Re: Please use the CODE tag if you post code. * check if any numbers are in the correct place * for each digit, if the number is NOT in the correct place, check if the number is somewhere else in the code | |
Re: Use Ctrl+Shift+F when you work in Eclipse, this will format your code. It's very useful when you don't know where you missed a bracket. The formatter will space out the code in the wrong way when you missed one, so you can see where you made an error! | |
Re: Well make a class with a Generic Type: [CODE]class mySet<T> { ArrayList<T> al = new ArrayList<T>(); public void add(T t) { al.add(t); } public void remove (T t) { al.remove(t); } }[/CODE] Something like this? | |
Re: I hope you are familiar to Regex. You can use that to match a set of characters in a string, perfect for you. The test code below is from [url]http://www.xinotes.org/notes/note/1319/[/url]. [CODE]import java.util.regex.*; public class RegExFindAll { public static void main(String[] args) { String str = "You can use a Matcher … | |
Re: You should capitalize the input, and make the code easier to read. A simple example: if (myChar >= 'a' && myChar <= 'd') myInt = 1; | |
Re: I have learned a lot of my Java from TheNewBoston on Youtube. He gives nice comments, and works out a lot better for me than a book. (I have also read books, but the start came from YouTube.) Really many video's, from the beginnings of Java, to full screen games. … | |
Re: I think I see the problem. When the user presses on Remove object from list, the method has a loop. However, everytime you ask an object from the list, you call getCurrent(), nothing to do with the loop. I hope this will solve it! | |
Re: [CODE]for (int i = 0; i < counts.length; i++) JOptionPane.showMessageDialog(null, "The number 1 occurs "+counts[i]+" times \nThe number 2 occurs "+counts[i+1]+" times \nThe number 3 occurs "+counts[i + 2]+ " times \nThe number 4 occurs " +counts[i+3]+ " times \nThe number 5 occurs " +counts[i + 4]+ " times \nThe … | |
Re: If the thread is solved, please mark it as solved! | |
Re: [QUOTE]If I remove the statement, the method does not return anything[/QUOTE] It should, I think you may be removing something else there then the print statement. I don't really understand what you want. Could you explain that a little more? ![]() | |
Re: Did VK_EXCLAMATION_MARK come up as an autocomplete option? I think you have run into the problem that has also been asked on this thread: [url]http://stackoverflow.com/questions/6634375/why-are-some-keyevent-keycodes-throwing-illegalargumentexception-invalid-key-c[/url]. James' solution will work, if I have to believe StackOverflow. | |
Re: First of all, a StrinTokenizer is depricated. You should look into String.split() ([url]http://www.rgagnon.com/javadetails/java-0438.html[/url]), which returns an array of Strings. [CODE]System.out.print(getMonth(dates[0])+"/"+getDay(dates[0])+"/"+getYear(dates[0]));[/CODE] Seems a little strange to me. Why not just: [CODE]System.out.print(dates[0]);[/CODE] Date manipulation in Java is done with the Calendar class. You can just call the after() method to check if … | |
Re: Well, to me the posted code look about right, I need more code, especially the attack() method, to see what goed wrong. Also: [CODE]Pokedex[a] = Pokedex[i]; Pokedex[b] = Pokedex[i];[/CODE] You are putting the two pokemons in the beginning of the list? There might be pokemons there, that you overwrite. | |
Re: Well, what do you have, and what problem do you have with the code? You should always start first, and then we can help you! | |
Re: 1: Use CODE tags to show code. This is unreadable. 2: We are not going to make your homework. Ask a question, and we can try to answer it. | |
Re: I thinking I'd use jQuery to select each square, and change the color. In your for loops you can generate IDs for your squares. | |
Re: You are asking US to make it look better/work better, so that you get a better grade for working harder? You gotta be kidding me. If you have a question please ask it, but we don't do any homework assignments around here. |
The End.