Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Tricky Question from Mock test

 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Pls can anybody help me , Why the frame is blank.
import java.awt.*;
public class CompLay extends Frame{
public static void main(String argv[]){
CompLay cl = new CompLay();
}
CompLay(){
setLayout(new FlowLayout());
Panel p = new Panel();
p.setBackground(Color.pink);
p.add(new Button("One"));
p.add(new Button("Two"));
p.add(new Button("Three"));

Panel p1 =new Panel();
p1.setBackground(Color.red);
p1.add(new Button("four"));

add(p);
add(p1);

setLayout(new BorderLayout());
setSize(300,300);
setVisible(true);
}
}
If you convert from BorderLayout to FlowLayout, u can see the result but why vice versa is not showing any result.Pls help me
Prasad
------------------
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when trying to jump on any interface changes mind one singal thing that whether changed interface implement layoutmanager2 or not. if it implements you just get nothing on changing.
further clarification will not be entertained.

Originally posted by Prasad Ballari:
Hi,
Pls can anybody help me , Why the frame is blank.
import java.awt.*;
public class CompLay extends Frame{
public static void main(String argv[]){
CompLay cl = new CompLay();
}
CompLay(){
setLayout(new FlowLayout());
Panel p = new Panel();
p.setBackground(Color.pink);
p.add(new Button("One"));
p.add(new Button("Two"));
p.add(new Button("Three"));

Panel p1 =new Panel();
p1.setBackground(Color.red);
p1.add(new Button("four"));

add(p);
add(p1);

setLayout(new BorderLayout());
setSize(300,300);
setVisible(true);
}
}
If you convert from BorderLayout to FlowLayout, u can see the result but why vice versa is not showing any result.Pls help me
Prasad


 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are basically over writing the Layout. You have set the Frame layout to Flow, add the panels and again resetting the layout to Border, which is overwriting the previous construction.
BOL
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Prasad,
You are setting Flow layout for the frame first and adds the buttons to it.
Again u r setting Border layout for the frame and set the size to
(300,300). That means u r overwriting the border layout on flow layout. Since the buttons r added to flow layout, u will get a blank window of size(300,300) on the screen.

 
Message for you sir! I think it is a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic