This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes problem in running AWT programs!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem in running AWT programs!!" Watch "problem in running AWT programs!!" New topic

problem in running AWT programs!!

ankush walia
Ranch Hand

Joined: Jan 24, 2001
Posts: 95
hi everyone;
i'm having some problems in running programs in which i have used AWT components!!as far as the program is concerned ,it's getting compiled successfully!!but the only thing i get on running the appletviewer is an empty applet without any components on it!!i did set the right path,otherwise the code couldn't get compiled!!is there some problem with my JDK1.2 installation!!plzzzzzzz give u'r useful suggestions so that i can work further!!and yes i didn't forget to import the packages for AWT and applet!!
Matthew Jones
Ranch Hand

Joined: Dec 21, 2000
Posts: 68
It would really help if you posted your code. If the applet is compling, your classpath is probably set correctly, but there is probably some minor thing wrong with the code that's causint the problem.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi. The code below works. It results in a button appearing on the applet.

Use the following paremters with the APPLET to use the Java code.
WIDTH=400 HEIGHT=400 CODE="SimpleApplet.class"
Good Luck,
[This message has been edited by Manfred Leonhardt (edited January 25, 2001).]
ankush walia
Ranch Hand

Joined: Jan 24, 2001
Posts: 95
hi everyone;
and here's the code !!can anyone tell me now as to what's the problem in this simple code!!i saved it as,compiled it successfully!!but all i got was a blue coloured frame with no buttons at all!!where did the buttons go??
import java.awt.*;
public class framex
void fun()
{ Frame frame;
Panel panel;
Button button1,button2,button3;
frame = new Frame("My Frame");
panel = new Panel();
button1 = new Button("Button1");
button2 = new Button("Button2");
button3 = new Button("Button3");

public static void main(String s[])
framex obj = new framex();;
ankush walia
Ranch Hand

Joined: Jan 24, 2001
Posts: 95
hi mr.manfred leonhardt;
ya u'r code is running perfecly alright!!then what is the problem with mine?? do suggest!!
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Try calling your setvisible method after the components have been added.

So much trouble in the world -- Bob Marley
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340

There is another way to set the frame visible.
Im not sure what the problem is but you can try this. After this line.
framex obj = new framex();;//try this
this is the entire main of an app I wrote that works.
public static void main (String args[]) {
new DiceRolls().show();

Visit my download page
kavya krushi
Ranch Hand

Joined: Oct 25, 2000
Posts: 48

It worked out fine for me ... do try this code on someother machine and see if you can see your buttons :->
[This message has been edited by kavya krushi (edited January 25, 2001).]
ankush walia
Ranch Hand

Joined: Jan 24, 2001
Posts: 95
hi bosun bello;
u'r valuable suggestion did work,but tell me something??
isn't it that the frame should be set visible before anything is added on it??i was knowing this only!!if i'm wrong plzzz correct me!! once again thanx for u'r suggestion!!
ankush walia
Ranch Hand

Joined: Jan 24, 2001
Posts: 95
thanx for u'r valuable suggestions friends ,but do tell me if what i have written above is wrong or right?? i'm happy that the buttons r back smiling on my window now!!
ryan burgdorfer
Ranch Hand

Joined: Jan 24, 2001
Posts: 219
No, the frame dosn't have to be visible befoer anything is added. It is best (but not required) to make it visible after your components have been added.

<UL TYPE=SQUARE><I><LI>Ryan Burgdorfer<BR><LI>Java Acolyte</I></UL>
jQuery in Action, 2nd edition
subject: problem in running AWT programs!!
Similar Threads
Printing from Applet
Why Fatal Exception comes ?
Painting using Microsoft VM
java.lang.VerifyError in Netscape when loading applet
problem with getPeer() method