0
我已經完全初始化我的SWT殼的主要方法裏面如下:SWT:最好使用新的display.shell方法?
public class MySWTTemplate;
public static void main(String[] args){
Display display = new display();
Shell shell = new Shell(display);
shell.setSize(250, 250);
Rectangle bds = getMonitor().getBounds();
Point p = shell.getSize();
int xPos = (bds.width - p.x)/2;
int yPos = (bds.height - p.y)/2;
shell.setBounds(xPos, yPos, p.x, p.y);
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch()){
display.sleep();
}
}
display.dispose();
}
但我見過一些人對其進行設置,以便shell啓動和定義自己的方法,而在啓動時在屏幕上的細胞定位在另一箇中,並且都通過主要方法簡單地被調用。我採取了這樣的刺,並提出以下幾點:
public class MySWTTemplate;
public static void main(String[] args){
Display display = new Display();
new MySWTTemplate(display);
display.didpose();
}
public MySWTTemplate(Display display){
Shell shell = new Shell(display);
shell.setSize(250, 250);
shellPos(shell);
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch()){
display.sleep()
}
}
}
public void shellPos(Shell shell){
Rectangle bds = shell.getMonitor().getBounds();
Point p = shell.getSize();
int xPos = (bds.width - p.x)/2;
int yPos = (bds.height - p.y)/2;
shell.setBounds(xPos, yPos, p.x, p.y);
}
兩者都工作。我的兩個問題是
1)這是爲視覺組織完成的,還是爲每個工作調用單獨的方法提供資源優勢?
2)有人可以在第二個代碼中解釋創建MySWTTemplate()方法時發生了什麼,然後在主方法中使用「new MySWTTemplate(display)」簡單調用?爲什麼命名與課程完全一樣?而這是什麼根本上說(你可以不設置此方法只公開與任何其他方法名。
謝謝......並會做。我記得建設者,我會刷新自己。在此期間,你能解釋爲什麼'public MySWTTemplate(Display display)'不是一種方法,'public void shellPos(Shell shell)'是一種方法嗎?除非我在調用shellPos方法時出錯。另外,'public static void main(String [] args)被認爲是一個正確的方法? – dbconfession
構造函數具有與該類相同的名稱,並且沒有返回類型(並使用'new'調用)。方法有一個返回類型(在'shellPos'情況下爲'void')。 「主」是一種方法,是的。更確切地說,是_static_方法(它屬於整個類而不是此類的對象)。 –
因此,靜態指定可以在類中使用方法。將修飾符完全拋出允許它只能被類內的特定對象訪問? – dbconfession