Home Segments Top Top Previous Next

728: Mainline

If you like, you can specify explicitly that you want a content pane to use the border layout. You first create an instance of the BorderLayout class, having imported the java.awt package; then, you add a setLayout statement to the frame's constructor to tie the new border layout to the content pane:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MovieApplication extends JFrame {
 public static void main (String argv []) {
  new MovieApplication("Movie Application");
 }
 private Meter meter;
 public MovieApplication(String title) {
  super(title);
  meter = new Meter(0, 30);
  getContentPane().setLayout(new BorderLayout()); 
  getContentPane().add("Center", meter);   
  addWindowListener(new LocalWindowListener()); 
  setSize(350, 150); 
  show(); 
 } 
 // Define window adapter 
 private class LocalWindowListener extends WindowAdapter { 
  public void windowClosing(WindowEvent e) { 
    System.exit(0); 
}}}