swt单选按钮。每个按钮显示不同的图像

时间:2011-07-26 20:15:35

标签: button swt radio

我遇到了问题!我想有两个显示不同图片的按钮。当我选择第一个单选按钮时,我的图片会出现,但是当我选择第二个单选按钮后,我的第二张图片将不会出现?

这是我的代码:

final Button buttondog= new Button(c1, SWT.RADIO);
buttondog.setText("dog");
buttondog.setBounds(10, 20, 169, 21);

final Button buttoncat= new Button(c1, SWT.RADIO);
buttoncat.setText("cat");
buttoncat.setBounds(10, 50, 169, 21);

buttonradio.addListener (SWT.Selection, new Listener () {
    public void handleEvent (Event event) {
        buttoncat.setSelection(false);
        buttondog.getSelection == true; 
        img = new Label(page1, SWT.TOP);
        img.setBounds(300, 100, 992, 568);
        img.setImage(SWTResourceManager.getImage("dog.jpg"));
        img.setVisible(true);
    }
});

buttoncat.addListener (SWT.Selection, new Listener () {
    public void handleEvent (Event event2) {
        buttondog.setSelection(false);
        buttoncat.setSelection(true); 
        img2 = new Label(page1, SWT.TOP);
        img2.setBounds(300, 100, 992, 568);
        img2.setImage(SWTResourceManager.getImage("cat.jpg"));
        img2.setVisible(true);
    }
});

0 个答案:

没有答案