java之構造方法建立JFrame
阿新 • • 發佈:2019-02-06
package test; import java.awt.*; import javax.swing.*; public class demo extends JFrame{ private JButton jb = null;; public static void main(String[] args){ demo demo1 = new demo(); } //建構函式 public demo(){ jb = new JButton("點我"); this.add(jb); this.setTitle("你好啊!"); this.setLocation(100,200); this.setSize(300,200) ; //關閉視窗時保證JVM依然退出 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true) ; } }