日期:2014-05-20 浏览次数:20850 次
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");
}
}
}