JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That doesn't allocate any memory for ObjectL objects - it allocates memory for an array of int a references (pointers) to possible ObjectL objects.
To allocate memory for the objects themselves you need to execute new ObjectL(...); where ... is zero or more parameters as required by ObjectL's constructor(s).

Because you defined and initialised the array numberL on line 3, it can never be null on line 5, so the test is redundant.
Note also that the array numberL was defined inside the formStyleOfLyle method, so it will go out of scope and be garbage collected as soon as you exit that method.

In summary, that whole method is equivalent to

public static int formStyleOfLyle(int a) {
   return 0;
}

What exactly do you want to achieve here?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

And I want my car to warm up automatically 10 minutes before I want to use it in winter.

Rather than just posting your demand here, you could have Googled - well, let me think... what would be a good search... oh! I know, how about
Auto Increase size of column width in jtable
when I do that it immediately gives me lots of code to do exactly that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This approach to keyboard handling is always a complete pain in the * because of precisely those focus issues.
Swing was enhanced back in Java 1.3 to provide a better way of doing things via two new classes: InputMap and ActionMap. Here's a good write-up on the theory behind it:
http://java.sun.com/products/jfc/tsc/special_report/kestrel/keybindings.html#new_bindings
and this is the tutorial:
http://download.oracle.com/javase/tutorial/uiswing/misc/keybinding.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Ah - just saw that you are using a null layout managers. (It's your program, so that's up to you). That changes everything. Forget the pack(), that's for real layout managers. Sorry about that, null layout is something you just don't see in "real life" development, so I had a false hidden assumption.
On the other hand, it's simpler because I now have no idea why the size should depend on where the add method is called from. If you can let me have a stand-alone single file version I'll run it and see what I can find; otherwize I'm afraid I'm not going to be much more use to you :-(

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you add stuff to a window you need to call pack() after adding everything.

public void pack()

Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. The resulting width and height of the window are automatically enlarged if either of dimensions is less than the minimum size as specified by the previous call to the setMinimumSize method.

If the window and/or its owner are not displayable yet, both of them are made displayable before calculating the preferred size. The Window is validated after its size is being calculated.

If you want the window to start out big enough to show a panel that you will add later you can either use setMinimumSize or use a place-holder component of the right size.

This is all part of the sometimes painful magic of layout managers. They're great and essential when you get control of them, but at first they seem totally out of control and prone to random behaviour.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can start by adding those buttons to the elseifs in you actionPerformed method - have them just call methods add(), save() etc, then write those methods, one at a time, testing each small step with lots of print statements as you go.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I assume you are drawing the grid in an overridden paintComponent?
After moving the label you should just call repaint() to let Swing know that the container's paintComponent needs to be called a.s.a.p.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your use of && looks OK to me. That isn't the neatest/shortest way to code it, but as far as I can see it should work as you intended, apart from some marginal cases where the ranges don't quite meet up, eg 3.05, which isn't a B+ or a B
Rather than all those else ifs and the afore-mentioned range problem, you could code it like this:

if (grade >= 4.0) return "A+";
if (grade >= 4.85) return "A"; 
etc
JeffGrigg commented: That's a very good suggestion. +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The secret of understanding this is to remember that list1, list2, list, and result are references (llike pointers) to an Object of type ArrayList<String>. The only way an actual ArrayList<String> object can be created is with the new keyword (line 3). If you follow the code 1 step at a time you will discover that there is only one ArrayList is this program, and that all those variables are just copies of the variable list1, so they all refer to the same object.
It's not easy to grasp 1st time round. Grab a sheet of paper with boxes for the variables and fill in the boxes as you step through the code. Remember the variables are references (pointers) they are not ArrayLists.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm sure there are many of us here who would like to help you, but its really hard to debug 900 lines of completely uncommented code with variable and method names in a language that few of us speak.
Unless you can create a smaller simpler version that displays the same problem, the only help I can give is to advise you to add a whole load of print statements around the relevant areas so you can see where the values are differing from what you
expect.
Good luck anyway.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

newMaze contains a copy of a reference (pointer) to the maze array in the instance of Maze, so yo can just use that as in newMaze[i][j] which will reference exactly the same memory location as the original maze[i][j]

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, it's not valid. The method currenttemp() must either have a body in {} or be declared abstract, in which case the class must also be declared abstract.
Without the () currenttemp becomes a float variable, not a method, and the code is valid.
We can only guess what the original author intended, but if he was following standard Java conventions that method would be called getCurrentTemp(), but then it wouldn't be private. My guess is that it's probably intended to be a variable.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is a standard problem with a standard solution:
Change the NewJFrame constructor to take an instance of Watcher as a parameter and store it. So your main now looks like

Watcher beholder = new Watcher();
NewJFrame GUI = new NewJFrame(beholder); // pass Watcher instance to GUI

now in NewJFrame you can use the beholder you have stored to access the variables and methods of your Watcher instance

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK. Start with this quick tutorial:
http://download.oracle.com/javase/tutorial/reflect/

In summary you get the Class of each classes containing your methods (Java refers to "functions" as "methods"), then from the Class get the Method objects representing the methods themselves. You can store those in an array of Methods. You can use "invoke" to invoke any of those methods with whatever parameters they need. It's a bit of a slog the very first time you do it, but once you get the first one sorted it's easy, and the code can be very compact.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1)Is Method Overloading considered as polymorphism?
2)Is there two types of polymorphism(run time and compile time ) available?

1. According to Oracle's web site - yes.
2. Given that Q1 answer is yes, then yes. Overridden methods are resolved at run time based on the target's run-time type. Overloaded methods are resolved at compile time based on the number and types of the arguments. Overridden overloaded methods are presumably resolved by a combination of the two.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's almost certainly a good idea. The code for GUIs with lots of controls like this gets out of hand very quickly; it's very long, horrible to debug, and incomprehensible for anyone else. Splitting it into separate classes for each panel helps enormously.
One hint: Keep a class for the whole window, and make the panel classes sub-classes of it. That way the panel classes have access to the class variables and methods of the window class. You can use that to handle anything that needs to be shared or communicated between the panels. Any methods that can't be handled within just one panel can go up in the window class.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

line 14 - you copy largest to nums - that's the wrong way round

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Using drawing statements is part of overriding paintComponent, and is independent of what kind of layout manager you use.
GridBagLayout, like all the other non-null layout managers avoids pixel coordinates and goes for rules about how you want the space divided up and how to fit/space/align things within those divisions. The point of this is that you can move your app to another computer where the fonts are different and it will preserve what's important about your layout while fitting it to the new text sizes. Similarly, when the user resizes the window it can allocate the increased/reduced space in the most appropriate way (eg resize a list box while keeping the buttons at the same relative position).
Frankly, if you are not going to move to a new machine, and you don't allow the user to resize the window, you may as well stay with null layout (but not in any other circumstances)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your problem is that although you know that one of those if tests must be true, the compiler isn't quite that smart, so it worries about the case where all 3 if tests are false and execution drops out of the last elseif. In that case it gets to the end of the method without returning a String. ilovejava's solution will fix it, or, if you want to keep the very explicit version of your if tests you can just add a final return ""; at the end of each method.

ps @ilovejava - that was a sensible solution, but you will help people even more if you give some explanation of what the problem was caused by, and how your solution fixes it. J.

xiangzhuang commented: thanks +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can add labels to a null layout - you need to call setBounds to specify both the position and size, and request a repaint afterwards. For ultimate control over layouts while retaining all the advantages of a layout manager use GridBagLayout. The learning curve is a bit steep, but it's worth the effort.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, you can use your image to make an ImageIcon and put that in your JLabel. Documentation is in the usual places.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

