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

AWT

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, there
could anyone explain why the result of executing the following two Applets(A, B) are so different? when i comment line1 in A there is no effect in the outcome. what is the magic of Panel???
//A
import java.applet.*;
import java.awt.*;
public class Appletandpaneltest extends Applet{
public void init(){
Panel p= new Panel();
p.setLayout(new BorderLayout());//1
p.add(new Button("hello"), BorderLayout.EAST);
p.add(new Button("bye"), BorderLayout.WEST);
add(p);
}
}
//B
import java.applet.*;
import java.awt.*;
public class Appletandpaneltest extends Applet{
public void init(){
setLayout(new BorderLayout());
add(new Button("hello"), BorderLayout.EAST);
add(new Button("bye"), BorderLayout.WEST);
}
}
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi fengqiao cao,
An applet uses the default layout scheme FlowLayout. In applet A, you create a panel & make it some other layout. Then you add it to the applet which has not had its layout changed. So the buttons do not appear as you expect. In applet B, you change the default layout that the applet itself is using to BorderLayout. Then you see the behaviour of the layout manager that you would expect.
Hope that helps,
KKoszegi
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change your code a bit and see the effects to understand this better:

You may try removing the lines for buttons "hello", "bye" and "hi" from the above code and see the effect.
------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/
)
 
Grow your own food... or this tiny ad:
The trailboss has a kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic