天天看點

java之JFrame

package test;

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

public class demo{
	
	public static void main(String[] args){
		
		//Jframe 是可添加Swing的容器類
		JFrame jf = new JFrame();
		
		JButton jb = new JButton("點我");
		
		jf.add(jb);
		
		jf.setTitle("你好啊!");
		jf.setLocation(100,200);
		jf.setSize(300,200) ;
		
		//關閉視窗時保證JVM依然退出
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		jf.setVisible(true) ; 
		
	}
}
           
運作結果:<img src="https://img-blog.csdn.net/20160531150818693?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />