9月24日 [JAVA]JFrame(視窗介面) 架構

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

public class Poly_main extends JFrame implements WindowListener,ActionListener {

//宣告 swing 物件 ex:
JButton funStart;

public Poly_main() {
super("FRAM");
//FRAME 設定
addWindowListener(this); //視窗事件監聽器

setSize(1000, 600); //視窗大小 長跟寬
setLocation(40, 40); //視窗左上角在螢幕視窗的位置 X跟Y
setVisible(true); //是否看的見
setLayout(new BorderLayout()); //版面配置


//instanciate
funStart=new JButton("請案我開始"); //初始化

//adding
getContentPane().setLayout(null); //版面配置 關閉
getContentPane().add(funStart); //在版面上放上 funStart

//setBounds
funStart.setBounds(10,10,100,25); // funStart按鈕 在版面 X=10 Y=10 長=100 寬=25
//add Listener
funStart.addActionListener(this); //監聽是否有按下

}

//各種監聽事件(一定要打這一段喔)
public void windowDeactivated(WindowEvent we) {}
public void windowActivated(WindowEvent we) {}
public void windowClosing(WindowEvent we) {System.exit(0); }
public void windowClosed(WindowEvent we) {}
public void windowOpened(WindowEvent we) {}
public void windowDeiconified(WindowEvent we) {}
public void windowIconified(WindowEvent we) {}

public void actionPerformed(ActionEvent ae){ //使用者click事件
}

public static void main(String args[]){ //這裡我不用多說了吧!!
Poly_main demo=new Poly_main();
demo.setVisible(true);
}
}

留言

這個網誌中的熱門文章

angular 如何Http 如何設定 CORS (Cross-Origin Resource Sharing)

Google Map 單車路徑計算坡度和角度小工具

Google URL Shortener API 快速教學