package com.wl.ui; import java.util.function.Consumer; import com.wl.util.DisItemUtil; import com.wl.util.DisKeyboard; import com.wl.util.PropertiesUtil; import com.wl.util.ResumeDisItemUtil; import com.wl.util.ShutDownUtil; import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.ObservableList; import javafx.concurrent.Worker; import javafx.concurrent.Worker.State; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.geometry.Rectangle2D; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ButtonType; import javafx.scene.control.Dialog; import javafx.scene.control.DialogEvent; import javafx.scene.control.Label; import javafx.scene.control.PasswordField; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.scene.control.TextField; import javafx.scene.image.Image; import javafx.scene.input.KeyCombination; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.paint.Color; import javafx.scene.text.Font; import javafx.scene.web.WebEngine; import javafx.scene.web.WebHistory; import javafx.scene.web.WebHistory.Entry; import javafx.scene.web.WebView; import javafx.stage.Modality; import javafx.stage.Screen; import javafx.stage.Stage; public class MainBrowser extends Application{ static ResumeDisItemUtil resumeDisItemUtil=new ResumeDisItemUtil(); static DisItemUtil disItemUtil=new DisItemUtil(); @Override public void start(Stage primaryStage) throws Exception { // TODO Auto-generated method stub WebView web=new WebView(); WebEngine engine=web.getEngine(); engine.load(PropertiesUtil.getValue("url")); WebHistory history=engine.getHistory(); ObservableList<WebHistory.Entry> obslist=history.getEntries(); //以tab显示engine的内容 TabPane tp=new TabPane(); Tab tab = new Tab(); tab.textProperty().bind(engine.titleProperty()); tab.setClosable(false); tab.setContent(web); tp.getTabs().add(tab); Rectangle2D screenRectangle = Screen.getPrimary().getBounds(); double width = screenRectangle.getWidth(); //double height = screenRectangle.getHeight(); HBox hbox=new HBox(40); Label lb1=new Label(PropertiesUtil.getValue("name")); lb1.setStyle("-fx-font-family: 'KaiTi';-fx-font-size: 16;"); lb1.setTextFill(Color.GREEN); lb1.setTranslateX(2); lb1.setTranslateY(3); Button b0=new Button("主页"); Button b1=new Button("后退"); Button b2=new Button("前进"); TextField tf =new TextField();// 创建一个单行输入框 tf.setEditable(false); double w=width-370; tf.setPrefSize(w, 20);// 设置单行输入框的推荐宽高 Button b4=new Button("退出"); b4.setTranslateX(width-w-370); hbox.setPadding(new Insets(9, 9, 9, 9)); hbox.setSpacing(10); //hbox.setStyle("-fx-background-color:red"); hbox.getChildren().addAll(lb1,b0,b1,b2,tf,b4); AnchorPane root=new AnchorPane(); //设置tab最大化显示 tp.prefHeightProperty().bind(primaryStage.heightProperty()); tp.prefWidthProperty().bind(primaryStage.widthProperty()); //将tab和hbox组件添加到AnchorPane面板容器上 root.getChildren().addAll(hbox,tp); AnchorPane.setTopAnchor(tp, 40.0); Scene scene=new Scene(root); primaryStage.setScene(scene); primaryStage.setAlwaysOnTop(true); primaryStage.setFullScreen(true); primaryStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH); primaryStage.show(); //web.prefWidthProperty().bind(root.widthProperty()); //web.prefHeightProperty().bind(root.heightProperty().subtract(30)); //主页功能监听 b0.setOnAction(new EventHandler< ActionEvent>() { @Override public void handle(ActionEvent arg0) { // TODO Auto-generated method stub engine.load(PropertiesUtil.getValue("url")); obslist.forEach(new Consumer<WebHistory.Entry>() { @Override public void accept(Entry t) { // TODO Auto-generated method stub System.out.println(t.getTitle()+":"+t.getUrl()); } }); } }); //后退按钮监听事件 b1.setOnAction(new EventHandler< ActionEvent>() { @Override public void handle(ActionEvent arg0) { // TODO Auto-generated method stub try { history.go(-1); }catch(Exception e) { return; } } }); //前进按钮监听事件 b2.setOnAction(new EventHandler< ActionEvent>() { @Override public void handle(ActionEvent arg0) { // TODO Auto-generated method stub try { history.go(1); }catch(Exception e) { return; } } }); //文本框动态显示网址 engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() { @SuppressWarnings("rawtypes") @Override public void changed(ObservableValue ov, State oldState, State newState) { if (newState == Worker.State.SUCCEEDED) { tf.setText(engine.getLocation()); } } }); web.getEngine().documentProperty().addListener((Observable,ov,document)->{ System.out.println(engine.getLocation()); }); b4.setOnAction(new EventHandler< ActionEvent>(){ @Override public void handle(ActionEvent event){ final Stage dialog = new Stage() ; dialog.initModality(Modality.APPLICATION_MODAL); dialog.initOwner(primaryStage); dialog.getIcons().add(new Image("/ico/exit.png")); //定义面板容器,用于放置所有组件 GridPane gp=new GridPane(); //密码框组件 Label l_password=new Label("密 码:"); l_password.setFont(Font.font(12)); PasswordField p_password=new PasswordField(); //退出按钮组件 Button logout=new Button("确认退出"); //组件添加到gp容器面板 gp.add(l_password,0,1); gp.add(p_password,1,1); gp.add(logout,1,2); //组件水平显示位置 gp.setHgap(5); //组件垂直显示位置 gp.setVgap(17); //容器组件居中 gp.setAlignment(Pos.CENTER); //VBox dialogVbox = new VBox(20); //dialogVbox.getChildren().add(new Text("This is a Dialog")); Scene dialogScene = new Scene(gp,260,130); dialog.setTitle("退出浏览器"); dialog.setResizable(false); //dialog.setAlwaysOnTop(true); dialog.setScene(dialogScene); dialog.show(); //确认退出按钮监听事件 logout.setOnAction(new EventHandler< ActionEvent>() { @Override public void handle(ActionEvent arg0) { // TODO Auto-generated method stub if(p_password.getText().trim().equals("")) { System.out.println("密码为空!"); Dialog<ButtonType> configdialog=new Dialog<ButtonType>(); configdialog.getDialogPane().setPrefSize(180, 80); configdialog.setTitle("警告"); configdialog.setContentText("密码不能为空,请输入!"); configdialog.getDialogPane().getButtonTypes().add(ButtonType.OK); Button ok=(Button)configdialog.getDialogPane().lookupButton(ButtonType.OK); configdialog.show(); dialog.hide(); ok.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { // TODO Auto-generated method stub dialog.show(); } }); configdialog.setOnCloseRequest(new EventHandler<DialogEvent>() { @Override public void handle(DialogEvent event) { // TODO Auto-generated method stub dialog.show(); } }); return; } if(!p_password.getText().trim().equals(PropertiesUtil.getValue("exitpassword"))) { Dialog<ButtonType> configdialog=new Dialog<ButtonType>(); configdialog.getDialogPane().setPrefSize(180, 80); configdialog.setTitle("OPAC警告"); configdialog.setContentText("密码错误,请输入正确密码!"); configdialog.getDialogPane().getButtonTypes().add(ButtonType.OK); Button ok=(Button)configdialog.getDialogPane().lookupButton(ButtonType.OK); configdialog.show(); dialog.hide(); ok.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { // TODO Auto-generated method stub dialog.show(); } }); configdialog.setOnCloseRequest(new EventHandler<DialogEvent>() { @Override public void handle(DialogEvent event) { // TODO Auto-generated method stub dialog.show(); } }); return; }else if(p_password.getText().trim().equals(PropertiesUtil.getValue("exitpassword"))){ System.out.println("退出浏览器"); System.out.println("禁用热键已还原!"); ResumeDisItemUtil.relockWorkstation(); ResumeDisItemUtil.reswitchUser(); ResumeDisItemUtil.recloseLogout(); ResumeDisItemUtil.rechangeUser(); ResumeDisItemUtil.redisabledTaskManager(); System.exit(0); } } }); } }); } public static void main(String[] args) throws Exception{ //屏蔽锁定计算机功能 DisItemUtil.lockWorkstation(); //屏蔽切换用户功能 DisItemUtil.switchUser(); //屏蔽注销功能 DisItemUtil.closeLogout(); //屏蔽修改密码功能 DisItemUtil.changeUser(); //禁用任务管理器 DisItemUtil.disabledTaskManager(); //禁用热键 DisKeyboard kbhook = new DisKeyboard(); new Thread(kbhook).start(); //定时关机 ShutDownUtil.showTimer(); try { launch(args); System.out.println("登录成功"); }catch(Exception e) { e.printStackTrace(); System.out.println("登录失败"); } } }
最近下载更多
rongsoft LV8
2022年8月29日
1690356080 LV37
2022年2月28日
dongzhan LV12
2021年11月27日
最代码官方 LV168
2021年10月31日