• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why components are not displayed

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am haviong the following code which is compiling fine but on running the applet, nothing except a Frame comes. Can you tell me why other components are not displayed and "System.out.println" have not printed.
I am new to java pl help me

code:
import java.awt.*;
import java.applet.Applet;
public class test1 extends Applet{
public void init(){
System.out.println("the size is x = "+this.getSize().width+" and y = "+this.getSize().height);
this.setForeground(Color.blue);
this.setBackground(Color.green);
this.setFont(new Font("serif",Font.BOLD,15));
Button b= new Button("press me");
Canvas c = new Canvas();
CheckboxGroup cbg = new CheckboxGroup();
Checkbox ab1 = new Checkbox("just check this",true,cbg);
Checkbox ab2 = new Checkbox("just check that",true,cbg);
Checkbox ab3 = new Checkbox("just check there",true,cbg);
Choice c1= new Choice();
c1.add("this this my choice");
c1.add("this this your choice");
Label l = new Label("this is label",Label.CENTER);
List Li = new List(4,true);
Li.add("this is 1");
Li.add("this is 2");
Li.add("this new 1");
ScrollPane sp= new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
Label lb = new Label("scrollpane is my owner");
lb.setFont(new Font("monospaced",Font.PLAIN,15));
sp.add(lb);
sp.setSize(50,50);
Scrollbar sc = new Scrollbar(Scrollbar.VERTICAL,25,25,0,100);
TextField tf = new TextField("my name is shikhar",15);
Frame f = new Frame("FRAME");
f.setSize(500,500);
f.setVisible(true);
FileDialog fg = new FileDialog(f,"this is to select",FileDialog.SAVE);
System.out.println("the item fron list is "+Li.getItem(2));
add(b);
add(c);
add(ab1);
add(ab2);
add(ab3);
add(c1);
add(l);
add(Li);
add(sp);
add(sc);
add(tf);
add(f);
}
}
thanks in advance
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Moderators...this should thread should probably be in a different folder?]
This isn't how you associate a Frame object with an Applet.
I think you might benefit from reading a code "cookbook" for some of the techniques on these things or looking at the code examples on the Java Tutorial at Sun's site. www.javasoft.com or some other book.
That being said, the code can be "fixed" with:
0. take out the line "add(f);"
1. Change line "Frame f = new Frame( "FRAME" );" to "f = new Frame( "FRAME");"
2. Put "Frame f;" outside of the Applet's init() method.
3. Add "fg.setVisible(true);" after the line "FileDialog fg = new FileDialog(f,"this is to select",FileDialog.SAVE);"
This will make everything display...but that's about all.
The frame will display first, then the file dialog which you will have to dismiss, and then the applet.
I answered your question but I think you need to dig a little deeper to find out why you wouldn't necessarily want to take this approach in working code.
Best regards,
Steve Butcher
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic