JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The text from an empty field is "" - a string of zero length.
You can't test the contents of a string with = or ==, you need equals(...).
The safest test here is to trim off any blank chars and see if anything is left, ie
s[1].trim().length() == 0

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Macify looks interesting as a packaged solution: http://simplericity.com/2007/10/02/1191336060000.html

or here's a load of info for doing it yourself: http://alvinalexander.com/apple/mac/java-mac-native-look/

... lots of other info is at the end of a very small Google query.

In either case you can use the same jar for both environments, and you can compile it wherever you want (ain't Java great?) You will probably need to convert your frames to JFrames if you want them all free-floating.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I have no idea what you are trying to achieve without any context. And "didn't weork" tells me nothing.
s is an array of Strings which was populated from the text of some JTextFields. Did you want to change the text fields? If so you need to use JTextField's setText method

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

By "value" do you mean the text in the JTextField? If so, the default is a zero-length String, ""

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can save time by trying your code in the Java compiler first - for example it would have immediately told you that "var" isn't Java (I think you meant String), rather than waiting 20 minutes for someone to read your post and reply. ;)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This isn't a Java question, it's an SQL question, and I'm not the best person to answer it. Try asking how to phrase the SQL query in our Databases forum - someone will know the answer.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you understand that then you will already know that whatever names you want for the columns just put those names in Vector columnNames
It's as easy as that.

columnNames.addElement("Column 1");
columnNames.addElement("My name for col2");
columnNames.addElement("This is col 3");
etc
shihab2555 commented: mmake crystal clear +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you understand what lines 14-16 are doing? Do you understand how Vector columnNames is used?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Then you will have to construct different SQL commands for each of the 6 possible combinations of criteria.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's not ideal because it's not obvious why you would do that to someone who just reads the code.
I would recommend this form for clarity..

int i = 0;
while (i < cookies.length) {
    for(CookieFlavors c : CookieFlavors.values()){
        cookies[i++] = new Cookie(c);
        ...

... but beware, you still have a bug that doesn't show up with an array size of 60, but will fail with 59 or 61 - if cookies.length is not an exact multiple of the nunmber of flavors then you will fall off the end of the cookies array in the inner loop before the outer loop gets a chance to exit, so you will need one more if test

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe OR those conditions rather than ANDing them?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Lines 14-16 create the Vector of column names from the result set (did you write that code yourself, or just copy it?). If you want some other name(s), put them into the Vector instead of the current value(s).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think you lost count somewhere.

First let's count the ref vars:
Every instance of a Swanky has one var s.
main has two local vars, s1 and s2.
go has one local var, gs, which is created each time you enter go, and destroyed at the end of go's execution. A copy of this reference is returned from the method; the caller can ignore this (line 6) or keep its own copy (line 7)

Now let's count the objects:
main calls new Swanky twice - two new Swankys, containing two new vars.
go calls new Swanky once each time it's called - each Swanky has one new var.
Instances of any class are garbage collected when there are no remaining references to them

Aermed with that, and a sheet of paper, you should now be ble to draw all the objects and references in a single diagram and update that as you step manually thru the code... after which the correct answers will be obvious to you. :)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When we assigned ls to o, didn't Object o become an array?

Don't lose track of the difference between objects and reference variables. Nothing you can do in Java will change the actual type of an object. ALl you can change is what references are known to refer to.
o is a ref var that can hold a reference to any object, including an array of ArrayLists. It can also hold a ref to a String, Integer, URL etc, which is why o[i] won't compile - unless it happens to be refering to an array at that particular time its wrong, and there's no general way for the compiler to know what it will be referring to at runtime.
In your first two cases you explicitly cast the ref to be a ref to an array, so the compiler believes that you can index it, but will compile in a runtime check, just to be sure.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
for(int i = 0; i < cookies.length; **i++**){
    for(CookieFlavors c : CookieFlavors.values()){
        cookies[**i++**] = new Cookie(c);

You increment i twice on some passes of this loop, so some indexes get skipped and are left as null.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How many Pixels are copied when the Picture is mirrored along the vertical line through its middle?

Isn't the answer just "all of them" (H*W)? Or am I missing something?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, you already said that in your first post.
The code you have posted in not valid Java. It won't compile, and therefore cannot be executed. So how about posting the actual code that gave you the error?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Vectors own methods are synchronised on the Vector instance, so if you call add on a Vector from one thread while another thread is executing a remove yhou should be OK.
Vetor knows nothing about your callMethod method, so it can do nothing about synchronising that. It does not / cannot know that you want the calls on lines 9 and 11 to be synchronised as one block.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

jpf, gif, png all work well in Java.
.ico is a problem because it's a Windows-only format. Unless anyone knows better, I think you will have to convert any icos to one of the other formats

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

java.lang.NullPointerException
at AppletMetodos.actionPerformed(AppletMetodos.java:96)

One of the values on line 96 is null (ie not initialised). Print all the variables used on that line to see which one is null, then you can back-track to find out why. The array "user" would be the prime suspect...

Kronolynx commented: thanks for the help +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You will find the official Oracle Look and Feel Graphics Repository at http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-java-client-419417.html#7520-jlf-1.0-oth-JPR
... but there are many mnany other sources of free icons that you can use for your Java application - just Google for them.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Debugging by re-reading your code and thinking hard is very ineffective.
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.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need public accessor methods such as getName, getID that simply return the values of those private variables. That way you allow other classes to get the values in a controlled way, but not to change or corrupt them.

Similarly you can create public setID etc methods if you want other classes to be able to change some of those values.
In your case, where presumably every Passenger has an ID and a name, which never change, you should consider having a public constructor that requires those values as parameters to create the Passenger object, and not having any set methods.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, that's the kind of thing I was referring to. Although htis may seems a bit complicated to start with, in the end it will be easier to use a proper model/view structure, a simple form of MVC, in which the logic is implemented in a non-GUI model, and a separate GUI just displays whatever the current state of the model may be. This breaks one big problem into two smaller ones.
Create a 2D array of Square objects. Each Square will have a color attribute (and other attributes depending on your application). Perform all your updating on that array (eg "directly touching" == array index differs by 1).
Create the GUI with each of your JPanels linked to one element of the array of Squares (you can use the JPanels' putClientProperty method to store a direct reference to its corresponding Square in the JPanel). Then updating the GUI is simply a process of looping thru all the JPanels querying their associated Squares to get the current color.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

My understanding is that a Node get deallocated by the garbage collecter automatecly when there is at least 1 reference is removed. is that right? correct me if I'm wrong.

No, that's not right. An object can only get garbage collected when there are zero remaining references to it (ps technically speaking there are also things called weak references that behave differently, but you can safely ignore those for the moment)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's really hard to understand your requirement, but is this what you mean (pseudocode)?...

  valuesToSkip = new ArrayList<Integer>

  for (r ...
     if (valuesToSkip.contains(r)) continue;
     ...
     valuesToSkip.add(anotherValueThatYouWantToSkipNextTime)
jalpesh_007 commented: good suggestion +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Instead of the println method, use printf
printf allows you to specify formats for how each variable is printed.
Have a look at http://www.homeandlearn.co.uk/java/java_formatted_strings.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

at BattleShipEnhanced.checkGuess(BattleShipEnhanced.java:108)

Yup, that's the one I expected.

Java naming conventions: this is a suitably short version of the standard:
http://en.wikipedia.org/wiki/Naming_convention_%28programming%29#Java

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You didn't say where the exception was being thrown, but maybe its like this:

for(ship currentShip : shipList){
   ...
   shipList.remove(currentShip)

You can't add or delete members from a list when you're in the middle of iterating thru it with an ordinary Interator or an enhanced for loop.

The easiest fix (provided the list isn't gargantuan big) is to create a temp copy of the original list to iterate thru, then you can delete from the original with no problems

ArrayList<ship> temp = new ArrayList<ship>(shipList);
for(ship currentShip : temp){
   ...
   shipList.remove(currentShip)

Or, if you want to be a real ninja java master, use a ListIterator

ps: "Ship" not "ship" for a class name

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Scanner is a pre-packaged reading/parsing class that gives novices a one-stop solution to processing simple text stream input. Apart from the nextInt/nextLine issue that you (and pretty much everybody else) ran into, it does a decent job within its design scope.
You use BufferedReader if you want to take control over all the parsing yourself, eg to parse input that's too complex for Scanner, eg dates or oddly-delimited multiple fields. Sooner or later you will get to that place, after which you will have climbed the learning curve, and will have no further need of Scanner. In the meantime there's no harm in doing it the easy way and using Scanners.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Personally I prefer not to use Scanner at all. Just read whole lines from a BufferedReader and parse fields, ints, dates etc etc using the methods in the appropriate classes. Maybe I'm just a control freak.
But seriously, the extra readLine is a perfectly good solution, and very commonly used.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Since OP is going with the brute force approach, I guess there's no harm in posting this code....

<snip>

It will multiply any two Java ints with a max of 31 recursions, vs 2 billion for the brute force solution.

<On second thoughts, maybe it's not a good idea to post the complete code here. Let's just say it's very small and fast, and you will get a real kick of satisfaction when you do it yourself. JC>

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, mixing nextInt and nextLine is a problem. Unline nextLine, which consumes the new line charater at the end ofthe line, nextInt takes the int and leaves the following new line character in the buffer, so the next readLine reads up to that newline (ie a zero length String).
There are a number of ways to avoid this - maybe the simplest is a quick "throw away" nextLine after the nextInt to consume the newline and leave the Scanner at the start of the next line as expected.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Looks more like C to me, definitely not Java. Try the C forum.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Because it will also accept objects from Integer's superclass(es), and they cannot be assigned to an Integer variable

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just for fun I did this as well, using the Egyptian Algo. This scales as O(log n) instad of Bibiki's O(n), so it's well worth the effort.
Like Taywin I passed those working values as parameters (not in an array because that was hard to read, and because it was easier when each invocation had its own values, except for the remainder). Including some initialisation its only a dozen lines of very simple code. Interesting project!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A grid layout is just an algorithm for placing GUI objects in a container. The "cells" are just an abstract geometrical concept, so there's no meaningful way to "mainipulate" them.
What you can do is create a 5x5 array of some real objects, eg JButton[5][5] or JLabel[5][5], then use the grid layout to place those objects in the container in the right positions. Then you can manipulate the objects however you wish.

Depending on your actual requirements you may be better with a JTable rather then a grid of separate objects.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The original requirement calls for a recursive solution, so presumably the list(s) will just become simple variables inside the recursive method. What hurts my brain is that the algorithm is essentially a 2-pass process that presumably maps to the before-the-recursive-call and after-the-recusive-call parts of the recursive method.
If I had more time now I'd get a big sheet of paper and work through a couple of really small examples, if I had more time now...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Look up the correct syntax for the import statement - you have an extra . that shoudn't be there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, sorry.

sobias commented: Why you're apologising :) +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to import the Scanner class.
ps
DaniWeb Member Rules include:
"Do not hijack old threads by posting a new question as a reply to an old one"
http://www.daniweb.com/community/rules
Please start your own new thread for your question

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe you would do better with the Russion Peasant algorithom - it's basically the same algorithm, but re-arranged so the iterative process and the stopping condition are much more obvious.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Ah ha! That looks like a standard floating point arithmetic rounding problem, nothing to do with your dot.
Decimals like 0.1 don't have an exact equivalent in a binary floating point number, so when you use them in arithmetic you often get an error in the very last digit of the floating point value. You can reduce these problems by using a higher-accuracy floating point type, ie double, but the problem still won't entirely go away.

This link explains the problem in more detail, and shows you how to use the BigDecimal class for exactly correct calculations on numbers with decimals.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That looks a lot better!
Apart from not resetting dotPressed after a C or CE I can't see any obvious problem. What exactly are the symptoms now?

ps Manage Operators - you seem to call calculate before you set the variable "operator" - is that right? WHy isn't operator passed as a parameter to that method, like the current value?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It seems that nobody here understands what you mean by "randomize the array indexs".
Java array indexes go from 0 to (length-1) as a strict integer sequence. The language does not allow you to change that in any way, let alone "randomise" it.
Can you re-state your requirement in a way that makes sense?

ps Java naming conventions reserve all-upper-case names for constants. Variable names should be in camel case (eg myParamVar)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's a mistake to use doubles here. Decimal fractions (eg 0.1) can't be exactly represented in a binary floating point format, so rounding errors are inevitable.
Your values are always an exact integer number of cents, so the obvious simplest (correct) way to hold the values in cents, not dollars, and store them in int variables. That way your calculations will always be exactly correct.
You may find it usefulto write a simple little method that takes a valaue in cents and converts it to a display string in $ddd.cc format, so your printouts are easy and look good.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's almost impossible to read your code, with unhelpful variables names and no comments, but maybe there's a problem with resetting the "pressed" boolean? The only place you reset it is in the else on 133, but given the obscurity of the code I have absolutely no idea under what conditions than block will be executed. At the very least I owuld expect it to be reset when you press CE, but maybe it needs to be reset whenever you press anything other than a digit button?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Case 1 every element is an Integer or a subclass of Integer. All subclasses of Integer are Integers (can be cast to Integer), so the implicit cast to Integer is OK
Case 2 every element is an Integer or a superclass of Integer. Not all superclasses of Integer are Integers (eg Object is not a kind of Integer), so the implicit cast is not valid.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to check the syntax for a constructor...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Strings in Java are immutable - ie their content never changes. The replace method therefore does not change the original String. It returns a new String that has the replacements made...

      String somestring="203/9834/345";
      String replaced = somestring.replace("/","");
      System.out.println(replaced);