Only one button is getting displayed in java awt -
i trying create display multiple buttons on it. however, 1 button being displayed. why happening? layout manager? did go wrong?
my code:
import java.awt.*; class buttondemo extends frame { button[] b;frame frame; buttondemo() { int i=0; b=new button[12]; frame=new frame(); frame.setlayout(new borderlayout()); (i=0;i<12;i++) { b[i] = new button("hello"+i);frame.add(b[i]); } frame.add(new button("hello")); frame.add(new button("polo")); frame.pack(); frame.setvisible(true); } public static void main(string args[]) { buttondemo bd = new buttondemo(); } }
this expected behaviour borderlayout
.
borderlayout
allow single component reside in each of it's 5 available positions.
you adding 2 buttons same position last 1 displayed.
try...
- adding 1 button
borderlayout.north
,borderlayout.south
positions - using different layout manager
take @ a visual guide layout managers , laying out components within container more details...
Comments
Post a Comment