使用JFram创建一个简单的窗口

import java.awt.*;
import javax.swing.*;

public class TopLevelWindow {

 private static void createWindow() {

//  Create and set up the window.

  JFrame frame = new JFrame("Simple GUI");

  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  JLabel textLabel = new JLabel("I'm a label in the window",SwingConstants.CENTER);

  textLabel.setPreferredSize(new Dimension(300, 100));

  frame.getContentPane().add(textLabel, BorderLayout.CENTER);

//  Display the window.

  frame.setLocationRelativeTo(null);

  frame.pack();

  frame.setVisible(true);

 }

 public static void main(String[] args) {

  createWindow();

 }

}

 

posted @ 2009-04-24 22:18  kanjc  阅读(381)  评论(0编辑  收藏  举报