swt 简单DEMO

来源:互联网 发布:步步高v206软件下载 编辑:程序博客网 时间:2024/06/11 23:07

 

package com;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.*;

public class Demo000 {
 
public static void main(String[]args){
  Demo000 demo 
= new Demo000();
 }

 
private Shell _shell;
 
public Shell getShell() {
         
return _shell;
 }

    
public void setShell(Shell shell) {
      
this._shell = shell;
    }

 
public Demo000(){
  Display display 
= new Display();
  Shell shell 
= new Shell(display,SWT.SHELL_TRIM);
  shell.setText(
"Event demo");
  RowLayout layout
=new RowLayout(SWT.VERTICAL);
  shell.setLayout(layout);
  Menu menubar 
= new Menu(shell, SWT.BAR);
  MenuItem fileitem01 
= new MenuItem(menubar, SWT.CASCADE);
  fileitem01.setText(
"&File");
  Menu filemenu 
= new Menu(shell, SWT.DROP_DOWN);
  fileitem01.setMenu(filemenu);
  MenuItem exititem 
= new MenuItem(filemenu, SWT.PUSH);
   exititem.setText(
"&Exit");
   exititem.addSelectionListener(
new SelectionAdapter() {
    
public void widgetSelected(SelectionEvent arg0) {
      MessageBox messagebox 
= new MessageBox(getShell(), SWT.YES | SWT.NO);
      messagebox.setText(
"Exit");
       messagebox.setMessage(
"Exit the program?");
       
int val=messagebox.open();
                      
if(val == SWT.YES)y
                      
{
                             getShell().close();
                               }

    }

             }
);
  TabFolder tf 
= new TabFolder(shell,SWT.NONE);
  tf.setLayout(
new FillLayout());
  tf.setBounds(
2020300200);
  TabItem ti 
= new TabItem(tf, SWT.NONE);
     ti.setText(
"A Simple TalItem");
     Composite composite 
= new Composite(tf, SWT.NONE);
     composite.setLayout(
new GridLayout(2true));
     
for (int i = 0; i < 3; i++{
        Label label 
= new Label(composite, SWT.RIGHT);
        Text text 
= new Text(composite, SWT.NONE);
        label.setText(
"Text" + i + ":");
        text.setText(
"Text" + i );
            }

     ti.setControl(composite);
  Button button 
= new Button(shell,SWT.PUSH|SWT.CENTER);
  button.setBounds(
20010010028);
  button.setText(
"This is a button!");
     button.pack();
     shell.pack();
        shell.setMenuBar(menubar);
        shell.open();
  
while(!shell.isDisposed()){
   
if(!display.readAndDispatch()){
    display.sleep();
   }

  }

  display.dispose();
  }


}

 

 

原创粉丝点击