Forums Register Login

Problem with taking the arguments

+Pie Number of slices to send: Send
public class JedApplet extends Applet {

public void init() {
// her comes code that create SimpleUniverse with Information=0, and
// whwn I clik with mouse on Button field, I have to put new
// SimpleUniverse with Information=1
}
......
}

class Controls extends Panel implements ActionListener {
Canvas3D c;
int Information;

public Controls(Canvas3D c) {
Button b = null;
this.c = c;
b = new Button("Button");
b.addActionListener(this);
add(b);
}

public void actionPerformed(ActionEvent ev) {
String label = ev.getActionCommand();
Information =1;
//??? Need to send Information from here to public void init()
}
}

I need to give Information from this ??? to public void init() so I can get different picture on my monitor when I clik the mouse. I know it is basic question but I really need help!!!
+Pie Number of slices to send: Send
Welcome to JavaRanch.

You should not construct any part of the GUI in the init method. That method is part of the applet lifecycle, and is called just once when the applet is started, and never again after that.

So you should define your own method that takes any parameters it needs to, and use that instead of the init method.
+Pie Number of slices to send: Send
Thanks, but still I can't do what I want.
I try like this, but have

public class JedApplet extends Applet {
JedApplet jedapplet

public void init() {
// her comes code that create SimpleUniverse with Information=0, and
// whwn I clik with mouse on Button field, I have to put new
// SimpleUniverse with Information=1
paint(Information);
}

public void paint(int Information){
//adding something in the scene
}

public void redraw(int Information){
paint(Information);
}

public static void main(String[] args) {
Frame frame = new MainFrame(new JedApplet(), 500, 500);
}
}

class Controls extends Panel implements ActionListener {
Canvas3D c;
int Information;
JedApplet jedapplet;

public Controls(Canvas3D c) {
Button b = null;
this.c = c;
b = new Button("Button");
b.addActionListener(this);
add(b);
}

public void actionPerformed(ActionEvent ev) {
String label = ev.getActionCommand();
Information =1;
jedapplet.redraw(Information);
}
}


Most probably something is wrong with this bold one and giving me
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException in this last bold line of the code.
+Pie Number of slices to send: Send
You never assign anything to field "jedapplet", so it's value remains null, and you will get a NullPointerException if you try to invoke one of its methods.

I'm guessing that you should assign the field jedapplet in class JedApplet with the anonymous object you're creating in the main method. Then you should pass that object as parameter to the constructor of class Controls -wherever that is called-, and assign it to field jedapplet of class Controls.

Please use the "CODE" button to surround code of any length with code tags to preserve its formatting.
[ March 07, 2007: Message edited by: Ulf Dittmer ]
+Pie Number of slices to send: Send


First thanks for trying to explain me
I know this is the basic, but it is very hard to learn it by yourself.
If I fill jedapplet like bold on the top I get Exception in thread "main" java.lang.StackOverflowError, and if I fill it like italic I get Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
[ March 07, 2007: Message edited by: Luka Juric ]
+Pie Number of slices to send: Send
Try this:

It seems that you understand why you got the NullPinterException.

You got the stack overflow because every time a new instance of JedApplet is created, it in turn creates another new instance of JedApplet, until all memory is filled up with JedApplet instances.
+Pie Number of slices to send: Send
Thanks, it works!!!
Legend has it that if you rub the right tiny ad, a genie comes out.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 554 times.
Similar Threads
JInternalFrame Problem: not showing the frame properly
need help whit 3d applet
VIEWING VRML FILES IN JAVA3D. URGENT!!!
Help Java3d
Error while running an example
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 02:03:18.