Google+ Followers

Thursday, June 14, 2012

Wednesday, June 6, 2012

JavaFx - CHART example

We would like to have a chart of the imported fruits. 
Let' see in JavaFx the PieChart diagram:

public class JavaFXApplication1 extends Application {

    public static void main(String[] args) {
    public void start(Stage primaryStage) {
      primaryStage.setTitle("Chart example");
      ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
                new PieChart.Data("Grapefruit", 13),
                new PieChart.Data("Oranges", 25),
                new PieChart.Data("Plums", 10),
                new PieChart.Data("Pears", 22),
                new PieChart.Data("Apples", 30));
        PieChart chart = new PieChart(pieChartData);
        chart.setTitle("Imported Fruits");       
        StackPane root = new StackPane();
        primaryStage.setScene(new Scene(root, 300, 250));;

Java - read from console, dos prompt

The JAVA file is the following, for an example of reading input values from console:

package javaapplication1;


public class JavaApplication1 {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(;
        String prompt = "";       
        System.out.println("Enter your name: ");
        prompt = reader.readLine();
        if (prompt.equals("\t"))
            System.out.println("You entered a TAB from your keyboard.");
            System.out.println("Your name is: "+prompt);

Friday, June 1, 2012

Java - sorting strings with Hungarian characters

        Let's sort some Hungarian strings in alphabetical order:

        String[] words = {"Bruce","Géza","Ákos"};

        Collator c = Collator.getInstance(new Locale("hu"));      
        Arrays.sort(words, c);

        for(int m=0; m<words.length; m++)
            System.out.print(words[m]+", ");