圖書館管理系統第一版出爐,上週一開會時,總經理問我,要開發校務還是薪資系。
當時,毫不考慮的說薪資系統,沒想到卻是惡夢的開始。。。。。。。冏oz
因為該系統要將目前既有的PHP版轉換成離線的JAVA版,並且使用SWT來做開發。
預計二月底要出來,哈哈。。。。。。哈哈。。。。。我苦命啊~~~~~~
沒開發過GUI的程式,SWT更是第一次聽過。。。。XD,糗大了~
心想,答應就答應了,做吧!反正沒摸過SWT,摸摸看囉。。。。
我開發環境是使用eclipse 3.11+ Visual Editor 1.1.0.1。
整體來說,網路上已經有很多SWT的入門文章與介紹。因此,不想作描述。
而我所要寫的,是我自己在摸索SWT時,在網路上solution較少的,也比較偏向實務面。
一般來說,開發一套單機AP時,都會看到一個啟動畫面,如何利用SWT來設計啟動畫面呢?
在此,先介紹方法一: |
| 一、我們可以先寫一支繼承Composite的程式,假設該檔名為SalayerWelcome.java程式內容如下: |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 |
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
public class SalayerWelcome extends Composite {
private Label label = null;
public SalayerWelcome(Composite parent, int style) {
super(parent, style);
initialize();
}
private void initialize() {
label = new Label(this, SWT.None | SWT.CENTER);
label.setBounds(new org.eclipse.swt.graphics.Rectangle(0,0,584,438));
label.setImage(new Image(Display.getCurrent(), “/Users/Mac/Documents/pay_workspace/Salayer/images/logo.jpg”));
setSize(new Point(584, 438));
}
} |
|
二、再來就是寫呼叫啟動畫面的主程式,檔名為SalayerMain.java。在main當中,是啟動剛剛所寫的SalayerWelcome,利用Thread
讓它呈現10秒左右,10秒過後將該畫面dispose,然後將SalayerMain Method給New起來,至於SalayerMain Method寫的主要任務
就是呈現出系統畫面。 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 |
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class SalayerMain {
private Display display;
public static void main(String[] args) {
try {
Display display = Display.getDefault();
Shell shell = new Shell(display, SWT.None);
shell.setLayout(new FormLayout());
shell.setText(“歡迎使用薪資管理系統”);
Rectangle shellRect = shell.getBounds();
Rectangle dispRect = display.getBounds();
int x = (dispRect.width – shellRect.width) / 2;
int y = (dispRect.height – shellRect.height) / 2;
shell.setLocation(x,y);
new SalayerWelcome(shell, SWT.None);
shell.pack();
shell.open();
Thread.sleep(10000);
shell.dispose();
new SalayerMain();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public SalayerMain(){
display = Display.getDefault();
SalayerMainShell thisClass = new SalayerMainShell();
thisClass.create_salayershell();
thisClass.salayershell.open();
while (!thisClass.salayershell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
} |
|
| 三、執行畫面: |
 |
相關文章如下:
尚無評論。
RSS feed for these comments.
|
TrackBack URI