File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem in running AWT programs!!" Watch "problem in running AWT programs!!" New topic
Author

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!!
ankush!!
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
ankush,
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,
Manfred.
[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 framex.java,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");
frame.setSize(300,400);
frame.setBackground(Color.blue);
frame.setVisible(true);
panel = new Panel();
button1 = new Button("Button1");
button2 = new Button("Button2");
button3 = new Button("Button3");

frame.add(panel);
panel.add(button1);
panel.add(button2);
panel.add(button3);
}
public static void main(String s[])
{
framex obj = new framex();
obj.fun();
}
}
ankush!!
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!!
ankush!!
Bosun Bello
Ranch Hand

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


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

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();
obj.show();//try this
this is the entire main of an app I wrote that works.
public static void main (String args[]) {
new DiceRolls().show();
}


SCJP
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!!
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
Ankush,
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.
~Ryan


<UL TYPE=SQUARE><I><LI>Ryan Burgdorfer<BR><LI>Java Acolyte</I></UL>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problem in running AWT programs!!