7,116 Posted Topics

Member Avatar for ravsau

public boolean isNorth(Location c) { if(north!=null) return true; else return false; } ... is a long version of public boolean isNorth() { return north!=null; } ie (1) `north!=null` is a boolean expression, so you don't need to convert it to true or false and (2) since you don't use the …

Member Avatar for sciwizeh
0
754
Member Avatar for Johannady2

You're heading in a right direction, but there's something missing between line 41 (where you prompt the user) and line 42 where you test the user's input (that you haven't read yet!).

Member Avatar for NormR1
0
324
Member Avatar for Stjerne

The Image class has a getScaledInstance method that scales the Image to whatever size you want (eg the size of your JPanel)

Member Avatar for JamesCherrill
0
656
Member Avatar for Johannady2

Line 26 closes the method definition, so the if statement is not in any method, which is illegal and has confused the compiler.

Member Avatar for NormR1
0
438
Member Avatar for ftrzjocelyn

Stack overflow is almost certainly caused by you recursively calling a method from inside itself (or from inside a method that it calls). The error message should also tell you the line number where it happened, so that's where you start looking.

Member Avatar for JamesCherrill
0
571
Member Avatar for vriend12345
Member Avatar for vriend12345
0
119
Member Avatar for utkarshsahu

Yes, the default appearance of buttons is not good for this application, but it's easy to change that. For example a quick `button.setMargin(new Insets(0, 0, 0, 0));` will leave you with a simple plain rectangle. Then you can still use `button.setText("X")`, or `setIcon` for a snazzier look wthout any need …

Member Avatar for utkarshsahu
0
130
Member Avatar for gigglygeckoq

Your {} are all messed up - eg on line 49 you have the } that closes the class definition, but there is obviously more code following that which should be in the class. The best way to sort out this kind of problems is to go through the code …

Member Avatar for JamesCherrill
0
112
Member Avatar for Torf

Do you know how to write a loop that traverses the list from the first node to the last?

Member Avatar for JamesCherrill
0
127
Member Avatar for reaper1395

In eclipse just File/Export select Java/Runnable Jar, fill in all the blanks (including the name of the class that contains your main method) and that should be OK.

Member Avatar for reaper1395
0
143
Member Avatar for mikekhd

You are missing some essential pieces to display your barcode. 1. To display something on the screen you need to put it some kind of window, eg a JFrame. 2. The thing you put in the window is a JPanel, but you need a special one because you are going …

Member Avatar for NormR1
0
270
Member Avatar for shean1488

1. You can combine multiple tests in one `if`, in this case ORing them together, as in `if ( site.next(1) == null || site.next(2) == null ...` 2. The contents of the `if` must be a boolean expression, so you don't need an `if` to turn that into a booelan …

Member Avatar for shean1488
0
93
Member Avatar for jjoensuu

I don't know of any way to make an application "crash" by entering stuff into a dialog, but things like invalid dates can cause an Exception to be thrown when you try to parse them- and if you don't catch and handle that properly your program will terminate.

Member Avatar for JamesCherrill
0
443
Member Avatar for jayson_g

Instead of an ActionListener you need a ListSelectionListener, which will be called whenever the user selects a city in the list. `list.addListSelectionListener(new MyListSelectionListener())` Check out the API JavaDoc for details of the ListSelectionListener interface and the ListSelectionEvent that it uses.

Member Avatar for jayson_g
0
124
Member Avatar for drameshgar1

/ means divide! % means remainder 1/3 = .33333, truncated to 0 in int arithmetic 1%3 = 1 (3 into 1 goes 0 times with a remainder of 1)

Member Avatar for JamesCherrill
0
106
Member Avatar for Torf

1. Norm is giving you good advice. Real programmers test early and test often. Adding more code to 200 lines that are probably full of errors is just making your life hard. 2. `Collections.sort` sorts objects that implement the `List` interface. Since your class doesn't implement it you can't use …

Member Avatar for Torf
0
229
Member Avatar for Fotis_13

