how to import data from text file to viewtable JAVAFX ?!
this is my code i want to read from a text file in this order
classNAME >> WMC >> DIT >> NOC >> CBO >>RFC >> LCOM >>Ca >> Ce ;
text file to be inputted to viewtable:
classNAME1 13 2 0 14 74 34 2 9
classNAME2 3 1 0 3 18 0 2 2
classNAME3 7 1 0 6 30 11 2 5
classNAME4 2 1 0 2 8 0 1 2
classNAME5 11 2 0 21 40 0 1 8
classNAME6 1 1 0 1 1 0 3 1
this is my viewtable source code
package viewtable;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.embed.swing.SwingFXUtils;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javax.imageio.ImageIO;
public class TableViewSample2 extends Application {
private TableView<metric> table = new TableView<metric>();
private final ObservableList<metric> data =
FXCollections.observableArrayList(
here i want to import data from text file
new Metric("99","1ss","2","3","4","5","6","7","8"),
new Metric("99","2","2","2","2","2","2","2","2"),
new Metric("99","3","3","3","3","3","3","3","3"),
new Metric("99","4","4","4","4","4","4","4","4"),
new Metric("99","5","5","6","6","5","5","5","5")
);
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws FileNotFoundException {
Scene scene = new Scene(new Group());
stage.setTitle("Result of Java Metrics Analysis");
stage.setWidth(700);
stage.setHeight(500);
final Label label = new Label("Result of Java Metrics Analysis");
label.setFont(new Font("Arial", 20));
table.setEditable(true);
TableColumn WMCCol = new TableColumn("WMC");
WMCCol.setMinWidth(50);
WMCCol.setCellValueFactory( new PropertyValueFactory<metric,>("WMC"));
TableColumn nCol = new TableColumn("nCol");
nCol.setMinWidth(50);
nCol.setCellValueFactory( new PropertyValueFactory<metric,>("nCol"));
TableColumn DITCol = new TableColumn("DIT");
DITCol.setMinWidth(50);
DITCol.setCellValueFactory( new PropertyValueFactory<metric,>("DIT"));
TableColumn NOCCol = new TableColumn("NOC");
NOCCol.setMinWidth(50);
NOCCol.setCellValueFactory( new PropertyValueFactory<metric,>("NOC"));
TableColumn CBOCol = new TableColumn("CBO");
CBOCol.setMinWidth(50);
CBOCol.setCellValueFactory( new PropertyValueFactory<metric,>("CBO"));
TableColumn RFCCol = new TableColumn("RFC");
RFCCol.setMinWidth(50);
RFCCol.setCellValueFactory( new PropertyValueFactory<metric,>("RFC"));
TableColumn LCOMCol = new TableColumn("LCOM");
LCOMCol.setMinWidth(50);
LCOMCol.setCellValueFactory( new PropertyValueFactory<metric,>("LCOM"));
TableColumn CaCol = new TableColumn("Ca");
CaCol.setMinWidth(50);
CaCol.setCellValueFactory( new PropertyValueFactory<metric,>("Ca"));
TableColumn NPMCol = new TableColumn("NPM");
NPMCol.setMinWidth(50);
NPMCol.setCellValueFactory( new PropertyValueFactory<metric,>("NPM"));
table.setItems(data);
table.getColumns().addAll(nCol,WMCCol,DITCol,NOCCol,CBOCol,RFCCol,LCOMCol,CaCol,NPMCol);
final VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.setPadding(new Insets(50, 10, 10, 10));
vbox.getChildren().addAll(label, table);
((Group) scene.getRoot()).getChildren().addAll(vbox);
stage.setScene(scene);
stage.show();
WritableImage image = table.snapshot(new SnapshotParameters(), null);
File file = new File("C:\\Users\\acer\\Desktop\\tableChart.png");
try {
ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
} catch (IOException e) {
}
}
public static class Metric {
private final SimpleStringProperty col;
private final SimpleStringProperty WMC;
private final SimpleStringProperty DIT;
private final SimpleStringProperty NOC;
private final SimpleStringProperty CBO;
private final SimpleStringProperty RFC;
private final SimpleStringProperty LCOM;
private final SimpleStringProperty Ca;
private final SimpleStringProperty NPM;
private Metric(String vcol,String vWMC,String vDIT, String vNOC, String vCBO,String vRFC,String vLCOM, String vCa, String vNPM) {
this.col = new SimpleStringProperty(vcol);
this.WMC = new SimpleStringProperty(vWMC);
this.DIT = new SimpleStringProperty(vDIT);
this.NOC = new SimpleStringProperty(vNOC);
this.CBO = new SimpleStringProperty(vCBO);
this.RFC = new SimpleStringProperty(vRFC);
this.LCOM = new SimpleStringProperty(vLCOM);
this.Ca = new SimpleStringProperty(vCa);
this.NPM = new SimpleStringProperty(vNPM);
}
public String getcol() { return col.get(); }
public void setcol(String vcol) { col.set(vcol); }
public String getWMC() { return WMC.get(); }
public void setWMC(String vWMC) { WMC.set(vWMC); }
public String getDIT() { return DIT.get(); }
public void setDIT(String vDIT) { DIT.set(vDIT); }
public String getNOC() { return NOC.get(); }
public void setNOC(String vNOC) { NOC.set(vNOC); }
public String getCBO() { return CBO.get(); }
public void setCBO(String vCBO) { CBO.set(vCBO); }
public String getRFC() { return RFC.get(); }
public void setRFC(String vRFC) { RFC.set(vRFC); }
public String getLCOM() { return LCOM.get(); }
public void setLCOM(String vLCOM) { LCOM.set(vLCOM); }
public String getCa() { return Ca.get(); }
public void setCa(String vCa) { Ca.set(vCa); }
public String getNPM() { return NPM.get(); }
public void setNPM(String vNPM) { NPM.set(vNPM); }
}
}