2011年8月24日

一個最簡單的JAVA Swing 視窗範例

http://uds.tw/page.php?i=57

package pbtw;

import javax.swing.*;

/**
 * @author feather
 * 
 */
public class SetConfig {

 private static void ShowGUI() {
  JFrame.setDefaultLookAndFeelDecorated(true);
  JFrame frame = new JFrame("HelloWorldSwing");

  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  JLabel label = new JLabel("Hello World");

  frame.getContentPane().add(label);

  frame.setSize(300, 300);
  // frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
 }

 public static void main(String[] args) {
  try {
   // UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  } catch (Exception e) {
   e.printStackTrace();
  }
  javax.swing.SwingUtilities.invokeLater(new Runnable() {
   public void run() {
    ShowGUI();
   }
  });
 }

}

沒有留言:

張貼留言