BorderLayout: A border layout lays out a container, arranging and - TopicsExpress



          

BorderLayout: A border layout lays out a container, arranging and resizing its components to fit in five regions: north, south, east, west, and center. Each region may contain no more than one component, and is identified by a corresponding constant: NORTH, SOUTH, EAST, WEST, and CENTER. When adding a component to a container with a border layout, use one of these five constants, code: import java.io.*; import java.applet.*; import java.awt.*; import java.applet.*; import java.awt.*; import java.lang.*; import java.awt.event.*; public class border extends Frame implements ActionListener { TextArea t1; Button b1,b2,b3,b4; public border() { setLayout(new BorderLayout()); t1=new TextArea(3,50); b1=new Button("north"); b2=new Button("east"); b3=new Button("west"); b4=new Button("south"); add(t1,BorderLayout.CENTER); add(b1,BorderLayout.NORTH); add(b2,BorderLayout.EAST); add(b3,BorderLayout.WEST); add(b4,BorderLayout.SOUTH); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); t1.setFont(new Font("Courier New",Font.BOLD,15)); } public void actionPerformed(ActionEvent e) { if(e.getSource()==b1) { t1.setText(" North Button Clicked"); } if(e.getSource()==b2) { t1.setText(" east Button Clicked"); } if(e.getSource()==b3) { t1.setText(" west Button Clicked"); } if(e.getSource()==b4) { t1.setText(" south Button Clicked"); } } public static void main(String a[]) { border v=new border(); v.setSize(300,300); v.show(); } }
Posted on: Sat, 27 Jul 2013 14:00:25 +0000

Trending Topics



Recently Viewed Topics




© 2015