展开全部
java浏览器开发,其实很简单, 使用JavaFX的WebView组件即62616964757a686964616fe58685e5aeb931333431356132可.(支持html5); 也可以在swing里使用JFXPanel然后添加WebView;
效果图如下
参考代码如下(java8+win10 x64 编写,测试)
import javafx.application.Application;
import javafx.concurrent.Worker.State;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.web.*;
import javafx.stage.Stage;
public class WebViewTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
//顶部
HBox hbox=new HBox(8);
Label labeAddr=new Label("地址");
TextField tfAddr = new TextField();
tfAddr.setMinWidth(500);
tfAddr.setText("http://www.baidu.com");
Button btnGo = new Button("Go转到");
Button btnGoBack=new Button("
Button btnH=new Button("->");
TextField tfSerch = new TextField();
Button btnSerch= new Button("捜");
hbox.getChildren().addAll(labeAddr,tfAddr,btnGoBack,btnH,btnGo,tfSerch,btnSerch);
hbox.setPadding(new Insets(5));
//中间
WebView wv = new WebView();
WebEngine we = wv.getEngine();
we.getLoadWorker().stateProperty().addListener((ob, ov, nv) -> {
if(nv==State.SCHEDULED) {
tfAddr.setText(we.getLocation());//
}
});
//底部
Label labelBottom = new Label();
labelBottom.textProperty().bind(we.getLoadWorker().messageProperty());//底下的信息显示
BorderPane root = new BorderPane();
root.setTop(hbox);
root.setCenter(wv);
root.setBottom(labelBottom);
Scene scene = new Scene(root, 900, 600);
primaryStage.setTitle("JavaFX 雪飞潇潇 web浏览器");
primaryStage.setScene(scene);
primaryStage.show();
btnGo.setOnAction(e -> {
we.load(tfAddr.getText().trim());
});
btnGoBack.setOnAction(e->{
we.executeScript("history.back()");//执行JavaScript,后退
});
btnH.setOnAction(e->{
we.executeScript("history.forward()");//执行JavaScript,前进
});
//搜索
btnSerch.setOnAction(e->{
we.load("https://www.baidu.com/s?wd="+tfSerch.getText());
});
}
}