JavaFX webbrowser :: WBstart.java + WBController.java + WBLayout.fxml |
Gebruikte gratis Programmas: Eclipse-standard-kepler-SR1-win32 C:Program Files/Java/jre8
Hulpprogramma: JavaFX Scene Builder" Dit is een GUI javaFX programma dat tevens ook een voorstel geeft voor de opbouw van je java controller bestand.
Indien je een lagere jre versie wil gebruiken kijk dan na of deze de jfxrt.jar bevat voeg deze anders toe via: Eclipse >> Build pad / add external jars.
Waar vind je de jfxrt.jar na het installeren van java op je PC? C:/program files/java/jdk1.7.0_45/jre/lib/jfxrt.jar C:/program files/java/jre7/lib/jfxrt.jar |
Used Free Programs: Eclipse-standard-kepler-SR1-win32 C:Program Files/Java/jre8
Helpprogram: JavaFX Scene Builder" A gui javaFX FXML-file buider that even generates a java controller file you can copy.
If you are using an older jre version,than check if it contains the jfxrt.jar, else you will have to add it to you build path: Eclipse project >> Build pad / add external jars.
Where can you find the jfxrt.jar after installing java on your PC? C:/program files/java/jdk1.7.0_45/jre/lib/jfxrt.jar C:/program files/java/jre7/lib/jfxrt.jar |
Programmas libres usados: Eclipse-standard-kepler-SR1-win32 C:Program Files/Java/jre8
Programma de ayuda: JavaFX Scene Builder" A JavaFX FXML-file constructor GUI que incluso genera un archivo de controlador de java (controller.java) que se puede copiar.
Si está utilizando una versión anterior de JRE, el mejor es de comprobar si contiene la versión jfxrt.jar, si no, añadirla a su proyecto Eclipse: Eclipse project >> Build pad / add external jars.
¿Dónde está el archivo "jfxrt.jar" en su PC después de instalar java? C:/program files/java/jdk1.7.0_45/jre/lib/jfxrt.jar C:/program files/java/jre7/lib/jfxrt.jar |
|
|
|
Project files |
1. Start.java ---------- package fxml.brauwser;
import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage;
public class WBstart extends Application{ public static void main(String[] args) { Application.launch(args); } public void start(Stage stage) throws Exception { Parent root = (Parent) FXMLLoader.load(getClass().getResource("WBLayout.fxml")); stage.setTitle("FXML pwBrauwser"); stage.setScene(new Scene(root, 800, 600)); stage.show(); } }
2. WBController.java ----------------- package fxml.brauwser;
import javafx.concurrent.Worker.State;
import java.net.URL; import java.util.ResourceBundle;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.MenuButton; import javafx.scene.control.ProgressIndicator; import javafx.scene.control.TextField; import javafx.scene.input.InputMethodEvent; import javafx.scene.layout.HBox; import javafx.scene.web.WebEngine; import javafx.scene.web.WebView;
public class WBController { @FXML private WebEngine webEngine; @FXML private ResourceBundle resources;
@FXML private URL location; @FXML private HBox titelbalk; @FXML private HBox titelhouder; //bevat titellabel gekonfigureerd in het fxml bestand en statelabel @FXML Label statelabel; @FXML private HBox keuzeknophouder;//bevat progressindicator menubutton @FXML ProgressIndicator pi = new ProgressIndicator(); @FXML private MenuButton menuadressen; @FXML private HBox adres_knoppen_balk; // bevat adres houder en aksieknoppen(bevelknoppen) @FXML private HBox adresveldhouder; @FXML private TextField adresveld;
@FXML private HBox bevelhouder; @FXML private Button ververs; @FXML private Button volgend; @FXML private Button vorig; @FXML private Button vuur;
@FXML private HBox webzichthouder; @FXML private WebView webzicht;
@FXML void aksie_ververs(ActionEvent event) { webEngine.reload(); }
@FXML void vuur_adres_af(ActionEvent event) { //webzicht = new WebView(); webEngine.load(adresveld.getText()); webEngine.getLoadWorker().stateProperty().addListener( new ChangeListener<State>() { public void changed(ObservableValue<? extends State> arg0, State arg1, State arg2) { statelabel.setText("State: "+arg2.toString()); //arg0 :: bean/name/value //arg2 :: value } }); webEngine.getLoadWorker().progressProperty().addListener(new ChangeListener<Object>(){ @Override public void changed(ObservableValue<?> arg0, Object arg1, Object arg2) { pi.setProgress((Double) arg0.getValue()); } }); webEngine.locationProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { adresveld.setText(newValue); } }); adresveld.setText(webEngine.getLocation()); }
@FXML void vuur_volgend_adres_af(ActionEvent event) { webEngine.executeScript("history.forward()"); }
@FXML void vuur_vorig_adres_af(ActionEvent event) { webEngine.executeScript("history.back()"); } @FXML void aksie_adresveld_onenterpressed(ActionEvent event) { vuur_adres_af(event); } @FXML void aksie_kies_website(ActionEvent event) { System.out.println("OPen aksie"); System.out.println("tekst"+menuadressen.getItems().get(0).getText()+"::"+menuadressen.getItems().get(1).getText()); if(menuadressen.getText().equals("item01")){ System.out.println("OPen website synoniemen"); } } @FXML void aksie_kies_menuitem(ActionEvent event) { //Kode voor menubutton hier System.out.println("tekst items: "+menuadressen.getItems().get(0).getText()+"::"+menuadressen.getItems().get(1).getText());
}
@FXML void initialize() { webEngine = webzicht.getEngine();
}
}
3. BWLayout.fxml ------------- <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.control.*?> <?import javafx.scene.effect.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.paint.*?> <?import javafx.scene.text.*?> <?import javafx.scene.web.*?>
<AnchorPane id="AnchorPane" style="-fx-background-color: gray;" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="536.0" prefWidth="692.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="fxml.brauwser.WBController"> <children> <HBox id="css_titelbalk" fx:id="titelbalk" alignment="CENTER" layoutY="4.0" prefHeight="30.0" prefWidth="663.0" spacing="5.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="15.0"> <children> <HBox alignment="CENTER_LEFT" prefHeight="30.0" prefWidth="337.0" spacing="5.0" HBox.hgrow="ALWAYS"> <children> <Label prefWidth="496.0" text="pwWebBrauwser" HBox.hgrow="ALWAYS"> <font> <Font name="Arial" size="18.0"/> </font> </Label> <Label id="css_statelabel" fx:id="statelabel" prefWidth="150.0" text="State: " /> </children> </HBox> <HBox id="css_keuzeknophouder" fx:id="keuzeknophouder" alignment="CENTER_RIGHT" prefHeight="30.0" prefWidth="210.0" spacing="5.0"> <children> <ProgressIndicator id="css_pi" fx:id="pi" prefHeight="55.0" prefWidth="55.0" progress="0.0" /> <MenuButton id="css_menuadressen" fx:id="menuadressen" contentDisplay="CENTER" mnemonicParsing="false" onAction="#aksie_kies_website" prefHeight="30.0" prefWidth="162.0" text="WebAdressen" HBox.hgrow="NEVER"> <items> <MenuItem id="item01" mnemonicParsing="false" onAction="#aksie_kies_menuitem" text="Synos" /> <MenuItem id="item02" mnemonicParsing="false" text="Rijmen" /> </items> </MenuButton> </children> </HBox> </children> </HBox> <HBox id="css_adres_knoppen_balk" fx:id="adres_knoppen_balk" alignment="CENTER_RIGHT" layoutY="34.0" prefHeight="30.0" prefWidth="663.0" spacing="5.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="15.0"> <children> <HBox id="css_adresveldhouder" fx:id="adresveldhouder" alignment="CENTER_LEFT" prefHeight="21.0" prefWidth="565.0" spacing="5.0" HBox.hgrow="ALWAYS"> <children> <TextField id="css_adresveld" fx:id="adresveld" alignment="CENTER_LEFT" prefWidth="508.0" onAction="#aksie_adresveld_onenterpressed" text="http://www.google.es" HBox.hgrow="ALWAYS" /> </children> </HBox> <HBox id="css_bevelhouder" fx:id="bevelhouder" alignment="CENTER" minWidth="86.0" prefWidth="160.0" spacing="5.0"> <children> <Button id="css_vuur" fx:id="vuur" mnemonicParsing="false" onAction="#vuur_adres_af" text="Vuur" /> <Button id="css_vorige" fx:id="vorig" mnemonicParsing="false" onAction="#vuur_vorig_adres_af" text="<" /> <Button id="css_volgende" fx:id="volgend" mnemonicParsing="false" onAction="#vuur_volgend_adres_af" text=">" /> <Button id="css_ververs" fx:id="ververs" mnemonicParsing="false" onAction="#aksie_ververs" text="VV" /> </children> </HBox> </children> </HBox> <HBox id="css_webzichthouder" fx:id="webzichthouder" prefHeight="463.0" prefWidth="692.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="73.0"> <children> <WebView fx:id="webzicht" prefHeight="471.0" prefWidth="617.0" HBox.hgrow="ALWAYS" /> </children> </HBox> </children> </AnchorPane>
|