SWT中Button的用法

package  netchat;

import  org.eclipse.swt. * ;
import  org.eclipse.swt.widgets. * ;
import  org.eclipse.swt.events. * ;
import  org.eclipse.swt.graphics.Color;

public   class  ButtonDemo  {
    
private Display display;
    
private Shell shell;
    
private Composite composite;
    
private Button noneButton;
    
private Button flatButton;
    
private Button borderButton;
    
private Button toggleButton;
    
private Button radioButton;
    
private Button checkButton;
    
private Button arrowButton;
    
private Button arrow2Button;
    
private Color backgroundColor;
    
private Text myText;

    
public ButtonDemo() {
        display 
= Display.getDefault(); // 创建没有显示
        
// display=Display.getCurrent(); //获取当前显示
        shell = new Shell(display, SWT.MAX | SWT.MIN | SWT.RESIZE | SWT.CLOSE);
        shell.setBackground(
new Color(display, 6561250));
        
// shell=new Shell(display,SWT.SHELL_TRIM); //与上面的功能一样
        composite = new Composite(shell, SWT.NONE);
        composite.setBounds(
55475315);
        backgroundColor 
= new Color(display, 105118209);
        composite.setBackground(backgroundColor);
        noneButton 
= new Button(composite, SWT.NONE);
        noneButton.setBounds(
10108040);
        noneButton.setText(
"NONE");
        noneButton.addSelectionListener(
new SelectionAdapter() {
            
public void widgetSelected(SelectionEvent e) {
                myText.append(
"You have selected None Button:"
                        
+ noneButton.getText() + ' ');
                myText.setBackground(
new Color(display, 10022111));
            }

        }
);
        flatButton 
= new Button(composite, SWT.FLAT);
        flatButton.setBounds(
110108040);
        flatButton.setText(
"FLAT");
        flatButton.addSelectionListener(
new SelectionAdapter() {
            
public void widgetSelected(SelectionEvent e) {
                myText.append(
"You have selected Flat Button:"
                        
+ flatButton.getText() + ' ');
                myText.setBackground(
new Color(display, 2169116));
            }

        }
);
        borderButton 
= new Button(composite, SWT.BORDER);
        borderButton.setBounds(
10708040);
        borderButton.setText(
"BORDER");
        borderButton.addSelectionListener(
new SelectionAdapter() {
            
public void widgetSelected(SelectionEvent e) {
                myText.append(
"You have selected Border Button:"
                        
+ borderButton.getText() + ' ');
                myText.setBackground(
new Color(display, 23570253));
            }

        }
);
        toggleButton 
= new Button(composite, SWT.TOGGLE);
        toggleButton.setBounds(
110708040);
        toggleButton.setText(
"TOGGLE");
        toggleButton.addSelectionListener(
new SelectionAdapter() {
            
public void widgetSelected(SelectionEvent e) {
                myText.append(
"You have selected Toggle Button:"
                        
+ toggleButton.getText() + ' ');
                myText.setBackground(
new Color(display, 92183231));
            }

        }
);
        radioButton 
= new Button(composite, SWT.RADIO);
        radioButton.setBounds(
101208040);
        radioButton.setText(
"RADIO");

        radioButton.addSelectionListener(
new SelectionAdapter() {
            
public void widgetSelected(SelectionEvent e) {
                myText.append(
"You have selected Radio Button:"
                        
+ radioButton.getText() + ' ');
                myText.setBackground(
new Color(display, 2146367));
            }

        }
);
        checkButton 
= new Button(composite, SWT.CHECK);
        checkButton.setBounds(
1101208040);
        checkButton.setText(
"CHECK");
        checkButton.addSelectionListener(
new SelectionAdapter() {
            
public void widgetSelected(SelectionEvent e) {
                myText.append(
"You have selected Check Button:"
                        
+ checkButton.getText() + ' ');
                myText.setBackground(
new Color(display, 16616674));
            }

        }
);
        arrowButton 
= new Button(composite, SWT.ARROW | SWT.LEFT);
        arrowButton.setBounds(
101808040);
        arrowButton.addSelectionListener(
new SelectionAdapter() {
            
public void widgetSelected(SelectionEvent e) {
                myText.append(
"You have selected Left Arrow Button:"
                        
+ arrowButton.getText() + ' ');
                myText.setBackground(
new Color(display, 20373102));
            }

        }
);
        arrow2Button 
= new Button(composite, SWT.ARROW | SWT.RIGHT);
        arrow2Button.setBounds(
1101808040);
        arrow2Button.addSelectionListener(
new SelectionAdapter() {
            
public void widgetSelected(SelectionEvent e) {
                myText.append(
"You have selected Right Arrow Button:"
                        
+ arrow2Button.getText() + ' ');
                myText.setBackground(
new Color(display, 116121160));
            }

        }
);
        myText 
= new Text(composite, SWT.WRAP);
        myText.setBackground(
new Color(display, 23519612));
        myText.setBounds(
21010220210);

        shell.setText(
"按钮实例");
        shell.setSize(
480320);
        shell.layout(
true);
        shell.open();
        
while (!shell.isDisposed()) {
            
if (!display.readAndDispatch())
                display.sleep();
        }


    }


    
public static void main(String[] args) {
        
new ButtonDemo();
    }


}

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值