arrFan[0].FAST tries to use an array element that you haven't initialised yet, so that's why its null.
But that's not what I just posted! Inside any class other than Fan itself, you must refer to those static variables as Fan.SLOW, Fan.MEDIUM and Fan.FAST.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, just add them one at a time and forget the second array.
You already have code to find an element and flag/unflag it - so what's the problem you are asking in bold above?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK you lucky people - here's the first public outing for JC's instant "how to start a thread as simply as possible" tutorial.
1. You have a method doStuff() that you want to run in a new Thread.
2. Threads need a class that implements Runnable (ie with a run() method) to define what needs to be executed in the thread.
You can do that with a simple inner class:

Runnable myRunnable = new Runnable() {
         public void run() {  // the run method...
            doStuff();        // .. just starts your doStuff method     
         }
      };

now you can create a Thread with that Runnable

Thread myThread = new Thread(myRunnable );

finally you just have to start the thread executing

myThread.start();

that's all folks!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Planet[] arrayPlanet = new Planet[4];

creates an array with slots for four Planets, but all those slots are originally empty (null). You need to initialise them with actual instances of Planet, eg

arrayPlanet[0] = new Planet("Venus", 255);
arrayPlanet[1] = new Planet("Mercury", ... etc

Now you can get rid of your p2, p3 etc variables and use the array instead, and get rid of all the if tests inside the loop. eg

System.out.println(arrayPlanet[i].calculateAge(age));
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's because the print statement is outside the loop. The loop goes from line 121 to line 127, and iterates without printing anything. When it exits the loop it goes on to line 129 where it prints the last result.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you try to use a reference variable or expression that does not contain a reference to an Object - ie contains null. This may be because it hasn't been initialised, or it may be the result of calling a method that returns null following an error or other condition such as end-of-file.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

And the main reason for making DungeonRoom a child was easy access to the parent dungeon.. :P Must've been some godforsaken hour when I decided to make it a child.

Excellent! ps where you need to access vars from a containing Object like that you can make the contained class an inner class of the containing class so it has access to the variables of the instance that contains it.

Aviras commented: You answered my question before I even got to ask it, great! +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The problem lies whenever I try to access dungeon in the DungeonRoom object the player is in

What does that code look like?

Is it possible you are accessing the dungeon array from your current DungeonRoom frather than that in the "parent" HostileArea? That would explain lack of error messages but no output.
If so you need DungeonRoom to have an instance variable for the HostileArea it's part of, and you can pass that in to the constructor for DungeonRoom when you create them following line 28.

It's perfectlt legal, but quite confusing having HostileArea as the superclass of DungeonRoom, but also a instance of HostileArea containing instances of DungeonRoom. Does DungeonRoom really have to extend HostileArea?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Ive always compaired strings like this, with no errors

The compiler is very smart about optimising String constants, so, for example, if you have
String s1 = "ABC";
then somewhere else
String s2 = "ABC";
the compiler will not create a second String, but will re-use the first String object (not the String reference!). In cases like that s1 == s2.
Optimisations like these are the reason that == sometimes works, but it's not part of the language spec, and you can't rely on it. equals(String other) is the only safe way.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

String is not an exception.
As for every other class == tests for two objects being the same object and equals(...) tests for two objects being equivalent as defined by the author of the class. If you are deriving Strings from an expression and comparing them with String constants in your program you must use equals, not ==. For example:

String s1 = "A", s2 = "a";
      System.out.println(s1 == s2.toUpperCase()); // prints false
      System.out.println(s1.equals(s2.toUpperCase())); // prints true

ps @hiddenpolen: while (input != 'n'... In Java 'n' is a char not a String. Strings and chars are not comparable with == or != Even if you replace this with "n" you have a perfect example of why you have to use equals(...)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's quite common for a beginner to put everything static - it's because they start coding in the public static void main(String[] args) method, and immediately discover that they get compiler errors if the members they reference are not also static.
More experienced Java developers tend to have a main that just instantiates a small number (eg 1) of important objects, and hands over control to a method in one of those.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Short answer: yes.
Longer answer: Java's GUI classes ("Swing") are more aimed at standard business applications, with a standard look and feel. Your panels will be pretty straightforward if you accept one of Java's standard looks. On the other hand you can draw shapes and images any way you want to get any exact appearance you desire, but that's more work.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 15: Math.random returns a value >=0, <1 So when you convert it to an int the int will always be zero.
Line 21 etc, the test for two values being equal is ==, not = (that's assignment).
Yes, you should definitely download the JDK at home. However, the general consensus here is that big IDEs like NetBeans or Eclipse are not suitable for beginners, and get in the way of learning the fundamentals properly. However, everyone has their own opinion...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to be on the .latest version of Java (Java 7, or version 1.7) then you can use the "new I/O" classes to access that kind of metadata.
It's all very new, so there's not a lot of examples on the web yet, but here's a good place to start:
http://download.oracle.com/javase/tutorial/essential/io/fileAttr.html

peter_budo commented: Nice info James +16
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What do you mean "the summary of a file"?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, that's a good start! So what exactly are you stuck on?

(Please post your code in code tags next time - it's much more readable)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The doc for NoSuchMethodError says
"Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed."
Try deleting all your compiled .class files and re-compile everything.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm going to (respectfully) disagree with the previous 2 posts.
Using NetBeans or another IDE to generate Swing code when you don't understand Swing will just lead you into more and more confusion. You'll get hundreds of lines of code that almost but not quite work, and you'll have no idea what to do next. Reading machine-generated code is a terrible way to learn about a subject.
Swing is a big complicated topic, so it's not easy to learn. The Oracle tutorials are of the very highest quality, and you won't find anything better. If you don't have the time (or patience) for "lots and lots of reading" then maybe you should switch to an easier subject.
The best advice I can give you is to start with the first Oracle tutorial and take them one at a time. Within each topic you can often skip the last couple of pages before moving on - it's usually pretty clear which pages are necessary for what follows.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How can we possibly answer that? You haven't told us what next is or what drawimage is or where they are.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You add a drawclass and call its method, but that draws nothing. The drawing code is in class Moon.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

string can never be assigned directly...
you can use for loop..
for(int i=0;i<name1.length();i++)
name=name1.charAt(i);

Unless I have completely misunderstood this post... it's complete nonsense.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Then isn't it just max/X - (min-1)/x ??? (ie subtract the ones below the min)
(I'm not certain about this, but if you have working code now you could try this and see if it gives the same answers)

bibiki commented: I agree, unless min must not be excluded +5
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

DaniWeb Member Rules:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/forums/faq.php?faq=daniweb_policies

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You'll have to Google for details, but briefly, JTree uses a JLabel to draw each cell in the tree. But you can define your own renderer (normally a subclass of JLabel) to draw each cell however you like - eg use a bigger font for some cells, add graphics etc etc

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could subclass TreeCellRenderer and use setCellRenderer(javax.swing.tree.TreeCellRenderer) to draw each row with any arbitrary height, and setRowHeight(0) so the the current cell renderer is queried for each row's height.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you just need some test data you can create and populate an int array like this:

int[] arr = {1,2,3,999}; // creates 4 element array with those values
JeffGrigg commented: Short. To the point. Excellent answer to a simple question! +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
public void display(){
for(int i = 0; i<count; i++){
System.out.println(numofcd[numCD].toString(numCD));

Shouldn't you use i to index into the array?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

BigInteger holds arbitrarily large integers as binary values (the implementation uses an array of ints to provide whatever number of bits are required). I can't imagine that there would be any faster way to hold or do arithmetic on giant numbers on an ordinary computer, and certainly it's the most memory-efficient representation.
The only exception may be if you want to work with individual digits of the decimal representation, in which case a byte array with one decimal digit per byte may be better (two decimal digits per byte if memory usage is more important than execution speed/code simplicity).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to add your buttons etc to the form, otherwize they are just floating about in a vacuum. Eg

Container cp = calc.getContentPane();
...
resultTF = new JTextField(10);
[B]cp.add(resultTF);[/B]