我正在学习如何使用Eclipse IDE,并尝试运行在Eclipse中构建的组合。 但是,我无法运行GUI,有人可以帮忙吗? 我知道我需要public static void main(String[] args)但是我需要添加什么方法才能使其正常运行? 谁能帮帮我吗。

package gui;  import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Combo; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.plaf.metal.MetalIconFactory; import org.eclipse.swt.custom.CCombo; import org.eclipse.wb.swt.SWTResourceManager; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent;  public class GUI extends Composite {  // Strings to use as list items private static final String[] items = { "Item 1", "Item 2", "Item 3", "Item 4" };  public Framework(Composite parent, int style) {     super(parent, style);      Combo comboBox= new Combo(this, SWT.DROP_DOWN);     comboBox.setBounds(174, 36, 534, 20);     comboBox.setItems(Algorithms);      Label lblOut = new Label(this, SWT.NONE);     lblOut.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));     lblOut.setBounds(38, 145, 534, 327);      Button btnExit = new Button(this, SWT.NONE);     btnExit.setText("EXIT");     btnExit.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));     btnExit.setBounds(591, 421, 166, 51);     btnExit.addSelectionListener(new SelectionAdapter() {         @Override         public void widgetSelected(SelectionEvent e) {             System.exit(0);         }     }); }  @Override protected void checkSubclass() {     // Disable the check that prevents subclassing of SWT components }  public static void main(String[] args) {     Framework framework = new Framework();      Composite c = new Composite(framework, SWT.NONE);  } } 

我在Framework framework = new Framework();上遇到错误Framework framework = new Framework(); 因为我需要两个参数parent, font 请帮助并解释我只是Java的初学者。

===============>>#1 票数:0 已采纳

SWT程序的main必须始终创建SWT显示并运行SWT事件分发循环。

诸如Composite控件必须包含在Shell控件中。

因此您的main可能看起来像:

public static void main(final String [] args) {   // Create the display   Display display = new Display();   try    {      // Create main shell      Shell shell = new Shell(display, SWT.SHELL_TRIM);       shell.setText("Shell Title");       shell.setLayout(new FillLayout());       // Put framework in the shell      new Framework(shell, SWT.NONE);       // Open the shell      shell.open();       // Main event dispatch loop      while (!shell.isDisposed())       {         if (!display.readAndDispatch())           display.sleep();       }     }   finally    {      // Clean up      display.dispose();    } } 

  ask by Grace Devlin translate from so

本文未有回复,本站智能推荐: