⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maingui.java

📁 SWT中采用继承SHELL的方法来实现主窗口调用子窗口的应用
💻 JAVA
字号:
package testshell;
 

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

/**
 * @author lvpin
 * 2007-2-6 10:43:24
 */

public class MainGUI extends Shell {

       /**
        * Launch the application
        * @param args
        */
       private static MainGUI mainGUI;
       private static Display display;
       static AssistantGUI assistantGUI;
       
       /**
        * Create the shell
        * @param display
        * @param style
        */
       public MainGUI(Display display, int style) {
    	   super(display, style);
           createContents();
       }

       /**
        * Create contents of the window
        */
       protected void createContents() {
    	   setText("MainGUI");
           final Button button = new Button(this, SWT.NONE);
           button.addSelectionListener(new SelectionAdapter() {
	           public void widgetSelected(final SelectionEvent e) {
	        	   ininitAssistantGUI();                 
	           }
           });

           button.setText("assistant");
           button.setBounds(120, 220, 120, 30);
       }

       public static void ininitAssistantGUI(){
    	   if(assistantGUI==null||assistantGUI.isDisposed())
    		   assistantGUI=new AssistantGUI(display,SWT.SHELL_TRIM);
    	   assistantGUI.setBounds(mainGUI.getBounds().x+mainGUI.getBounds().width,
    			   mainGUI.getBounds().y,200,200);
    	   assistantGUI.addMouseListener(new MouseAdapter(){
    		   public void mouseDown(MouseEvent e){
    			   assistantGUI.stop();
    		   }
    	   });
    	   assistantGUI.open();
    	   assistantGUI.layout();
       }

       protected void checkSubclass() {
              // Disable the check that prevents subclassing of SWT components

       }

       public static void main(String args[]) {
    	   System.out.println("hello world");
    	   try {
    		   display = Display.getDefault();
               mainGUI = new MainGUI(display, SWT.SHELL_TRIM);
               mainGUI.setBounds(300,300,500,375);     
               mainGUI.addListener(SWT.Move,new Listener(){
            	   public void handleEvent(Event arg0) {
                       Rectangle r=mainGUI.getBounds();
                       if(assistantGUI!=null&&!assistantGUI.isDisposed()){
                    	   assistantGUI.setBounds(r.x+r.width,r.y,200,200);
                       }
            	   }      
               });

               mainGUI.open();
               mainGUI.layout();
               while (!mainGUI.isDisposed()) {
            	   if (!display.readAndDispatch())
            		   display.sleep();
               }

	        } catch (Exception e) {
	        	e.printStackTrace();
	        }
       }                     
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -