Re: Mixing Cocoa/Java problem
Re: Mixing Cocoa/Java problem
- Subject: Re: Mixing Cocoa/Java problem
- From: Ricky Sharp <email@hidden>
- Date: Tue, 20 Nov 2001 10:44:32 -0600
Comments below...
On Monday, November 19, 2001, at 05:22 PM, Frangois GOURAND wrote:
I had a quite simple question for you, and I'd be pleased if somebody
could
answer to me !
I created a small Cocoa/Java project type with Project Builder whose name
is
Test2.
And the problem is I can't understand why it doesn't work !
Here's the code, it's very short and easy :
I didn't change the Main.m file, as usual !
I have two Java classes
WINDOW.JAVA
Your filenames should use the correct case (i.e. if your object is named
MyObject, its filename should be MyObject.java.
---------------------------------------
import java.util.*;
import javax.swing.*;
public class window {
public void Window () {}
Your class name is window, but your CTOR is named Window (note the case).
I'm assuming this is a typo? Otherwise, what you've done here is have an
object named window with two methods: an instance method named Window and
a class method named display.
public static void display() {
System.out.println("Step 1");
JFrame myFrame = new JFrame("It's my frame !");
System.out.println("Step 2");
myFrame.show();
}
}
The display method above is static. To call it, you just need to do
Window.display();
See comments below as to a reason why this method is not being called.
CLICKIT.JAVA
---------------------------------------
import com.apple.cocoa.foundation.*;
import com.apple.cocoa.application.*;
public class ClickIt extends NSObject {
NSButton connect;
public void clicked(NSButton sender) {
System.out.println("You clicked the button");
Window window2 = new Window();
window2.display();
}
}
In the clicked method, you are creating an instance of a Window object and
calling the display method.
Since Window already exists in AWT (java.awt.Window), you may want to pick
a different name. Or, you'll have to explicitly specify your Window
object (e.g. com.mycompany.Window).
It appears as if you are actually creating an instance of java.awt.Window
and calling its display method (not yours).
Please tell me what I should do to make this work... And if you also know
where I can found good documentation on that particular subject, please
let
me know !
I think you'll need some more general Java coding practice.
------------------------------------------------------------
Ricky A. Sharp Instant Interactive(tm)
Founder & President <
http://www.instantinteractive.com>
<
mailto:email@hidden>
------------------------------------------------------------