用到了,swt,在frame中有两个按钮,test1,test2。点test1时,会出现一个新的窗口里面显示baidu但这是,我点test2 没有反应,这是什么原因,应该怎么处理,谢了。
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JFrame;import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Shell;public class HelloFrame extends JFrame implements ActionListener{

private String name="";
private JButton btn;
private JButton btn2;
public HelloFrame(){
this.setLayout(new FlowLayout());
this.setSize(200,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Hello World!");
 btn =new JButton("test1");
btn.addActionListener(this);
this.add(btn);

 btn2 =new JButton("test2");
btn2.addActionListener(this);
this.add(btn2);
this.setVisible(true);
} public static void main(String[] args){
new HelloFrame();
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public void actionPerformed(ActionEvent e) {


if(e.getSource()==btn){
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("CNTalk-UC Manger");
shell.setLayout(new FillLayout());
shell.setBounds(100, 100, 810, 600);
shell.setMaximized(false); // 窗口最大化
final Browser browser = new Browser(shell, SWT.NONE);
browser.setBounds(0, 0, 800, 600);
browser.setUrl("http://www.baidu.com");
browser.setMenu(new Menu(browser)); shell.open(); while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}else if(e.getSource()==btn2){
System.out.println("test2");
}
}


}

解决方案 »

  1.   

    if(e.getSource()==btn){ //当e.getSource()==btn2时的处理没有,当然没反应了
      

  2.   

    点test2时只是在控制台输出数据 System.out.println("test2");
    如果你是控制台启动的,可以看到控制台打印出 test2
      

  3.   


    点test2 控制台没有反应。
      

  4.   

    只有关闭新打开的窗口时,test2才会在控制台输出内容。
      

  5.   


       不可能!肯定会打印的,你没有使用个Eclipse开发工具么?把你的console打开,肯定会看到的
      

  6.   

    你打开的Browser就相当于个模式窗口,不是你的test2不输出内容,是当你打开Browser的时候,test2不可点击,父窗口都不能获取焦点。
      

  7.   

    那我打开Browser后,,怎么使test2可以点击或父窗口获得焦点呢。
      

  8.   

    你把新窗口关了,点击btn2就会有输出的,是不能获取焦点的问题
      

  9.   

    你为btn2添加的监听器只是输出test2这个字符串,没有设置其它的处理功能,它当然不会显示新的窗体了!
      

  10.   

    不可能!肯定会打印的,你没有使用个Eclipse开发工具么?把你的console打开,肯定会看到的
      

  11.   


    当点击test1后,会出现一个新的窗口。此时如果点test2,控制台是没有输出的。。当关闭刚才打开的窗口后,控制台就显示输出了。。