Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

layout

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
So there I was, trapped in the jungle. And at the last minute, I was saved by this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic