wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes layout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "layout" Watch "layout" New topic
Author

layout

Jason sigel
Ranch Hand

Joined: Oct 07, 2003
Posts: 30
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
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://aspose.com/file-tools
 
subject: layout
 
Similar Threads
layout
applets
layout flow/border
awt
LAYOUTS. PLS HLP !!!