7,116 Posted Topics

Member Avatar for speakon

That's good progress - you learn fast! Let's get rid of the duplicated code for getting the value of a card... maybe a method that has all the "if card equals... value = ..." lines `public static int getCardValue(String card) { ...` then you can simplify code like this for(int …

Member Avatar for speakon
0
1K
Member Avatar for GlenRogers

If a class has a private attribute, and the developer didn't supply a setter, that means you're not supposed to set it (eg look at the get methods for the String class - you won't find any corresponding set methods because they don't want you to change a String object …

Member Avatar for GlenRogers
0
288
Member Avatar for deshazer.jad

You can read your big file into a BufferedImage, then use its getSubimage method to pick out the separate icons, and pass those to the ImageIcon constructor

Member Avatar for deshazer.jad
0
271
Member Avatar for gosensgo87

That means you tried to run the program when it still had error(s) that prevent it from compiling. In Eclipse look for the little red x at the left of the code, red underlining under the code in question, and a red block in the vertical scroll bar to show …

Member Avatar for JamesCherrill
0
311
Member Avatar for brunoccs

Suppose class B extends class A and overrides its doIt method. Consided this pseudo code A myObject; while ... { ask the user a question if (user reply is "A") myObject =- new A(); else myObject = new B(); myObject.doIt(); // sometimes this is A's version, sometimes it's B's }

Member Avatar for JamesCherrill
0
152
Member Avatar for godzab

Burning the CPU in an infinite loop is a very bad way to look for changes. Add a `TextListener` to your JTextField. It will be called once every time the text is updated in any way, so that's the ideal place for you to check the length. See the API …

Member Avatar for softswing
0
589
Member Avatar for breakid

No, you would normally open the socket connection once, send all your data, then close the connection. Opening and closing for every message is unnecessary unless there are very long time intervals between the messages. You will need to flush the output stream after each message if you expect an …

Member Avatar for JamesCherrill
0
150
Member Avatar for rahul.ch

1. At *compile* time Java checks that the method call is valid. It checks that using the declared type of the reference. You cast the reference to Dog and Dog does not have a sniff method so line 11 will be rejected by the compiler. Dog does have a bark …

Member Avatar for JamesCherrill
0
267
Member Avatar for skiabox

You need: 1: a reference to the instance of "another class" that has the JPane you are interested in 2: a method in "another class" that returns the JPane Then you can just call that method on that instance to get a reference to the JPane and thus its contents

Member Avatar for skiabox
0
171
Member Avatar for GlenRogers
Member Avatar for GlenRogers
0
136
Member Avatar for skiabox

The Action mechanism was created for exactly this purpose: http://docs.oracle.com/javase/tutorial/uiswing/misc/action.html

Member Avatar for JamesCherrill
0
104
Member Avatar for skiabox
Member Avatar for skiabox
Member Avatar for skiabox
0
185
Member Avatar for rahul.ch

disp() is not static, so d isn't being used in a static context. If you did use it in a static context you would get a compiler error. The NPE exception message will tell you exactly where in your code the NPE happened.

Member Avatar for JamesCherrill
0
232
Member Avatar for hszforu

What version of Java are you running? I tried... public void x(String s, int... i) {System.out.println("i");} public void x(String s, double... d) {System.out.println("d");} public void run() { x("abc", 1,2); x("abc", 1.0,2.0); } ... and that works exactly as you would expect - Java 1.7 Windows 64.

Member Avatar for hszforu
0
167
Member Avatar for rahul.ch

No, it's not important. You have no control/knowledge of how those two threads will be scheduled; they have the same priority as each other and the thread from which you are starting them - eg it will depend on how many processors you have in your machine. If you need …

Member Avatar for rahul.ch
0
267
Member Avatar for 47pirates

Work out how to draw that whole thing using ordinary Java 2D graphics methods like drawLine and drawString, then follow this: http://docs.oracle.com/javase/tutorial/2d/printing/index.html

Member Avatar for JamesCherrill
0
138
Member Avatar for rahul.ch

1. You can't define one method inside another - that's just the Java langauge definition. (except when the second method is inside an inner class defined inside a method...) 2. After executing t.start()) you have two threads withe same priority and no synchronisation, so you have no control or knowledge …

Member Avatar for rahul.ch
-1
229
Member Avatar for rahul.ch

FYI it's the same thing for static methods - because they cannot be inherited, just like private methods, you can re-define (create a method with the same name) but not override.

Member Avatar for JamesCherrill
0
207
Member Avatar for B204

Right now it looks like your file transfers run from actionPerformed methods. These are called on the Swing Event Dispatch Thread, and no other Swing code will run until the actionPerformed returns. This includes any code to update the screen with progress bar changes. So the first thing you have …

Member Avatar for JamesCherrill
0
398
Member Avatar for trishtren

ints always have 32 bits. When you convert to a String to display them the string conversion method supresses leading zeros.

Member Avatar for JamesCherrill
0
166
Member Avatar for 47pirates
Member Avatar for Viped

I doubt very much that your key listener is working properly. Unless you have other code changes it will still have the "updates eveything at once at the end" symptom. Everything to do with Swing (eg painting the screen, running actionPerformed methods) happens on a single thread - the "Event …

Member Avatar for JamesCherrill
0
965
Member Avatar for hszforu

++x is 3, then the next ++x is 4 then the last one is 5, so you have 3*4*5 ie 60. Now x+= adds that 60 to the initial value of x (2) to give a result of 62.

Member Avatar for hszforu
0
109
Member Avatar for shammons1
Member Avatar for GlenRogers

Have a look at the API doc for JTextField. The intro shows how to create a custom field - in that example one that takes upper-case letters only. You should be able to use that example and its accompanying explanation to create your own numeric-only field. Alternatively, if you have …

Member Avatar for GlenRogers
0
131
Member Avatar for GlenRogers

If you have the key then it's just bMap.remove(ref) - or did I misunderstand your question?

Member Avatar for GlenRogers
0
171
Member Avatar for GlenRogers

Loop thru coustomers, loop thru each customer's repairs looking for the right key value, eg for (Customer c : customers) { for (String repairNo : c.getRepairs().keySet()) { if (repairNo.equals(...)) ... Repair r = c.getRepairs().get(repairNo) (this code can be optimised, but that's the clearest version to understand)

Member Avatar for GlenRogers
0
112
Member Avatar for wallet123

1. You need to determine whether the original letter was upper or lower case before you add the encryptor to it. Eg adding a suitable encryptor to an upper case may give you a valid lower case letter 2. If the encryptor can be >26 then instead of just subtractiong …

Member Avatar for JamesCherrill
0
140
Member Avatar for iEpic

90% probability that it's just looking in the wrong place. You can try `System.out.println(new File("xxx").getAbsolutePath());` (with your own file names) to see exactly where Java is expecting to find them.

Member Avatar for NormR1
0
253
Member Avatar for Boyd_

I don't have that much free time, and I'm certainly not a teenager, but if you want someone to review your design and proposed library APIs I'd be glad to help. J

Member Avatar for JamesCherrill
0
198
Member Avatar for kannan_pahang

Because you have not followed all the instrctions yet. What about "Create the class program that has main() method for execution. This program should create two Student objects and implement all methods listed in the Student class."

Member Avatar for JamesCherrill
0
128
Member Avatar for sammoto

> i don't think your clone method works, might wanna check that Can you clarify that? ArrayList certainly implements a shallow clone(), so what do you suspect, and why? Thanks.

Member Avatar for curiousgeorgem
0
3K
Member Avatar for sammoto

So you are getting an NPE in this line? this.cards.get(i).getValue() == value you first need to print out the parts of that expression to see what's null, is is cards? or the result of calling cards.get(i)? or the result of calling cards.get(i).getValue()? Once you know what is null you can …

Member Avatar for sammoto
0
447
Member Avatar for pendo826

Search by name you already have from the map itself. For the others you have to loop through all the Employee values in the map testing each Employee to see if it has the desired values.

Member Avatar for JamesCherrill
0
1K
Member Avatar for kannan_pahang

You must go back and read the assignment carefully - you won't get marks for ignoring it. Start with the first five words "**Create a class named Student**..." Then follow the rest of the instructions one line at a time.

Member Avatar for JamesCherrill
0
105
Member Avatar for efth

`public void main..`. declares its return type as "void" - ie it returns nothing. Do you mean something like this? public int timesTwo(int i) { // method returns an int int j = i*2; return j; }

Member Avatar for jLocke
0
254
Member Avatar for Massa3332

for(int x = 0; x <= count; x++) { myArray[x-1] = myArray[x]; } If you really executed that code the very first array index will evaluate to -1 and it will throw an index out of bounds exception. So what's *really* going on?

Member Avatar for JamesCherrill
0
216
Member Avatar for sarathsshanker

Every Java class inherits a toString() method from the Object class, so methods like println use that to convert the object you want to print into a String. The inherited method prints the class name and the object's hash (normally the same as its address). If you want to display …

Member Avatar for sarathsshanker
0
2K
Member Avatar for hszforu

When you have an arithmetic expression with all integers, Java does integer arithmetic. The integer result of 85/100 is 0 (fractions are truncated) That's why you get 0 if you do the division first. If you do the multiplication first it's OK.

Member Avatar for hszforu
0
201
Member Avatar for Krokcy

The normal way to copy a file from an input stream to an output stream looks like this: byte[] data = new byte[4096]; int count; // open input and output streams while ((count = in.read(data)) != -1) { out.write(data, 0, count); } // close input and output streams Under all …

Member Avatar for Krokcy
0
4K
Member Avatar for hszforu

i=i++; is a no-op - it leaves i unchanged. What happens is: the current value of i is stored i is incremented the stored value is assigned to i See http://skeletoncoder.blogspot.fr/2006/09/java-tutorials-i-i.html

Member Avatar for hszforu
0
123
Member Avatar for wallet123

After `x=x+encryptor;` you can test to see if `x>'z'` and if it is then subtract 26

Member Avatar for wallet123
0
192
Member Avatar for jalpesh_007

> Please help me to how to solve the error. 1. The error message contains the line number where the error happened; go to that line. 2. Immediately before that line add a print statement to print the value(s) of the index variable(s)/expressions(s) to see exactly when they are going …

Member Avatar for JamesCherrill
0
404
Member Avatar for trishtren

getOutput() is a method, but you call it without its () - yet there's no compiler message? Do you have a variable with the same name?

Member Avatar for JamesCherrill
0
209
Member Avatar for rossi1114

This is a pretty common mystery area, because different layout managers have different behaviour in terms of overriding the size to fit the layout. You may have better luck with setMinimumSize(...)

Member Avatar for jalpesh_007
0
207
Member Avatar for lj81

Maybe add a boolean to the Ball class for isPotted. (initially false, set t o true when the ball is potted) Then your paint/collision etc methods can call isPotted() to see if the ball is still in play or not (rather than performRemoval). Then when the black is potted you …

Member Avatar for lj81
0
153
Member Avatar for sush jack

Rather than just printing the exception's messgae, do a full e.printStackTrace(); This will give you the details of any errors that caused the exception eg file not found, incorrect priveleges to read file etc etc

Member Avatar for NormR1
0
11K
Member Avatar for enakta13

You can use getText() to get the existing text in the text field, then append your new character, then use setText() to update the field.

Member Avatar for Krokcy
0
290
Member Avatar for speakon

A couple of quick observations: You repeat the code to get the numeric value of a card a few times - repeating code is never agood idea. You can put all that into a method ` public int getValue(String card) ... ` that you can call whenever you want the …

Member Avatar for JamesCherrill
0
3K

The End.