close
BasicFramework code : (來源 SWT)
package org.eclipseguide.swt;
 
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.*;
 
public abstract class BasicFramework
{
 
   protected Display display;
   protected Shell shell;
   protected Menu menuBar, fileSubMenu, helpSubMenu;
   protected MenuItem fileSubMenuHeader;
   protected MenuItem fileExit, helpSubMenuHeader;
   protected MenuItem helpAbout;
 
   public abstract void dispose();
   public abstract void displayHelpAboutDialog();
 
   class FileExitListener implements SelectionListener
   {
      public void widgetSelected(SelectionEvent event)
      {
         shell.close();
         dispose();
      }
 
      public void widgetDefaultSelected(SelectionEvent event)
      {
         shell.close();
         dispose();
      }
   }
 
   class HelpAboutListener implements SelectionListener
   {
      public void widgetSelected(SelectionEvent event)
      {
         displayHelpAboutDialog();
      }
 
      public void widgetDefaultSelected(SelectionEvent event)
      {
         displayHelpAboutDialog();
      }
   }
 
   public BasicFramework(String windowTitle)
   {
      display = new Display();
      shell = new Shell(display);
      shell.setText(windowTitle);
 
      menuBar = new Menu(shell, SWT.BAR);
      fileSubMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
      fileSubMenuHeader.setText("&File");
 
      fileSubMenu = new Menu(shell, SWT.DROP_DOWN);
      fileSubMenuHeader.setMenu(fileSubMenu);
 
      fileExit = new MenuItem(fileSubMenu, SWT.PUSH);
      fileExit.setText("E&xit");
 
      helpSubMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
      helpSubMenuHeader.setText("&Help");
 
      helpSubMenu = new Menu(shell, SWT.DROP_DOWN);
      helpSubMenuHeader.setMenu(helpSubMenu);
 
      helpAbout = new MenuItem(helpSubMenu, SWT.PUSH);
      helpAbout.setText("&About");
 
      fileExit.addSelectionListener(new FileExitListener());
      helpAbout.addSelectionListener(new HelpAboutListener());
 
      shell.setMenuBar(menuBar);
   }
 
   public void mainLoop(int hSize, int vSize)
   {
      shell.setSize(hSize, vSize);
      shell.setVisible(true);
      shell.open();
 
      while (!shell.isDisposed())
      {
         if (!display.readAndDispatch())
            display.sleep();
      }
   }
}
arrow
arrow
    全站熱搜

    identical 發表在 痞客邦 留言(0) 人氣()