import javafx.application.Application; import javafx.application.Platform; import javafx.stage.Stage; import javafx.scene.layout.*; import javafx.scene.control.*; import javafx.scene.text.*; import javafx.event.*; import javafx.scene.*; import java.io.*; import java.util.*; import javafx.geometry.Insets; import javafx.stage.FileChooser; public class Handleliste extends Application{ public void start(Stage teater){ VBox matListe = new VBox(); Button filvelger = new Button("Velg Fil"); Text antallText = new Text("Antall:"); Text tallet = new Text("0"); filvelger.setOnAction(new FilBehandler(teater,tallet, matListe)); VBox.setMargin(matListe,new Insets(10,0,10,0)); HBox antallBox = new HBox(); antallBox.getChildren().addAll(antallText,tallet); Button stop = new Button("stopp"); stop.setOnAction(new StoppBehandler()); VBox kuliss = new VBox(); kuliss.getChildren().addAll(filvelger, antallBox, matListe,stop); kuliss.setStyle("-fx-backgroundcolor:#f0f0f0;"+ "-fx-padding:20px;"); Scene scene = new Scene(kuliss); teater.setScene(scene); teater.show(); } public class StoppBehandler implements EventHandler{ public void handle(ActionEvent event){ Platform.exit(); } } public class FilBehandler implements EventHandler{ Stage teater; VBox matListe; Text tallet; public FilBehandler(Stage teater,Text tallet, VBox matListe){ this.matListe = matListe; this.teater = teater; this.tallet=tallet; } public void handle(ActionEvent event){ FileChooser filvelger = new FileChooser(); File fil = filvelger.showOpenDialog(teater); try{ Scanner in =new Scanner(fil); int antall = 0; while(in.hasNextLine()){ Text matbit = new Text(in.nextLine()); matListe.getChildren().add(matbit); antall ++; } tallet.setText("" + antall); }catch(FileNotFoundException exception){} } } }