欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SWT(JFace) 簡易瀏覽器 制作實現(xiàn)代碼

 更新時間:2009年06月25日 11:34:12   作者:  
SWT(JFace) 簡易瀏覽器 制作實現(xiàn)代碼

再看一個好一點的實現(xiàn):
SWTBrowser.java
復(fù)制代碼 代碼如下:

package swt_jface.demo8;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.CloseWindowListener;
import org.eclipse.swt.browser.LocationEvent;
import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.browser.OpenWindowListener;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.browser.StatusTextEvent;
import org.eclipse.swt.browser.StatusTextListener;
import org.eclipse.swt.browser.TitleEvent;
import org.eclipse.swt.browser.TitleListener;
import org.eclipse.swt.browser.VisibilityWindowListener;
import org.eclipse.swt.browser.WindowEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
public class SWTBrowser {

Display display = new Display();
Shell shell = new Shell(display);
Text textLocation;
Browser browser;
Label labelStatus;
public SWTBrowser() {

shell.setLayout(new GridLayout());
ToolBar toolBar = new ToolBar(shell, SWT.FLAT | SWT.RIGHT);
final ToolBarManager manager = new ToolBarManager(toolBar);
Composite compositeLocation = new Composite(shell, SWT.NULL);
compositeLocation.setLayout(new GridLayout(3, false));
compositeLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label labelAddress = new Label(compositeLocation, SWT.NULL);
labelAddress.setText("Address");
textLocation = new Text(compositeLocation, SWT.SINGLE | SWT.BORDER);
textLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Button buttonGo = new Button(compositeLocation, SWT.NULL);
buttonGo.setImage(new Image(shell.getDisplay(), "C:/icons/web/go.gif"));
browser = new Browser(shell, SWT.BORDER);
browser.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite compositeStatus = new Composite(shell, SWT.NULL);
compositeStatus.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
compositeStatus.setLayout(new GridLayout(2, false));
labelStatus = new Label(compositeStatus, SWT.NULL);
labelStatus.setText("Ready");
labelStatus.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
final ProgressBar progressBar = new ProgressBar(compositeStatus, SWT.SMOOTH);
Listener openURLListener = new Listener() {
public void handleEvent(Event event) {
browser.setUrl(textLocation.getText());
}
};
buttonGo.addListener(SWT.Selection, openURLListener);
textLocation.addListener(SWT.DefaultSelection, openURLListener);
final Action actionBackward =
new Action(
"&Backword",
ImageDescriptor.createFromFile(
null,
"C:/icons/web/backward.gif")) {
public void run() {
browser.back();
}
};
actionBackward.setEnabled(false);
final Action actionForward =
new Action(
"&Forward",
ImageDescriptor.createFromFile(
null,
"C:/icons/web/forward.gif")) {
public void run() {
browser.forward();
}
};
actionForward.setEnabled(false);
Action actionStop =
new Action(
"&Stop",
ImageDescriptor.createFromFile(null, "C:/icons/web/stop.gif")) {
public void run() {
browser.stop();
}
};
Action actionRefresh =
new Action(
"&Refresh",
ImageDescriptor.createFromFile(
null,
"C:/icons/web/refresh.gif")) {
public void run() {
browser.refresh();
}
};
Action actionHome =
new Action(
"&Home",
ImageDescriptor.createFromFile(null, "C:/icons/web/home.gif")) {
public void run() {
browser.setUrl("http://www.eclipse.org");
}
};
manager.add(actionBackward);
manager.add(actionForward);
manager.add(actionStop);
manager.add(actionRefresh);
manager.add(actionHome);
manager.update(true);
toolBar.pack();
browser.addLocationListener(new LocationListener() {
public void changing(LocationEvent event) {
textLocation.setText(event.location);
}
public void changed(LocationEvent event) {
actionBackward.setEnabled(browser.isBackEnabled());
actionForward.setEnabled(browser.isForwardEnabled());
manager.update(false);
}
});
browser.addProgressListener(new ProgressListener() {
public void changed(ProgressEvent event) {
progressBar.setMaximum(event.total);
progressBar.setSelection(event.current);
}
public void completed(ProgressEvent event) {
progressBar.setSelection(0);
}
});
browser.addStatusTextListener(new StatusTextListener() {
public void changed(StatusTextEvent event) {
labelStatus.setText(event.text);
}
});
browser.addTitleListener(new TitleListener() {
public void changed(TitleEvent event) {
shell.setText(event.title + " - powered by SWT");
}
});
initialize(display, browser);
shell.setSize(500, 400);
shell.open();
browser.setText("<html><body>" + "<h1>SWT & JFace </h1>" + "</body/html>");
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
static void initialize(final Display display, Browser browser) {
browser.addOpenWindowListener(new OpenWindowListener() {
public void open(WindowEvent event) {
Shell shell = new Shell(display);
shell.setText("New Window");
shell.setLayout(new FillLayout());
Browser browser = new Browser(shell, SWT.NONE);
initialize(display, browser);
event.browser = browser;
}
});
browser.addVisibilityWindowListener(new VisibilityWindowListener() {
public void hide(WindowEvent event) {
Browser browser = (Browser) event.widget;
Shell shell = browser.getShell();
shell.setVisible(false);
}
public void show(WindowEvent event) {
Browser browser = (Browser) event.widget;
Shell shell = browser.getShell();
if (event.location != null)
shell.setLocation(event.location);
if (event.size != null) {
Point size = event.size;
shell.setSize(shell.computeSize(size.x, size.y));
}
shell.open();
}
});
browser.addCloseWindowListener(new CloseWindowListener() {
public void close(WindowEvent event) {
Browser browser = (Browser) event.widget;
Shell shell = browser.getShell();
shell.close();
}
});
}
public static void main(String[] args) {
new SWTBrowser();
}
}

相關(guān)文章

