尝试在窗口构建器中构建一个简单的GUI,完全失去了我接下来的工作

时间:2017-08-04 10:58:48

标签: java eclipse swt windowbuilder

我一直在为Eclipse Window Builder中的java程序开发一个简单的GUI,但是作为Java新手并且对Eclipse非常不熟悉,我不知道如何将我的程序与代码相结合界面,这是我到目前为止所得到的

自动生成的代码

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(实际上是什么)以及一些称为样式的奇怪的东西,我不知道该怎么做,我没有&#39;关于SWT如何工作的最模糊的想法,我假设窗口构建器只会吐出可以包含在我的项目中的可用代码。

2 个答案:

答案 0 :(得分:0)

您可以查看本教程:Eclipse RCP以了解如何在Eclipse环境中创建GUI。 我跟着它,在Eclipse中创建了一个非常基本的布局。要查找有关使用SWT的更多详细信息,请尝试查看其他教程:SWT Tutorial。 这将帮助您了解有关Eclipse中GUI的更多详细信息。

答案 1 :(得分:0)

如果你想用Eclipse而不是用Eclipse构建一个GUI,你可能意外地选择了SWT而不是Swing GUI框架(你混合了哪个is possible但不是你做到了):

请参阅 How to create a Swing application with the Eclipse WindowBuilder (剧透:请注意您在新... 对话框中选择的内容)