【從零開始學 Java 程式設計】 線上教學課程目錄,使用 Java 程式語言,開發應用程式。
main -> createAndShowGUI -> addComponentsToPane
import javax.swing.*;
import java.awt.*;
public class DemoSwing {
public void addComponentsToPane(Container pane) {
//宣告定義元件與對應處理事件...
JLabel jLabel = new JLabel("哈囉 Swing!");
//在 Pane 畫面中加入元件,pane.add(...);
pane.add(jLabel);
}
private DemoSwing() {
JFrame frame = new JFrame("Swing 起手式範例");
// 獲取螢幕解析度
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
// 設定視窗大小佔螢幕四分之一
frame.setSize(dimension.width/2, dimension.height/2);
//設定視窗顯示在螢幕畫面中間位置
int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2);
int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2);
frame.setLocation(x, y);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設定關閉可以關掉程式
//在 Pane 畫面中加入元件
addComponentsToPane(frame.getContentPane());
//frame.pack();
frame.setVisible(true);
}
//最一開始程式進入點
public static void main(String[] args) {
//使用 invokeLater 確保 UI 在排程執行緒內
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
new DemoSwing();
}
});
}
}
那這次的課程就介紹到這邊囉~
順帶一提,KT 線上教室,臉書粉絲團,會不定期發佈相關資訊,不想錯過最新資訊,不要忘記來按讚,加追蹤喔!也歡迎大家將這套課程分享給更多人喔。
我們下次再見囉!!!掰掰~
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing