Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in running AWT programs!!

 
ankush walia
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try calling your setvisible method after the components have been added.
Bosun
 
Randall Twede
Ranch Hand
Posts: 4481
3
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
 
kavya krushi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic