import java.awt.*; import java.io.*; public class mframe extends Frame{ Button bn,bs,be,bw,bc; public mframe(){ super("maha"); Button bn = new Button("North"); Button bs = new Button("South"); Button be = new Button("East"); Button bw = new Button("West"); Button bc = new Button("Center"); setLayout(new FlowLayout()); //add(bn); add(bs); add(be); add(bn); add(bn);} try{ add("North",bn); setSize(300,300); setVisible(true); System.out.println("Added north and sleepling"); Thread.sleep(2000); add("East",be); setSize(300,300); setVisible(true); System.out.println("Added East and sleepling"); Thread.sleep(2000); add("South",bn); setSize(300,300); setVisible(true); System.out.println("Added South and sleepling"); Thread.sleep(2000); add("West",bw); setSize(300,300); setVisible(true); System.out.println("Added West and sleepling"); Thread.sleep(2000); add("Center",bc); setSize(300,300); setVisible(true); System.out.println("Added Center and sleepling"); Thread.sleep(2000); } // catch(InterruptedException e) {} } public static void main(String args[]){ new mframe(); } } import java.awt.*; import java.io.*; public class mframe1 extends Frame{ Button bn,bs,be,bw,bc; public mframe1(){ super("maha"); Button bn = new Button("North"); Button bs = new Button("South"); Button be = new Button("East"); Button bw = new Button("West"); Button bc = new Button("Center"); setLayout(new FlowLayout()); add(bn); add(bs); add(be); add(bn); add(bn);}
public static void main(String args[]){ new mframe1(); } } /* here nothing happens untill I store new mframe1() object is frame f object and call f.show(). frame f=new mframe1(); f.show(); please explain it to me.Is it due to layout as in border layout I don't have to add f.show. */ jaideep
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
Hi Your second code is like this : public class mframe1 extends Frame{ Button bn,bs,be,bw,bc; public mframe1(){ super("maha"); Button bn = new Button("North"); Button bs = new Button("South"); Button be = new Button("East"); Button bw = new Button("West"); Button bc = new Button("Center"); setLayout(new FlowLayout()); add(bn); add(bs); add(be); add(bn); add(bn);} public static void main(String args[]){ new mframe1(); } } In case of Frame, to display it you have to explicitly call the function to display it. Also you've to call setSize() function to assign it a size. In the first program You are useing it , thats why it's coming. Try with this: import java.awt.*; import java.io.*; public class mframe extends Frame{ Button bn,bs,be,bw,bc; public mframe(){ super("maha"); Button bn = new Button("North"); Button bs = new Button("South"); Button be = new Button("East"); Button bw = new Button("West"); Button bc = new Button("Center"); setLayout(new FlowLayout()); add(bn); add(bs); add(be); add(bn); add(bn);} public static void main(String args[]){ mframe t = new mframe(); t.setSize(100,100); t.setVisible(true); } } Hope this helps you Shikhar
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.