尝试在 window builder 中构建一个简单的 GUI,完全不知道我接下来要做什么

Trying to construct a simple GUI in window builder, at a complete loss with regards to what I do next

我一直在为 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
}

My Main(在同一个 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 是如何工作的,我假设 window 构建器只会吐出我可以合并到我的项目中的可用代码。

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

如果您想使用 Eclipse 而不是为 Eclipse 构建 GUI,您可能 不小心选择了 SWT 而不是 Swing GUI 框架(您混合了两者 is possible 但不像你那样做):

How to create a Swing application with the Eclipse WindowBuilder(剧透:注意你在新... 对话)