点击按钮,新打开一个窗口
用到了,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"); } } }