In this video, we will create 5 buttons and give it to a Java AWT BorderLayout manager to study how it organizes them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
package AwtDemoPkg; import java.awt.BorderLayout; import java.awt.Button; import java.awt.Frame; import java.awt.GridLayout; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; public class FrameWindow extends Frame implements WindowListener { public FrameWindow(String FrameTitle) { //Display the Frame Window super(FrameTitle); setSize(460, 170); setLocation(100,100); addWindowListener(this); //Sample 01: Create Five Buttons Button btn1 = new Button("North"); Button btn2 = new Button("South"); Button btn3 = new Button("East"); Button btn4 = new Button("West"); Button btn5 = new Button("Center"); //Sample 02: Add it to the Frame Window add(BorderLayout.NORTH, btn1); add(BorderLayout.SOUTH, btn2); add(BorderLayout.EAST, btn3); add(BorderLayout.WEST, btn4); add("Center", btn5); } public void windowOpened(WindowEvent e) {} public void windowClosed(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowActivated(WindowEvent e) {} public void windowDeactivated(WindowEvent e) {} public void windowClosing(WindowEvent e) { this.dispose(); } } |
Categories: AWT-Tube