7,116 Posted Topics
Re: Its just more of the same... [CODE] ProductTable.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent k){ ProductTable_KeyPressed(k); } public void keyReleased(KeyEvent k){ // do whatever you want with key released event } });[/CODE] | |
Re: [QUOTE].but i still get this error. [/QUOTE] What error? | |
Re: You should get one mouse event for each click. What exactly is happening? Post the relevant code so we can have look - it may be something else (eg re-initialising the array each time the listener is called). | |
Re: There's no such thing in Java as a 2D array. Java has 1D arrays, but each element of that array can be another array (etc). It's a subtle distinction, but important. eg [ICODE]int[][] a = {{1},{2,3},{4,5,6,7}}[/ICODE] defines an array of arrays of ints, but every array is a different size. … | |
Re: int angleInDeg; // this is an unitialised variable... double angleInRadians = Math.toRadians(angleInDeg); // ... which is used here You define angleInDeg then immediately try to pass its value to a method. Obviously that's a mistake. What were you expecting that method call to do in that position? | |
Re: [QUOTE]it wouldn't work since you are forcing character into integer. [/QUOTE] Are you sure? char is a 16 bit integer, int is a 32 bit integer - assignment should be legal? | |
Re: Wow! That's a load of code with no indentation or syntax highlighting. I hope you don't expect anyone to read it. Code tags next time please. Anyway, what help do you need, exactly? | |
Re: The array you pass as parameter is of <T extends Object>, but the method signature requires <T extends Number & Comparable<T>> A type of Object is not a valid substitute for a type of (Number that implements Comparable). You need to define the array that you pass as parameter to … | |
Re: Line 66 instead of assigning the new array to the existing "array" class variable, you define a new local "array" variable which goes out of scope at the end of the method. | |
Re: You have a class and an interface with the same name, and that's not allowed. ps: Java convention is that interface and class names should begin with a capital letter. | |
![]() | Re: Error message means what it says. You are trying to pass a char[][] as a parameter to a Picture constructor, but the only constructor you have defined takes int,int,char as parameters. Either you need to define a constructor that takes a char[][]. or change the offending call to pass the … |
Re: Your code is unreadable because you have not got the right syntax for your code tags, but at a quick scan it looks like this implementation is massively over-complex and thus far too slow for simply logging mouse drag coords. I think you should strip it back to bare essentials … | |
Re: Google the Swing Event Dispatch Thread - this is a standard problem that's well documented - but basically your ActionPerformed method blocks all screen updates etc until it has finished. The right way to handle delays in a Swing GUI is to use a javax.swing.Timer - once again this is … | |
Re: You can't create a new array instance like that. First you create a new array of BankAccounts, giving it a size. This will have all its elements initially null. Then you can store a BankAccount into any of the array elements: [CODE] BankAccount[] accounts = new BankAccount[10]; // create array … | |
Re: 1. Look at the brackets in your while statement. 2. Next time post your code in code tags and post the complete compiler error message (including the line number) | |
Re: Are you really using JDK 1.3? That was released in 2000 replaced in 2002. The language had major upgrades with 1.5, and we are currently on 1.6 Time to update. ps If you really want to give sample code to someone trying to learn the language, please don't use deprecated … | |
Re: I think you will have to set up a HashMap to link the Strings to actual Colors, eg [CODE=JAVA]HashMap<String, Color> map = new HashMap<String, Color>(); map.put("Red", Color.RED); map.put("Green", Color.GREEN); // etc ... String colorName = "Green"; g.setColor(map.get(colorName));[/CODE] Or you could use Refection to access the Color constants by name. | |
Re: You can use the split method (String class) to split your input into an array of words, then check how many words there are, then check each word using isLetter | |
Re: Are your monsters etc rectangles? If not, this is quite hard. Are they Java Shapes (instances of the Shape class) - if so there's a method in Shape that does that. For rectangles you can easily see if they touch/overlap by comparing their top/bottom coordinates to see if they overlap, … | |
Re: To create a string of "n" stars: 1. Have a loop that executes n times and adds a star each time. 2. Start with a string that contains a lot of stars and use substring(...) to get the first n characters from that string. 3. I'm sure there are other … | |
![]() | Re: lines 82/83 you add together the numerators (after getting them over the LCM denominator), but you forgot to divide by the LCM denominator - ie you calc (2*6) + (1*6) when it should be ((2*6) + (1*6))/(6*6) But in any case shouldn't add return a RationalNumber, rather than an int … |
Re: [CODE]if (charInt>=97 && charInt<=122) { charInt -= 32; } // convert lower to upper if (intLetter>=1 && intLetter<=26)[/CODE] When will people ever learn? Of all the world's many languages, English is just about the only one that uses a 26 letter alphabet. Even Spanish and French have accented characters with … | |
Re: I don't think there is any way to delete lines in the middle of a file. What you can do is to copy the file to a new file, only writing the lines you want to keep. | |
Re: The launcher error message suggests to me that the file association for .jar files may be giving you javaw swingset2.jar when it should be javaw -jar swingset2.jar | |
Re: @codewall. Please keep in mind the Daniweb principle: "to keep DaniWeb a student-friendly place to learn, don't expect quick solutions to your homework. We'll help you get started and exchange algorithm ideas, but only if you show that you're willing to put in effort as well." Just giving lazy people … | |
Re: This is a Java forum. That's not Java. | |
Re: the front tires can be within 3 psi of each other: -3 <= (right front pressure - left front pressure) <= +3 back tyres ditto. | |
Re: rndm is your random number generator. num (line 3) is the random number. On line 7,8 etc you compare the guess with (the random number generator) when you should compare it with the random number. | |
Re: I don't know if this helps... but, if you really are desperate, here are some random thoughts, although I can't guarantee any of this ... Language Ref 3.8: [QUOTE]An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter. An … | |
Re: Interesting... for your two cases my little laptop gave me 2126 mSec and 3044 mSec - implying that the first loop takes an extra 900 mSec going from 1000 to 1000000. But if I limit the main loop to just 1 pass, even j<10000000 runs in 1 mSec. | |
Re: The normal way to run a method every 30 secs is to use a java Timer. See the API docs for java.util.Timer (not javax.swing.Timer) for details, or example here: [url]http://www.exampledepot.com/egs/java.util/ScheduleRepeat.html[/url] | |
Re: [QUOTE]I want it to animate my bullet across the screen just by pressing the space bar(not by pressing the space bar mulitple times).[/QUOTE] On KeyPressed start a Swing Timer that fires every 1/n secs and moves the bullet each time it fires. On KeyReleased, stop the Timer. ps what on … | |
Re: You can read the file as a byte array, then convert each byte to a standard hex String representation with something like [CODE]String byteToHex(byte b) { // coded for clarity - could be a lot shorter char[] chars = { ' ', ' ' }; chars[0] = "0123456789ABCDEF".charAt((b >> 4) … | |
Re: You need another loop so that line 23 input=myObj.nextLine(); is inside a loop that iterates until the last line has been entered. | |
Re: NullPointerException ("NPE") means either you are using a variable that hasn't been initialised, or you are using the result of a method that has returned null. Search down the error listing until you find a reference to one of your classes, and that's where the error happened, in this case: … | |
Re: Is that line 79? If so, you need to exit the loop after finding a match - otherwize you just go on to test all the other chards - which don't match. | |
Re: You can use JFileChooser [CODE=JAVA] JFileChooser fc = new JFileChooser(); fc.showSaveDialog(null); File outFile = fc.getSelectedFile(); System.out.println(outFile.getName());[/CODE] There are many other options in JFiuleChooser - see the API doc. | |
Re: Get the text field's Document getDocument() then add a DocumentListener to that - the DocumentListener can respond to each char as it's entered. | |
Re: This is a deep question, and the answer changed with Java 1.4. Unfortunately there is a lot of info on the web that relates to old versions of Java. Here's an authoritative doc from Oracle re Java 1.5 [url]http://download.oracle.com/javase/1.5.0/docs/api/java/awt/doc-files/AWTThreadIssues.html[/url] The most relevant part is [QUOTE]... Prior to 1.4, the helper … | |
Re: Maybe after adding the text you can explicitly force the vertical scroll bar down to the bottom [CODE]int y = // some calc based on number of actual lines - size of viewport myJScrollPane.getVerticalScrollbar().setValue(y); [/CODE] | |
Re: Here's a hint: Start at the nth element. If that's <= the n-1th element then it's not ascending. If its >, then you can go on to check (n-1) against (n-2) etc until you get down to elements 2 vs 1. | |
Re: In Jave SE the Byte class has a constructor that takes a String as parameter: [CODE]byte byteVar = new Byte("0xFF");[/CODE] I don't know if ME will do that unboxing, so maybe [CODE]byte byteVar = (new Byte("0xFF")).byteValue() ;[/CODE] | |
Re: == to test for equality of 2 chars. = is assignment | |
Re: [QUOTE=vincentjohn;1445437]i think that using the try catch finall block is more efficient than using the throws clause.. :)[/QUOTE] It's nothing to do with "efficiency". If your method can sensibly handle the Execption then it should catch it and handle it. If it can't sensibly handle it it should throw it … | |
Re: Well done Vichu - you just rewarded Rona25 for being lazy and dishonest. What did he/she learn from this? no Java, that's for sure, just that cheating is easier. | |
Re: Why the map? Why not just test the button to see if it's checked? | |
Re: Outer loop tests all the numbers from 1 to 50 (i) For each i the inner loop tries dividing it by all the numbers less than i (j) If the remainder is 0 then i is exactly divisible by j , so i cannot be prime and it breaks out … |
The End.