Saturday, June 1, 2013

Fee Payment Module

Hi
After the last hello world program in javafx, I started developing an app to check for student fee payment details based on the bill number. Only the interface part is done.

In developing this interface, I have used BorderPane, StackPane, HBox, VBox, TextField, Label, and Button (to toggle fullscreen mode).

The interface displays the college name, department (in this case it is Academic Section), followed by date. There  is a text field that takes the bill number.
A Full screen button to toggle fullscreen.

Hope it is useful for your understanding of javafx.

Source Code:
/**
 * Created with IntelliJ IDEA.
 * User: NaveenKumar
 * Date: 1/6/13
 * Time: 10:16 AM
 */

package FeeReceipt;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.util.Date;
import java.util.GregorianCalendar;

public class Main extends Application {

    public static void main(String[] args){
        launch(args);
    }

    @Override
    public void start(final Stage stage) throws Exception {
        stage.setFullScreen(true);

        BorderPane border = new BorderPane();
        VBox vbox_top = new VBox();
        vbox_top.setAlignment(Pos.CENTER);
        vbox_top.setPadding(new Insets(10,10,10,10));
        vbox_top.setStyle("-fx-background-color: #A9D0F5");

        // College Name
        Label colg_name = new Label();
        colg_name.setText("XYZ College of Engineering");
        colg_name.setFont(Font.font("Calibri", FontWeight.BOLD, 35));

        // Academic Section
        Label academic_section = new Label();
        academic_section.setText("Academic Section");
        academic_section.setFont(Font.font("Arial", FontWeight.BOLD, 30));

        //Fee Receipt
        Label fee_receipt = new Label();
        fee_receipt.setText("(Fee Receipt)");
        border.setTop(vbox_top);
        fee_receipt.setFont(Font.font("Verdana", FontWeight.BOLD, 20));

        HBox hbox1 = new HBox();
        //Bill No
        Label bill_no = new Label();
        bill_no.setText("Bill No:");
        bill_no.setFont(Font.font("Verdana", FontWeight.NORMAL, 18));

        //Bill Number Text field
        TextField bno = new TextField();
        bno.setPrefColumnCount(8);

        hbox1.getChildren().addAll(bill_no,bno);

        //date
        Label dt = new Label();
        dt.setText("Date:");

        StackPane dt_stack = new StackPane();
        Rectangle dt_rect = new Rectangle(150.0,25.0);
        dt_rect.setFill(new LinearGradient(0,0,0,1,true, CycleMethod.NO_CYCLE,
                new Stop[]{
                        new Stop(0, Color.web("#4977A3")),
                        new Stop(0.5,Color.web("#B0C6DA")),
                        new Stop(1,Color.web("9CB6CF")),
                }));
        dt_rect.setStroke(Color.web("#D0E6FA"));
        dt_rect.setArcHeight(3.5);
        dt_rect.setArcWidth(3.5);

        Date dt_today = new Date();
        String dt_today1 = dt_today.toString().substring(4,10)+" "+dt_today.toString().substring(dt_today.toString().length()-4,dt_today.toString().length());
        Text dt_text = new Text("  "+dt_today1);
        dt_text.setFont(Font.font("verdana", FontWeight.BOLD, 18));
        dt_text.setFill(Color.WHITE);
        dt_text.setStroke(Color.web("#7080A0"));
        dt_stack.getChildren().addAll(dt_rect,dt_text);
        dt_stack.setAlignment(Pos.CENTER_LEFT);

        //stack pane for full screen button
        StackPane stack = new StackPane();


        ImageView fs = new ImageView(
                new Image(Main.class.getResourceAsStream("graphics/view-fullscreen.png")));
        Button fullScrn = new Button();
        fs.setFitHeight(30);
        fs.setFitWidth(30);
        fs.setPreserveRatio(true);

        fullScrn.setGraphic(fs);

        //full screen event handler
        fullScrn.setOnAction(new EventHandler() {
            @Override
            public void handle(ActionEvent e) {
                stage.setFullScreen(!stage.isFullScreen());
            }
        });

        stack.getChildren().addAll(fullScrn);
        stack.setAlignment(Pos.CENTER_RIGHT);
        StackPane.setMargin(fullScrn,new Insets(0,10,0,0));
        // end of stack pane


        hbox1.getChildren().addAll(stack);
        HBox.setHgrow(stack, Priority.ALWAYS);

        vbox_top.getChildren().addAll(colg_name, academic_section, fee_receipt,dt_stack,hbox1);

        Scene scene = new Scene(border);
        stage.setScene(scene);
        stage.setTitle("Fee Payment");
        stage.show();
    }
}

OUTPUT:


Feel free to leave a comment. Thanks for visiting. Have a nice day.