SoFunction
Updated on 2025-04-06

SWT(JFace) Simple Browser Creation Implementation Code Page 2/2


package swt_jface.demo8;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
public class SWTBrowser {

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

(new GridLayout());
ToolBar toolBar = new ToolBar(shell, | );
final ToolBarManager manager = new ToolBarManager(toolBar);
Composite compositeLocation = new Composite(shell, );
(new GridLayout(3, false));
(new GridData(GridData.FILL_HORIZONTAL));
Label labelAddress = new Label(compositeLocation, );
("Address");
textLocation = new Text(compositeLocation, | );
(new GridData(GridData.FILL_HORIZONTAL));
Button buttonGo = new Button(compositeLocation, );
(new Image((), "C:/icons/web/"));
browser = new Browser(shell, );
(new GridData(GridData.FILL_BOTH));
Composite compositeStatus = new Composite(shell, );
(new GridData(GridData.FILL_HORIZONTAL));
(new GridLayout(2, false));
labelStatus = new Label(compositeStatus, );
("Ready");
(new GridData(GridData.FILL_HORIZONTAL));
final ProgressBar progressBar = new ProgressBar(compositeStatus, );
Listener openURLListener = new Listener() {
public void handleEvent(Event event) {
(());
}
};
(, openURLListener);
(, openURLListener);
final Action actionBackward =
new Action(
"&Backword",
(
null,
"C:/icons/web/")) {
public void run() {
();
}
};
(false);
final Action actionForward =
new Action(
"&Forward",
(
null,
"C:/icons/web/")) {
public void run() {
();
}
};
(false);
Action actionStop =
new Action(
"&Stop",
(null, "C:/icons/web/")) {
public void run() {
();
}
};
Action actionRefresh =
new Action(
"&Refresh",
(
null,
"C:/icons/web/")) {
public void run() {
();
}
};
Action actionHome =
new Action(
"&Home",
(null, "C:/icons/web/")) {
public void run() {
("");
}
};
(actionBackward);
(actionForward);
(actionStop);
(actionRefresh);
(actionHome);
(true);
();
(new LocationListener() {
public void changing(LocationEvent event) {
();
}
public void changed(LocationEvent event) {
(());
(());
(false);
}
});
(new ProgressListener() {
public void changed(ProgressEvent event) {
();
();
}
public void completed(ProgressEvent event) {
(0);
}
});
(new StatusTextListener() {
public void changed(StatusTextEvent event) {
();
}
});
(new TitleListener() {
public void changed(TitleEvent event) {
( + " - powered by SWT");
}
});
initialize(display, browser);
(500, 400);
();
("<html><body>" + "<h1>SWT & JFace </h1>" + "</body/html>");
while (!()) {
if (!()) {
();
}
}
();
}
static void initialize(final Display display, Browser browser) {
(new OpenWindowListener() {
public void open(WindowEvent event) {
Shell shell = new Shell(display);
("New Window");
(new FillLayout());
Browser browser = new Browser(shell, );
initialize(display, browser);
= browser;
}
});
(new VisibilityWindowListener() {
public void hide(WindowEvent event) {
Browser browser = (Browser) ;
Shell shell = ();
(false);
}
public void show(WindowEvent event) {
Browser browser = (Browser) ;
Shell shell = ();
if ( != null)
();
if ( != null) {
Point size = ;
((, ));
}
();
}
});
(new CloseWindowListener() {
public void close(WindowEvent event) {
Browser browser = (Browser) ;
Shell shell = ();
();
}
});
}
public static void main(String[] args) {
new SWTBrowser();
}
}