0

I've been working on a simple GUI for a java program in Eclipse Window Builder, but being a Java novice and very unfamiliar with Eclipse, I have no idea as to how I incorporate my program with the code for the interface, this is what I've got so far

The Autogenerated code

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 (in the same java file)

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)); 
     }
  });
}

I'm aware of the fact that I am calling the CPGUI without a composite (whatever that actually is) and some strange int called style, I've no idea what to do, I haven't the foggiest idea as to how SWT works, I assumed window builder would just spit out usable code that I could incorporate into my project.

R.McGuigan
  • 13
  • 5

2 Answers2

0

You might have a look at this tutorial: Eclipse RCP to learn about creating GUI within the Eclipse environment. I followed that and created a very basic layout within Eclipse. To find more details about working with SWT, try to look at this other tutorial: SWT Tutorial. This will help you to get into more details about GUI in Eclipse.

fran_jo
  • 69
  • 9
0

If you want to build a GUI with Eclipse but not for Eclipse, you probably accidentally chose the SWT instead of the Swing GUI framework (you have mixed both which is possible but not as you did it):

See How to create a Swing application with the Eclipse WindowBuilder (spoiler: pay attention what you choose in the New... dialog)

howlger
  • 31,050
  • 11
  • 59
  • 99
  • Well that clears quite a lot up, pretty sure I intended it to be with swing to start with, but I'm not experienced with eclipse or window builder, so I guess it somehow ended up with SWT, thanks! – R.McGuigan Aug 04 '17 at 12:42