  • Java測試題 實現(xiàn)一個注冊功能過程解析

    Java測試題 實現(xiàn)一個注冊功能過程解析

    這篇文章主要介紹了Java測試題 實現(xiàn)一個注冊功能過程解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-10-10
  • RocketMQ特性Broker存儲事務(wù)消息實現(xiàn)

    RocketMQ特性Broker存儲事務(wù)消息實現(xiàn)

    這篇文章主要為大家介紹了RocketMQ特性Broker存儲事務(wù)消息實現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-08-08
  • SpringBoot自定義轉(zhuǎn)換器應(yīng)用實例講解

    SpringBoot自定義轉(zhuǎn)換器應(yīng)用實例講解

    SpringBoot在響應(yīng)客戶端請求時,將提交的數(shù)據(jù)封裝成對象時,使用了內(nèi)置的轉(zhuǎn)換器,SpringBoot 也支持自定義轉(zhuǎn)換器,這個內(nèi)置轉(zhuǎn)換器在 debug的時候,可以看到,提供了124個內(nèi)置轉(zhuǎn)換器
    2022-08-08
  • Java+Swing實現(xiàn)中國象棋游戲

    Java+Swing實現(xiàn)中國象棋游戲

    這篇文章將通過Java+Swing實現(xiàn)經(jīng)典的中國象棋游戲。文中可以實現(xiàn)開始游戲,悔棋,退出等功能。感興趣的小伙伴可以跟隨小編一起動手試一試
    2022-02-02
  • Java通過接口實現(xiàn)匿名類的實例代碼

    Java通過接口實現(xiàn)匿名類的實例代碼

    這篇文章介紹了Java通過接口實現(xiàn)匿名類的實例代碼,有需要的朋友可以參考一下
    2013-10-10
  • java serialVersionUID解決序列化類版本不一致問題面試精講

    java serialVersionUID解決序列化類版本不一致問題面試精講

    這篇文章主要為大家介紹了serialVersionUID解決序列化類版本不一致問題的面試精講,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-10-10
  • 用SpringMVC編寫一個HelloWorld的詳細過程

    用SpringMVC編寫一個HelloWorld的詳細過程

    SpringMVC是Spring的一個后續(xù)產(chǎn)品,是Spring的一個子項目<BR>SpringMVC?是?Spring?為表述層開發(fā)提供的一整套完備的解決方案,本文我們將用SpringMVC編寫一個HelloWorld,文中有詳細的編寫過程,需要的朋友可以參考下
    2023-08-08
  • 關(guān)于Hadoop的HDFS集群

    關(guān)于Hadoop的HDFS集群

    這篇文章主要介紹了關(guān)于Hadoop的HDFS集群,Hadoop 如何配置集群、不同的計算機里又應(yīng)該有怎樣的配置,這些問題是在學(xué)習(xí)中產(chǎn)生的。本章的配置中將會提供一個典型的示例,需要的朋友可以參考下
    2023-05-05
  • Java?8中?Stream小知識小技巧方法梳理

    Java?8中?Stream小知識小技巧方法梳理

    這篇文章主要介紹了Java8中Stream小知識小技巧方法梳理,Stream流和迭代器一樣,它只能夠迭代一次。當它遍歷完的時候,我們就稱它已經(jīng)消費完了。如果還想重新執(zhí)行操作,那么就只能從原來的地方再獲取一個流
    2022-09-09
  • Spring需要三個級別緩存解決循環(huán)依賴原理解析

    Spring需要三個級別緩存解決循環(huán)依賴原理解析

    這篇文章主要為大家介紹了Spring需要三個級別緩存解決循環(huán)依賴原理解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-02-02

最新評論