title: Java Eclipse Composite Layout program structure
body: <p>A bit new to programming, I'm trying to write a GUI for a little custom built drone project. Hopefully I can get it to display the telemetry/camera and buttons for commands. I don't want to go to far without understanding the proper structure I should use. So far I have created a composite layout with a few place holders. I am ok with using events for buttons and keys etc, but can not see how to easily set up a 'main loop' that runs each cycle. For example I want to show the seconds elapsed for the gui/flight etc in the bottom right hand corner which is updated from the difference between the start time and current time. Any help on structure would be awesome thanks.</p>
  <p>I know the layout is rubbish and some imports not needed etc, its purely a test to get the right setup to begin with :)</p>
  <pre><code>package testGUI;
  
  import org.eclipse.swt.widgets.Composite;
  import org.eclipse.swt.widgets.Display;
  import org.eclipse.swt.widgets.Event;
  import org.eclipse.swt.layout.GridLayout;
  import org.eclipse.swt.widgets.ToolBar;
  
  import org.eclipse.swt.SWT;
  import org.eclipse.swt.graphics.Image;
  import org.eclipse.swt.widgets.Label;
  import org.eclipse.swt.widgets.Listener;
  import org.eclipse.swt.widgets.Shell;
  import org.eclipse.swt.widgets.Text;
  import org.eclipse.swt.widgets.Group;
  import org.eclipse.ui.forms.widgets.FormToolkit;
  import org.eclipse.swt.widgets.Canvas;
  import org.eclipse.swt.custom.CLabel;
  import org.eclipse.swt.events.MouseMoveListener;
  import org.eclipse.swt.events.MouseEvent;
  
  public class TestComposite extends Composite {
      private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
  
      static int elapsedSecondsGUI;
  
      public static void main(String[] args) {
          System.out.println(&quot;Working Directory = &quot; + System.getProperty(&quot;user.dir&quot;));
          long startTimeGUI = System.currentTimeMillis();
          elapsedSecondsGUI = 0;
          Display display = new Display();
          Shell shell = new Shell(display);
          shell.setLayout(new GridLayout(1, false));
  
          TestComposite myNewGUI = new TestComposite(shell, SWT.NONE);
  
          shell.pack();
          shell.open();
          
          display.addFilter(SWT.None, new Listener() {
              
              @Override
              public void handleEvent(Event event) {
                  char c = event.character;
                  System.out.println(c);
              }
              
          });
          
          while (!shell.isDisposed()) {
  
              // main loop
              elapsedSecondsGUI = (int) ((System.currentTimeMillis() - startTimeGUI) / 1000);
              //TestComposite.autoUpdate();
  
              if (!display.readAndDispatch())
                  display.sleep();
          }
          display.dispose();
      }
  
  
      
      /**
       * Create the composite.
       * 
       * @param parent
       * @param style
       */
      public TestComposite(Composite parent, int style){
          
          super(parent, style);
          setLayout(null);
  
          Group grpCurrentRawData = new Group(this, SWT.BORDER | SWT.SHADOW_ETCHED_IN);
          grpCurrentRawData.setText(&quot;Current Raw Data&quot;);
          grpCurrentRawData.setBounds(10, 91, 233, 251);
  
          Label lblNewLabel_1 = new Label(grpCurrentRawData, SWT.NONE);
          lblNewLabel_1.setBounds(86, 116, 70, 20);
          lblNewLabel_1.setText(&quot;New Label&quot;);
  
          Label lblGpsX = new Label(grpCurrentRawData, SWT.NONE);
          lblGpsX.setBounds(10, 64, 70, 20);
          lblGpsX.setText(&quot;GPS X&quot;);
  
          Label lblGpsY = new Label(grpCurrentRawData, SWT.NONE);
          lblGpsY.setBounds(10, 90, 70, 20);
          lblGpsY.setText(&quot;GPS Y&quot;);
  
          Label lblAltitude = new Label(grpCurrentRawData, SWT.NONE);
          lblAltitude.setBounds(10, 116, 70, 20);
          lblAltitude.setText(&quot;Altitude&quot;);
  
          Label lblNewLabel = new Label(grpCurrentRawData, SWT.NONE);
          lblNewLabel.setBounds(86, 64, 70, 20);
          lblNewLabel.setText(&quot;New Label&quot;);
  
          Label lblNewLabel_2 = new Label(grpCurrentRawData, SWT.NONE);
          lblNewLabel_2.setBounds(86, 90, 70, 20);
          lblNewLabel_2.setText(&quot;New Label&quot;);
  
          Group grpMisc = new Group(this, SWT.BORDER | SWT.SHADOW_ETCHED_IN);
          grpMisc.setText(&quot;Misc&quot;);
          grpMisc.setBounds(10, 357, 233, 143);
  
          Label label = new Label(grpMisc, SWT.NONE);
          label.setText(&quot;New Label&quot;);
          label.setBounds(109, 116, 70, 20);
  
          Label lblLocalTime = new Label(grpMisc, SWT.NONE);
          lblLocalTime.setText(&quot;Local time&quot;);
          lblLocalTime.setBounds(10, 64, 70, 20);
  
          Label lblFlightTime = new Label(grpMisc, SWT.NONE);
          lblFlightTime.setText(&quot;Flight time&quot;);
          lblFlightTime.setBounds(10, 90, 70, 20);
  
          Label lblSomethingElse = new Label(grpMisc, SWT.NONE);
          lblSomethingElse.setText(&quot;Something else&quot;);
          lblSomethingElse.setBounds(10, 116, 70, 20);
  
          Label label_4 = new Label(grpMisc, SWT.NONE);
          label_4.setText(&quot;New Label&quot;);
          label_4.setBounds(109, 64, 70, 20);
  
          Label label_5 = new Label(grpMisc, SWT.NONE);
          label_5.setText(&quot;New Label&quot;);
          label_5.setBounds(109, 90, 70, 20);
  
          Group grpBattery = new Group(this, SWT.BORDER | SWT.SHADOW_ETCHED_IN);
          grpBattery.setText(&quot;Battery&quot;);
          grpBattery.setBounds(10, 506, 233, 143);
  
          Label label_1 = new Label(grpBattery, SWT.NONE);
          label_1.setText(&quot;New Label&quot;);
          label_1.setBounds(109, 116, 70, 20);
  
          Label lblRemaining = new Label(grpBattery, SWT.NONE);
          lblRemaining.setText(&quot;% remaining&quot;);
          lblRemaining.setBounds(10, 64, 93, 20);
  
          Label lblDischargeRate = new Label(grpBattery, SWT.NONE);
          lblDischargeRate.setText(&quot;Discharge&quot;);
          lblDischargeRate.setBounds(10, 90, 70, 20);
  
          Label lblTimeRemaining = new Label(grpBattery, SWT.NONE);
          lblTimeRemaining.setText(&quot;Time remaining&quot;);
          lblTimeRemaining.setBounds(10, 116, 70, 20);
  
          Label label_7 = new Label(grpBattery, SWT.NONE);
          label_7.setText(&quot;New Label&quot;);
          label_7.setBounds(109, 64, 70, 20);
  
          Label label_8 = new Label(grpBattery, SWT.NONE);
          label_8.setText(&quot;New Label&quot;);
          label_8.setBounds(109, 90, 70, 20);
  
          Image drone_file = new Image(getDisplay(), &quot;src/testGUI/images/drone.jpg&quot;);
  
          Label lblNewLabel_3 = new Label(this, SWT.NONE);
          lblNewLabel_3.setBounds(283, 91, 660, 266);
          formToolkit.adapt(lblNewLabel_3, true, true);
          lblNewLabel_3.setText(&quot;New Label&quot;);
          lblNewLabel_3.setImage(drone_file);
  
          Canvas canvasAltitude = new Canvas(this, SWT.NONE);
          canvasAltitude.setBounds(283, 395, 267, 183);
          formToolkit.adapt(canvasAltitude);
          formToolkit.paintBordersFor(canvasAltitude);
  
          CLabel labelBRTime = new CLabel(this, SWT.NONE);
          labelBRTime.setBounds(844, 664, 146, 26);
          formToolkit.adapt(labelBRTime);
          formToolkit.paintBordersFor(labelBRTime);
          labelBRTime.setText(&quot;No data&quot;);
      
      }
  
      @Override
      protected void checkSubclass() {
          // Disable the check that prevents subclassing of SWT components
      }
  }
  </code></pre>