7,116 Posted Topics

Member Avatar for amrita111
Member Avatar for ahmed_fawzy

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]

Member Avatar for JamesCherrill
0
183
Member Avatar for lashbandi
Member Avatar for JamesCherrill
0
804
Member Avatar for NickJoe

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).

Member Avatar for JamesCherrill
0
284
Member Avatar for himanshu1051

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

Member Avatar for JamesCherrill
0
154
Member Avatar for Java NOOB

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?

Member Avatar for JamesCherrill
0
134
Member Avatar for Poopster01

[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?

Member Avatar for Akill10
-1
326
Member Avatar for haribasker

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?

Member Avatar for JamesCherrill
0
3K
Member Avatar for JGriffCS

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 …

Member Avatar for JamesCherrill
0
704
Member Avatar for coolcool1980

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.

Member Avatar for coolcool1980
0
3K
Member Avatar for Phatsimo Mosiam

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.

Member Avatar for javaAddict
0
107
Member Avatar for Gsterminator

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 …

Member Avatar for JamesCherrill
0
121
Member Avatar for nallasivam25

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 …

Member Avatar for JamesCherrill
0
347
Member Avatar for StevoLord

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 …

Member Avatar for StevoLord
0
116
Member Avatar for Harliquin

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 …

Member Avatar for Harliquin
0
153
Member Avatar for lorettah

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)

Member Avatar for jon.kiparsky
0
123
Member Avatar for clairvoyance

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 …

Member Avatar for -ordi-
0
192
Member Avatar for sitajaf
Member Avatar for sirlink99

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.

Member Avatar for sirlink99
0
7K
Member Avatar for Latvija13

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

Member Avatar for JamesCherrill
0
123
Member Avatar for javanoob101

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

Member Avatar for javanoob101
0
370
Member Avatar for theurbanist

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 …

Member Avatar for JamesCherrill
0
118
Member Avatar for Amoryethel

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 …

Member Avatar for JamesCherrill
0
163
Member Avatar for curbster

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

Member Avatar for curbster
0
1K
Member Avatar for Neversleepin

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.

Member Avatar for Neversleepin
0
9K
Member Avatar for anuj_sharma
Member Avatar for register86

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

Member Avatar for kvprajapati
0
270
Member Avatar for vin24

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

Member Avatar for JamesCherrill
0
150
Member Avatar for Dharni.Gurnani
Member Avatar for rusl07cl08

the front tires can be within 3 psi of each other: -3 <= (right front pressure - left front pressure) <= +3 back tyres ditto.

Member Avatar for JamesCherrill
0
118
Member Avatar for Darren76

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.

Member Avatar for Darren76
0
240
Member Avatar for k4it0xtr3me

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 …

Member Avatar for k4it0xtr3me
0
149
Member Avatar for purijatin

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.

Member Avatar for purijatin
0
189
Member Avatar for newbie14

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]

Member Avatar for newbie14
0
116
Member Avatar for javanoob101

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

Member Avatar for javanoob101
0
231
Member Avatar for ChiboSempai

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

Member Avatar for JamesCherrill
0
234
Member Avatar for pmark019

You need another loop so that line 23 input=myObj.nextLine(); is inside a loop that iterates until the last line has been entered.

Member Avatar for JamesCherrill
0
220
Member Avatar for HDRG

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

Member Avatar for HDRG
0
195
Member Avatar for DarkLightning7

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.

Member Avatar for JamesCherrill
0
260
Member Avatar for Neversleepin

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.

Member Avatar for Neversleepin
0
846
Member Avatar for AhmedGhazey

Get the text field's Document getDocument() then add a DocumentListener to that - the DocumentListener can respond to each char as it's entered.

Member Avatar for AhmedGhazey
0
89
Member Avatar for ronnieaka

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 …

Member Avatar for JamesCherrill
0
565
Member Avatar for warlord902

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]

Member Avatar for JamesCherrill
0
227
Member Avatar for matrixcool

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.

Member Avatar for JamesCherrill
0
190
Member Avatar for RossR

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]

Member Avatar for javinpaul
0
236
Member Avatar for crazy8
Member Avatar for salmanrauf

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

Member Avatar for JamesCherrill
0
137
Member Avatar for Rona25

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.

Member Avatar for VichuTheWizard
-1
122
Member Avatar for emint
Member Avatar for jsaddam709
0
210
Member Avatar for rayden150

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 …

Member Avatar for jon.kiparsky
0
317

The End.