Monday 6 November 2017

How to get past "InaccessibleObjectException" while running a JavaFX application in Java 9?

When you run a JavaFX project, that was perfectly running fine in Java 8, now in Java 9, you are faced with "InaccessibleObjectException" exception  that is thrown by the Java runtime. It complains that the variables and/or methods that you have declared as private (albeit annotated with @FXML) in your "controller" classes are inaccessible as your project's Java module has not made "open" the containing package to the JDK module "javafx.fxml". Here is the full text of the exception thrown by the runtime in my sample JavaFX project:
java.lang.reflect.InaccessibleObjectException: Unable to make field private javafx.scene.control.Label sample.Controller.nameLabel accessible: module LearningJavaModules does not "opens sample" to module javafx.fxml

I have declared the "nameLabel" Label variable as follows in the controller class:
 @FXML
 private Label nameLabel;

And it has been declared in the corresponding fxml file as below:
<Label fx:id="nameLabel" />

In order to remove this exception, one needs to add the following line to the "module-info.java" file of your project's Java Module:
opens sample to javafx.fxml;

Here is the complete "module-info.java" file of my sample JavaFX project:
module LearningJavaModules {
    requires javafx.graphics;
    requires javafx.fxml;
    requires javafx.controls;
    opens sample to javafx.fxml;
    exports sample;
}

Please note that it has been given in the "JavaFX: New & Notworthy" presentation by Oracle dated September 19, 2016 that one needs to add the following line to the "module-info.java" file:
exports private my.pkg to javafx.fxml;

However, this doesn't work. It seems that the implementation has changed since the above-mentioned presentation by Oracle was released. One now needs to use "opens" instead of "exports" to make private fields accessible to JavaFX runtime.

Trust that you find this useful. :-)

Sunday 1 October 2017

School Fee Manager - a free and open-sourced JavaFX application

Hi,

I am writing this post to introduce 'School Fee Manager' - an application that I have written for a neighborhood Play School.

This application manages fee payment records and student registration details. It issues fee receipts, generates few MIS reports, and prints Driver Sheet for school bus drivers' who ferry students to the school. It allows for filtering data on almost every screen where it displays the data so as to enable easy access to the relevant data. The filter facility can be accessed on most occasions by right-clicking a table-cell and choosing appropriate option from the context menu.

While generating a fee payment receipt, the application auto calculates the fee due, and auto populates the table that displays the fee items being paid. If a student is paying only a subset of the fee items due, then the remaining fee items can be removed from the receipt. It also provides for editing a fee payment receipt after it is generated to change the payment mode if that may be required.

The options to backup, restore and compact databases are available as they should be available in any good application. Few screenshots of the application are given below:





You can see many more screenshots of the application here.

The entire source code of the application as well as its executable file and Windows setup file is available for download. You can download it from here.

Please note that you need to have Java SE Runtime Environment (JRE) installed in your system in order to run this application. You can get the latest edition of JRE for your system from here.

I trust you will find this application useful. Truly speaking, I myself would have find this application extremely useful if I was learning JavaFX application development.

Should you have any query regarding the application, please use the comment section below to communicate with me.

Thanks for reading this post.

Cheers!







Thursday 22 September 2016

FXBilling - A free and open-sourced JavaFX Billing Application

Hi, I am happy to share with all the readers of my blog a billing application named FXBilling that I have developed in JavaFX. Before I tell more about this application, please have a look at its screenshot below:


More screenshots of the application can be viewed here.

This application is targeted at small-scaled Indian Traders, and is a JavaFX port of my earlier released C# billing application named Biller. The features include invoice generation & printing, invoice search, payment receipt, payment search, customer account lookup & printing, database backup & restoration.

I have taken every care to make this application bug-free; however, a bug or two may still have crept in. So, if you come across any bug, please let me know.

The Java version 8 (update 72) has been used to develop this application. Hence, you will require this or a newer version of Java to run the application. You can download Java SE Runtime Environment (JRE) from here.

FXBilling Executable Download Link

FXBilling Source Code Download Link

FXBilling Windows Installer Link

I trust that you will find this application useful whether you are a developer or a user, and you will also enjoy using it as much as I have enjoyed developing it. Do provide your feedback through the comments section below.

Thanks for your time!








Friday 29 January 2016

An Indian Matrimony website with source code in ASP.NET Web Pages

Today, I am sharing a website that I have developed to teach myself website development. It is a basic version of a typical Indian Matrimony website that allows users to register themselves, post their profiles and search for a suitable partner.

