Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

setVisible() causing headaches

0 views
Skip to first unread message

Galen

unread,
Apr 2, 1997, 3:00:00 AM4/2/97
to

This is probably something simple, but
setVisible() is acting weird.

I just converted some code over from java 1.0 - an application, not an applet.

So, instead of using show(), I need to use something like setVisible(true);
(I think)

Here is the relevant code: (inside of the class AllComponents)

public static void main(String[] args) {
Frame f = new AllComponents("AWT Demo");
// We should call f.pack() here. But its buggy.
f.setVisible(true);
f.setSize(450, 475);
}

and the error:

java.lang.NullPointerException
at sun.awt.motif.MFramePeer.<init>(MFramePeer.java:59)
at sun.awt.motif.MToolkit.createFrame(MToolkit.java:153)
at java.awt.Frame.addNotify(Frame.java)
at java.awt.Window.show(Window.java)
at java.awt.Component.show(Component.java)
at java.awt.Component.setVisible(Component.java)
at AllComponents.main(AllComponents.java:165)


So, why is it doing this? I think I am using the right method.


-Galen

ps. Is there a good source of application code for 1.1 anywhere online?

Galen

unread,
Apr 2, 1997, 3:00:00 AM4/2/97
to

Please mail responses to me regarding my last posting.

Thanks,

-Galen

Richard Baldwin

unread,
Apr 3, 1997, 3:00:00 AM4/3/97
to

In article <5hujra$p...@mimsy.cs.umd.edu>, ga...@umiacs.umd.edu (Galen) wrote:
>This is probably something simple, but
>setVisible() is acting weird.
>
>I just converted some code over from java 1.0 - an application, not an applet.
>
>So, instead of using show(), I need to use something like setVisible(true);
>(I think)
>
>
>
>Here is the relevant code: (inside of the class AllComponents)
>
> public static void main(String[] args) {
> Frame f = new AllComponents("AWT Demo");
> // We should call f.pack() here. But its buggy.
> f.setVisible(true);
> f.setSize(450, 475);
> }
>
>and the error:
=============================
I forgot to mention in my previous post that the following code compiles and
runs fine under JDK 1.1.1 /Win95. The possible difference is that
AllComponents extends Frame. If "extends Frame" is removed from the class
definition, it won't compile.


import java.awt.*;
class AllComponents extends Frame{

AllComponents(String x){
System.out.println(x);
}//



public static void main(String[] args) {
Frame f = new AllComponents("AWT Demo");
// We should call f.pack() here. But its buggy.
f.setVisible(true);
f.setSize(450, 475);
}
}

Enjoy the Java,
Dick Baldwin

======================================================================
Richard G. Baldwin, Assoc. Prof. of Computer Science
Austin Community College, Austin, TX

Richard...@worldnet.att.net
http://www.austin.cc.tx.us/baldwin/

Richard Baldwin

unread,
Apr 3, 1997, 3:00:00 AM4/3/97
to

In article <5hujra$p...@mimsy.cs.umd.edu>, ga...@umiacs.umd.edu (Galen) wrote:
>This is probably something simple, but
>setVisible() is acting weird.
>
>I just converted some code over from java 1.0 - an application, not an applet.
>
>So, instead of using show(), I need to use something like setVisible(true);
>(I think)
>
>
>
>Here is the relevant code: (inside of the class AllComponents)
>
> public static void main(String[] args) {
> Frame f = new AllComponents("AWT Demo");
> // We should call f.pack() here. But its buggy.
> f.setVisible(true);
> f.setSize(450, 475);
> }
>

>ps. Is there a good source of application code for 1.1 anywhere online?
============
Unless AllComponents is a subclass of Frame, I would be suspicious of the
statement

Frame f = new AllComponents("AWT Demo");

In any event you can find dozens of example programs, many of which use Frame
objects on Dick Baldwin's Instructional Java Page at:

<http://www.geocities.com/Athens/7077/Java000.htm>

0 new messages