Some Java Questions

Kris

Registered
I have some Java questions which I hope someone can answere. :)

1: I have two windows (so far) in my program, and they are in the same folder (package). I was thinking of moving one of them into another folder. Let's say I did that, and got these folders: MyProgram/Window and MyProgram/Color. The packages would then be: MyProgram.Window and MyProgram.Color. If one of the classes from the MyProgram/Window directory wanted to call one of the classes from the MyProgram/Color directory, how would I do that? I tried writing package MyProgram.Color in the file that is located in MyProgram/Window, but it didn't seem to work. (...did this make any sense?)

2: On the menu-bar, where the name of the program should be, it only says the name of the package. How can I change that into, let's say: "My program"? This should be done in the main class, right?


:)
Kris
 
Instead of using package MyProgram.Color how about import MyProgram.Color? Or is that not what you are trying to do?
 
thank you, nkuvu. :)

Perhaps you're right, but my compiler gives me an error, saying it can't access the package and that the class file (that calls it) contains a wrong class name (which it doesn't, not at as I can see at least). Are you sure this is the right way to do it? Am I the one who's messing it all up?


Kris
 
This is what you want to do:

file myprogram/window/Window.java:

Code:
package myprogram.window;

import myprogram.color;

// "public" is important
public class Window {
	// java code here
}


file myprogram/color/Color.java:

Code:
package myprogram.color;

import myprogram.window;

// "public" is important
public class Color {
	// java code here
}

In the class Window you can now refer to the class Window and in the class Color you can refer to the class Window.

If you don't want to use import (for whatever odd reason) you can refer to the classes excplicitly: myprogram.color.Color and myprogram.window.Window.

Theo
 
Check your spelling of your class and package names.
Remember that java is case-sensitive, so that Color != color
 
Thanks guys! :)

I tested out what you wrote iconara, and it worked. But not perfectly though. It works if my classes are empty, but if I write some code in them, the compiler gives me an error, where it says I already declared the class in the opposite (meaning the class that calls the other class) file. Strange.

I suppose I just have to test it out a bit...

Hmhm.. anyone know the answere to question two ? :)


Kris
 
If MyPackage.Color are both directories, then what you mean to write is this:
Code:
package MyPackage.Window;
import MyPackage.Color[b].*[/b];

// yadda yadda yadda
...
You need the .* in there.

Or you can reference classes by their fully-qualified name:
Code:
package MyPackage.Window;

// yadda yadda
...
    {
        MyPackage.Color.SomeClass foo;
        ...
     }
Cheers,

-Rob
 
Originally posted by aishafenton
[..]If so you can use frame.setTitle("Title Here")
This sets the title on the specific frame, which is not quite what I mean. (Sorry for being unclear.) What I'm talking about is the title on the menubar, at the top of the screen. I want to put a name where every program has a name, right next to the little Apple. But thank you anyway for replying.:)


Kris
 
Doh!, yes sorry Kris.

What you need then is to place the -Xdock:name="name" in your java command line.

For example!
java -Xdock:name="YOUR APP NAME HERE" MyApp

The only other way I know is to wrap the whole app in a Native loader using the MSJAppBuilder program included with the developer tools.
 
It worked! Thanks. It looks so much better now, though it will be a bit "stressy" to always write the "-Xdock:name"-sentence at the java line in the Terminal. But it'll do for now. :)

I must say I'm positively surprised by the fact that Java doesn't feel like Java in Mac OS X. But some of the classic Java-problems are still there. For example, one of the frames in my program has a blue background. But its plain and grey when the program loads. If I make the window a little bit bigger, the blue color shows up. Very annoying!


Kris
 
Go to your home directory and edit your .login file (if it exists) and make an alias like so:

alias javaDock ''java -Xdock:name='

Then you just have to type the name of your app javaDock "Name of App" myApp. Edit yo your hearts content.

HTH,
F-bacher
 
Back
Top