2017-08-04 62 views
0

我一直在爲Eclipse Window Builder中的Java程序開發一個簡單的GUI,但作爲Java新手而且很陌生與Eclipse,我不知道,我怎麼納入我的程序與界面的代碼,這是我走到這一步,試圖在窗口構建器中構建一個簡單的GUI,完全沒有關於我下一步做什麼

自動生成的代碼

public class CPGUI extends Composite { 
private Text text_2; 
private Text text_1; 
private Text text; 
private Text text_3; 
private Text text_4; 
private Text text_5; 
private Text text_9; 
private Text text_10; 
private Text text_11; 

private JTextField Cards; 
private JTextField Cleared; 
private JTextField Remaining; 
private JTextField TotalMnHr; 
private JTextField CompletedMnHr; 
private JTextField MnHrRemaining; 

/** 
* Create the composite. 
* @param parent 
* @param style 
*/ 
public CPGUI(Composite parent, int style, Task[] AllTasks, int[] data) { 
    super(parent, style); 

    setLayout(new GridLayout(6, true)); 
    new Label(this, SWT.NONE); 

    Label lblEstMnhrs = new Label(this, SWT.NONE); 
    lblEstMnhrs.setText("EST. MNHRS"); 
    new Label(this, SWT.NONE); 

    Label lblDates = new Label(this, SWT.NONE); 
    lblDates.setText("DATES"); 
    new Label(this, SWT.NONE); 

    Label lblTasks = new Label(this, SWT.NONE); 
    lblTasks.setText("TASKS"); 

    Label lblTotal = new Label(this, SWT.NONE); 
    lblTotal.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 
    lblTotal.setText("TOTAL"); 

    text_3 = new Text(this, SWT.BORDER); 
    text_3.setEditable(false); 
    text_3.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); 

    Label label = new Label(this, SWT.NONE); 
    label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 
    label.setText("DEADLINE"); 

    text_9 = new Text(this, SWT.BORDER); 
    text_9.setEditable(false); 
    text_9.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); 

    Label lblTotal_1 = new Label(this, SWT.NONE); 
    lblTotal_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 
    lblTotal_1.setText("TOTAL"); 

    text = new Text(this, SWT.BORDER); 
    text.setEditable(false); 
    text.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); 

    Label lblFinished = new Label(this, SWT.NONE); 
    lblFinished.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 
    lblFinished.setText("FINISHED"); 

    text_4 = new Text(this, SWT.BORDER); 
    text_4.setEditable(false); 
    text_4.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); 

    Label label_1 = new Label(this, SWT.NONE); 
    label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 
    label_1.setText("TODAY"); 

    text_10 = new Text(this, SWT.BORDER); 
    text_10.setEditable(false); 
    text_10.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); 

    Label lblCleared = new Label(this, SWT.NONE); 
    lblCleared.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 
    lblCleared.setText("CLEARED"); 

    text_1 = new Text(this, SWT.BORDER); 
    text_1.setEditable(false); 
    text_1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); 

    Label lblRemaining = new Label(this, SWT.NONE); 
    lblRemaining.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 
    lblRemaining.setText("REMAINING"); 

    text_5 = new Text(this, SWT.BORDER); 
    text_5.setEditable(false); 

    Label label_2 = new Label(this, SWT.NONE); 
    label_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 
    label_2.setText("MNHRS LEFT"); 

    text_11 = new Text(this, SWT.BORDER); 
    text_11.setEditable(false); 
    text_11.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); 

    Label lblRemaining_1 = new Label(this, SWT.NONE); 
    lblRemaining_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 
    lblRemaining_1.setText("REMAINING"); 

    text_2 = new Text(this, SWT.BORDER); 
    text_2.setEditable(false); 
    text_2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); 

    Label lblProgress = new Label(this, SWT.NONE); 
    lblProgress.setText("PROGRESS"); 

    ProgressBar progressBar = new ProgressBar(this, SWT.NONE); 
    GridData gd_progressBar = new GridData(SWT.RIGHT, SWT.CENTER, true, true, 3, 1); 
    gd_progressBar.widthHint = 357; 
    progressBar.setLayoutData(gd_progressBar); 
    new Label(this, SWT.NONE); 
    new Label(this, SWT.NONE); 

    pack(); 
    setSize(549, 300);   
    setVisible(true); 

    Button btnUpdate = new Button(this, SWT.NONE); 

    btnUpdate.setText("UPDATE"); 

    btnUpdate.addListener(SWT.Selection, new Listener() { 
     public void handleEvent(Event e) { 
      switch (e.type) { 
      case SWT.Selection: 
       int[] data; 
       data = dataCalculator(AllTasks); 
       Cleared = new JTextField(data[1]); 
       Remaining = new JTextField(data[4]); 
       CompletedMnHr = new JTextField(data[3]); 
       TotalMnHr = new JTextField(data[0]); 
       MnHrRemaining = new JTextField(data[2]); 
      break; 
      } 
     } 
     }); 

    new Label(this, SWT.NONE); 
    new Label(this, SWT.NONE); 
    new Label(this, SWT.NONE); 
    new Label(this, SWT.NONE); 
} 

@Override 
protected void checkSubclass() { 
    // Disable the check that prevents subclassing of SWT components 
} 

我的主要(在同一java文件)

public static void main(String[] args) 
{ 
int NumTasks; 
NumTasks = NumTasks(); 

Task[] AllTasks = new Task[NumTasks]; 
Composite Parent = null; 
int Style = 1; 

for(int i = 0; i < AllTasks.length; i++) 
{ 
    AllTasks[i] = new Task(); 
} 
SwingUtilities.invokeLater(new Runnable() { 
    @Override 
    public void run() { 
     new CPGUI(AllTasks, dataCalculator(AllTasks)); 
    } 
    }); 
} 

我意識到我沒有組合(實際上是什麼)調用CPGUI和一些奇怪的int稱爲樣式,我不知道該怎麼做,我不知道怎麼做SWT的作品,我假設窗口建設者只是吐出我可以合併到我的項目中的可用代碼。

+0

要調用在Swing事件分派線程的SWT GUI組件...這將不會工作。 。 –

+0

請參閱:http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet1.java對於一個非常簡單的演示... –

+0

在這個演示中,'Shell'窗口是一個'Composite' –

回答

0

如果你想建立與Eclipse而不是Eclipse的GUI,你可能無意中選擇了SWT而不是搖擺 GUI框架(你有混合這兩種is possible但不是你做到了):

How to create a Swing application with the Eclipse WindowBuilder(擾流板:關注您在新選擇什麼...對話框)

+0

好吧,清除了很多,很確定我打算用swing來開始,但我沒有使用eclipse或window builder的經驗,所以我想這不知何故以SWT結束了,謝謝! –

0

您可以參閱本教程:Eclipse RCP瞭解如何在Eclipse環境中創建GUI。 我遵循這一點,並在Eclipse中創建了一個非常基本的佈局。要找到關於使用SWT的更多細節,請嘗試查看其他教程:SWT Tutorial。 這將幫助您瞭解更多關於Eclipse中GUI的細節。

相關問題