Sure. Suppose I had an array of Car objects, I could find the Fords with something like for (Car c : myArrayOfCars) { if (c.getManufacturer().equals("Ford") ... }

Member Avatar for Fotis_13
0
206
Member Avatar for sonicx2218

Norm's advice makes perefect sense. Alternatively, if you are going to be doing a lot of these drawings (eg animation) then you can create a new BufferedImage, get its Graphics, and draw your Shapes into that Graphics. Now you have your creature as a simple Image that you can draw …

Member Avatar for sonicx2218
0
407
Member Avatar for hszforu

Here's the problem: you are writing your data to the output stream as ASCII text, but you are reading from your input streams as raw bytes. It's essential that you read and write using the same format, eg if you print to the output then you should use readLine to …

Member Avatar for hszforu
0
4K
Member Avatar for shifat96

anand01 Please don't throw code like that at someone who is trying to learn. At the very least explain it properly. Even better explain enough for the OP to write it himself. That's the best way to learn.

Member Avatar for shifat96
0
2K
Member Avatar for Diogo Martinho

This is easier if you implement a full MVC (model-view-controller) architecture. In that case the controller handles the "logical" meaning of the user input by performing the appropiate method calls to the model (your spreadsheet). It's a bit tedious, but not difficult, to create a log of the calls that …

Member Avatar for JamesCherrill
0
164
Member Avatar for javaprog200

In your paint method, draw your images with an alpha (opacity) less than 1.0 Something like: float alpha = 0.5; composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha); Graphics2D g2D = (Graphics2D) g; g2D.setComposite(composite); g2D.drawImage(...

Member Avatar for JamesCherrill
0
204
Member Avatar for zuzzles

You may want to look at line 29. The value returned for EOF is -1. According the the JavaDoc a value of zero will never be returned, but I have a fuzzy memory of seeing a problem where read did return zero sometimes from an input stream that was network-based. …

Member Avatar for JamesCherrill
0
313
Member Avatar for chinee

The priority queue sorts your orders according to the comparator that you supply. The comparator must take two orders and determine which is highest priority - that's just some if tests using the urgent and booked in advance fields from the two orders. The StringLengthComparator in your code is just …

Member Avatar for NormR1
0
791
Member Avatar for vedro-compota

The standard Java GUI library is called "Swing", which is built on, and still uses many classes from, an earlier version called "AWT". Swing classes have names that begin with a J, as in JFrame, JLabel, JButton etc. Swing GUIs are portable across all platforms where Java runs. SWT was …

Member Avatar for vedro-compota
0
206
Member Avatar for Andy90

You need to wait for input from the local user and at the same time you need to wait for input from the remote end, and at the server you also need to wait for new client connections. Although it is technically possible to do that in a single thread …

Member Avatar for JamesCherrill
0
174
Member Avatar for fonzi

Yes, it's very likely that the heap overflow is caused by an excess of recursion, however I don't think your max recursion depth should increase so fast with array size (shouldn't it scale with log(n)?). Try putting one or more print statements in each of the methods to show what …

Member Avatar for JamesCherrill
0
310
Member Avatar for VeyRonX

The keyword "new" is wrong here. You are just calling the static method "forName" in the Class class. It's not a constructor. `Class ourClass = Class.forName("com.app.something");`

Member Avatar for JamesCherrill
0
651
Member Avatar for Muhammad Anas

The API doc for removeAll says: > This method changes layout-related information, and therefore, invalidates the component hierarchy. If the container has already been displayed, the hierarchy must be validated thereafter in order to reflect the changes.

Member Avatar for Muhammad Anas
0
6K
Member Avatar for J.S.AlKatheeeri

You extend an abstract class but implement an interface. You can only extend one class, so that limits their usefulness. In general an abstract class makes most sense when it contains a larg-ish amount of code that its subclasses can inherit and use.

Member Avatar for JamesCherrill
0
204
Member Avatar for bizak

Can you confirm the exact message and the line it refers to? The line you quoted (38) will only throw an NPE if hp is null, but to get there it must have executed line 24, so hp cannot be null (or I'm mis-reading your code, in which case, apologies)

Member Avatar for JamesCherrill
0
304
Member Avatar for empror9
Member Avatar for empror9
0
92
Member Avatar for gedas
Member Avatar for JamesCherrill
0
95
Member Avatar for nagatron

> Is there any way to make the method accepts any length from the input? Tecnically yes, you can use `Array1(int... n)` which declares a variable nunber (>=0) of int params - inside your method you will see n as an int array of the appropriate size. But in practice …

Member Avatar for nagatron
0
251
Member Avatar for sonicx2218

The easiest way is just to use a "enhanced" for loop, as in for (Integer i : list) { sum += i; // etc }

Member Avatar for sonicx2218
0
3K
Member Avatar for crownedzero

Put a load of print statements into your code, printing the values of the key variables at each stage so you can see where it's going wrong.

Member Avatar for NormR1
0
207
Member Avatar for devninja

I wouild expect that to print "ping" and "pong" (or "pong" and "ping"), then wait 10 secs, and repeat. What does yours do? How ***exactly*** does that differ from what you expect?

Member Avatar for NormR1
0
609
Member Avatar for Baduizm
Member Avatar for swagen

You can use your text field's ` getText()` method to get the String that was typed in. You can compare that to any other String by using its `equals` method. Then you can use an if test to set the text of the label.

Member Avatar for devninja
0
3K
Member Avatar for FUTURECompEng

> The output of the following line of code is: Not Done End Not according to Java. I just copied and executed the code you posted and it outputted Not End, exactly as expected. Have you tried it?

Member Avatar for FUTURECompEng
0
271
Member Avatar for DEAD TERMINATOR

You haven't gone wrong, the strange String you see is the default toString method that everything inherits from Object ( [ = array, I = int, @xxx = hash code ). The easiest way to print the contents of an array is with the `Arrays.toString(myArray)` method.

Member Avatar for JamesCherrill
0
313
Member Avatar for v3ga

I built a lttle training demo on exactly this theme a while back, and it's not easy for someone who has "just started learning Java". You're going to have to build some specific skills and cod techniques first before you try to put them all together into this app. I …

Member Avatar for v3ga
0
1K
Member Avatar for katiecathey

> I am suppose to just construct a Room with the possible components and then create a 5x5 TwoD array of type Room in the Dungeon class and then create a Dungeon object in the DungeonAdventure class. Looks like you are heading in the right direction. You need an array …

Member Avatar for JamesCherrill
0
710
Member Avatar for anuj_sharma

Perhaps it's a task switch thing? You could try a sleep(1000) after taking the screenshot but before accessing the clipboard?

Member Avatar for anuj_sharma
0
263
Member Avatar for Johannady2

You may have "enough braces", but you don't have an equal number of { (five) and } (four). Proper indntation would make the error immediately obvious.

Member Avatar for NormR1
0
278
Member Avatar for TakinANapster

Looking at your code I can't see code that would display anything on the screen/in the browser window. You just print things to System.out, which is the java console. To display things on the screen/in the browser window you will need to useSwing components such as JLabel or JTextArea

Member Avatar for NormR1
0
1K
Member Avatar for jarograv

On line 6 you declare, but do not initialise an array variable called className, so its initial value is null. That's the one you try to use on line 72, which is why you get an NPE. Your code on lines 24-29 has absolutely no effect on this because that …

Member Avatar for jarograv
0
225
Member Avatar for Stjerne

You don't have to use Strings to populate a JList - you can use any Objects. JList by default will use the objects' toString() method to get the text to display in the list. . So you can add Book objects to the JList - Then `list.getSelectedValue()` will return the …

Member Avatar for NormR1
0
309
Member Avatar for brandon66

> Use an enhanced for loop to sum the values in the array. Your loop is the traditional kind, not an enhanced for loop https://blogs.oracle.com/CoreJavaTechTips/entry/using_enhanced_for_loops_with

Member Avatar for brandon66
0
617
Member Avatar for erms

Fortunately Sun/Oracle have already written 99% of the code you need. It's all in the standard API. Use the ImageIO class to *read* the file into memory, ImageIO will handle all the details of decompressing the jpeg for you.That gives you an in-memory BufferedImage, so you can use its getRGB …

Member Avatar for erms
0
293

The End.