Awt Panel
Advertisements
Awt Panel
It is a predefined class used to provide a logical container to hold various GUI component. Panel always should exist as a part of frame.
Note: Frame is always visible to end user where as panel is not visible to end user.
Panel is a derived class of container class so you can use all the methods which is used in frame.
Syntax
Panel p=new Panel(); p.setBackground(Color.red); p.setSize(400,300);
Example frame and panel
import java.awt.*; class PanelFrame { PanelFrame() { Frame f=new Frame(); f.setSize(600,400); f.setBackground(Color.pink); f.setLayout(new BorderLayout()); Panel p1=new Panel(); p1.setBackground(Color.cyan); Label l1 =new Label("Enter Uname"); TextField tf1=new TextField(15); Label l2=new Label("Enter Passward"); TextField tf2=new TextField(15); p1.add(l1); p1.add(tf1); p1.add(l2); p1.add(tf2); f.add("North",p1); Panel p2=new Panel(); p2.setBackground(Color.yellow); Button b1=new Button("Send"); Button b2=new Button("Clear"); p2.add(b1); p2.add(b2); f.add("South",p2); f.setVisible(true); } public static void main(String[] args) { PanelFrame pf=new PanelFrame(); } }
Download code Click
Google Advertisment