The website is complete as all the bare minimum features have been implemented. The website enables quick and advanced partner search as well as a search by Profile Id. The user can register with the site and create his/her profile; he/she can also upload up to 3 photos. The registration is not required to perform a partner search. Although, it is required to send a message to a user.

The facility to send a message to a user is not yet implemented. It is a critical feature as the website doesn't disclose the contact details of its users; so, in the absence of this feature, an interested person has no means to contact a profile owner. This facility (and some other facilities like blocking a message from a user, pagination of partner search results etc.) may be make available in a future release of the website.

The website has been developed in ASP.NET Web Pages 3 framework using Visual Studio 2013 Community Edition. The data store is SQL Server 2012. The server side language is C#.

No third party library or framework has been used either on the client side or the server side. It is all native, pure and standards-complaint HTML, CSS and JavaScript on the client side. The website supports modern browsers only (A modern browser usually means a browser that has been released not more than 2 years back). I have tested the application in the latest version of Chrome for Windows (version 48), but it should work in all capable modern browsers as no Chrome-specific property, feature or method has been used.

This source code could be a great learning resource for a person looking to learn website programming as it tries to make maximum use of the modern APIs like Constraint Validation API, asynchronous file upload through AJAX, displaying file upload progress through a Progress Bar etc. Best of all, it is all done through natively-available features. So, one is not burdened with the necessity to learn 3rd party libraries.

Website source code  |  Screenshots

Hope, you find this project useful. Please feel free to provide your feedback through the comments section.

Thanks for reading this post :-)

Friday 4 October 2013

Automatic client-side validation using the HTML5 'pattern' attribute

The new "pattern" attribute defined in HTML5 facilitates automatic validation of a textbox value by allowing the developer to define a Regular Expression pattern for the field. On form submission, the input value is validated against the pattern, and if the validation fails, the browser highlights the field and shows an error message.
Let's see an example that illustrates all this:



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Pattern attribute example</title>
</head>
<body>
<form>
<label id="pincode">Pin Code:</label>
<!--"required" attribute makes input mandatory in an input element -->
<input type="text" id="pincode" name="pincode"
pattern="^[1-9][0-9]{5}$" required
title="A six digit number that doesn't begin with zero.">
<br /> <br />
<button type="submit">Submit</button>
</form>
</body>
</html>


Running the above code in the Google Chrome browser gives me the following screenshot:


Wednesday 2 October 2013

JavaScript Slideshow

In this post, I will illustrate how to periodically change the image source of an 'img' element using JavaScript. This is a simple Slideshow, and doesn't show any animation in sliding in and sliding out of images. Images will be shown one after one at an interval of 3 seconds. Let's see the code now:



<!DOCTYPE html>
<html>
<head>
<title>JavaScript Slideshow</title>
</head>
<body>
<img >
<script>
var photos = ["file:///C:/Users/Public/Pictures/Sample Pictures/Tulips.jpg",
"file:///C:/Users/Public/Pictures/Sample Pictures/Penguins.jpg",
"file:///C:/Users/Public/Pictures/Sample Pictures/Lighthouse.jpg",
"file:///C:/Users/Public/Pictures/Sample Pictures/Koala.jpg",
"file:///C:/Users/Public/Pictures/Sample Pictures/Jellyfish.jpg"];
setInterval(changePhoto, 3000); //change image every 3 seconds
var imageElement = document.getElementsByTagName("img")[0];
imageElement.src = photos[0];
var arrayIndex = 0;
var arrayLength= photos.length;
function changePhoto() {
arrayIndex++;
if (arrayIndex === arrayLength) {
arrayIndex = 0;
}
imageElement.src = photos[arrayIndex];
}
</script>
</body>
</html>



Monday 30 September 2013

Extending properties/methods of an existing class in JavaScript

In JavaScript, properties/methods of an existing class can be extended by using the 'prototype' property of that class. Let's see an example of how to add a function named 'isInt' to String class. This function, as is obvious from its name, tells whether the text content of the target String is a number or not.


<script>
if (String.prototype.isInt == null) {
String.prototype.isInt = function() {
var result = parseInt(this.valueOf());
return !isNaN(result);
}
}
var i = "27";
var j = "shyam";
var paraElement = document.getElementById("output");
paraElement.innerHTML = ("Is '27' an integer : " + i.isInt());
paraElement.innerHTML += (" <br > Is 'shyam' an integer : " + j.isInt());
</script>