-
Notifications
You must be signed in to change notification settings - Fork 0
/
web
150 lines (111 loc) · 4.23 KB
/
web
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebHistory;
import javafx.scene.web.WebView;
public class Controller implements Initializable{
@FXML
private WebView webView;
@FXML
private TextField textField;
private WebEngine engine;
private WebHistory history;
private String homePage;
private double webZoom;
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
engine = webView.getEngine();
homePage = "www.google.com";
textField.setText(homePage);
webZoom = 1;
loadPage();
}
public void loadPage() {
//engine.load("http://www.google.com");
engine.load("http://"+textField.getText());
}
public void refreshPage() {
engine.reload();
}
public void zoomIn() {
webZoom+=0.25;
webView.setZoom(webZoom);
}
public void zoomOut() {
webZoom-=0.25;
webView.setZoom(webZoom);
}
public void displayHistory() {
history = engine.getHistory();
ObservableList<WebHistory.Entry> entries = history.getEntries();
for(WebHistory.Entry entry : entries) {
//System.out.println(entry);
System.out.println(entry.getUrl()+" "+entry.getLastVisitedDate());
}
}
public void back() {
history = engine.getHistory();
ObservableList<WebHistory.Entry> entries = history.getEntries();
history.go(-1);
textField.setText(entries.get(history.getCurrentIndex()).getUrl());
}
public void forward() {
history = engine.getHistory();
ObservableList<WebHistory.Entry> entries = history.getEntries();
history.go(1);
textField.setText(entries.get(history.getCurrentIndex()).getUrl());
}
public void executeJS() {
engine.executeScript("window.location = \"https://www.youtube.com\";");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.web.WebView?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="576.0" prefWidth="757.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
<children>
<WebView fx:id="webView" layoutX="7.0" layoutY="71.0" prefHeight="505.0" prefWidth="749.0" />
<Button layoutY="46.0" mnemonicParsing="false" onAction="#loadPage" text="load" />
<TextField fx:id="textField" layoutY="21.0" onAction="#loadPage" prefHeight="25.0" prefWidth="757.0" />
<Button layoutX="40.0" layoutY="46.0" mnemonicParsing="false" onAction="#refreshPage" text="refresh" />
<Button layoutX="93.0" layoutY="46.0" mnemonicParsing="false" onAction="#zoomIn" text="+" />
<Button layoutX="118.0" layoutY="46.0" mnemonicParsing="false" onAction="#zoomOut" prefHeight="25.0" prefWidth="25.0" text="-" />
<Button layoutX="143.0" layoutY="46.0" mnemonicParsing="false" onAction="#displayHistory" text="history" />
<Button layoutX="195.0" layoutY="46.0" mnemonicParsing="false" onAction="#back" text="back" />
<Button layoutX="236.0" layoutY="46.0" mnemonicParsing="false" onAction="#forward" text="forward" />
<Button layoutX="293.0" layoutY="46.0" mnemonicParsing="false" onAction="#executeJS" text="execute JS" />
</children>
</AnchorPane>
package application;
import java.io.IOException;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.input.KeyEvent;
public class Main extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("Scene.fxml"));
Parent root = loader.load();
Controller controller = loader.getController();
Scene scene = new Scene(root);
//stage.getIcons().add(new Image("icon.png"));
//stage.setTitle("Bro web browser");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}