Steinalb's Posts
Nairaland Forum › Steinalb's Profile › Steinalb's Posts
1 2 3 4 5 6 7 8 9 10 (of 16 pages)
I am really very interested in ML but have not seen any good java textbook on it. Someone can please lend a helping hand. |
if your usb port is broken like mine, transfer the apk to the android phone and install. Be mindful of the footprint. JavaFX Desktop Applications have bigger footprints than their Android counterparts.
|
open command prompt, use cd command to enter into the new JavaFX android project. use the command: ant debug or ant clean debug This will create a debug-version (not signed) of the Android application in the bin subdirectory of the directory. The Android application can now be transferred to a real Android device connected to your development system, by calling $ANDROID_SDK/platform-tools/adb install -r bin/FXANDROIDTUT-debug.apk if adb is part of the android sdk you downloaded.
|
Open the Visual Code Studio (Am using it as an Editor). Add this code to build an Android gradle project from the JavaFX project (FXANDROID). set ANDROID_SDK=C:/Users/STEINACOZ-PC/AppData/Local/Android/sdk set WORKDIR=C:/Users/STEINACOZ-PC/Documents/portingFX set JFX_SDK=C:/dalvik-sdk-latest/dalvik-sdk gradlew.bat --info --stacktrace createProject -PDEBUG -PDIR=%WORKDIR% -PPACKAGE=com.fxandroid -PNAME=FXANDROIDTUT -PANDROID_SDK=%ANDROID_SDK% -PJFX_SDK=%JFX_SDK% -PJFX_APP=C:/Users/STEINACOZ-PC/Documents/NetBeansProjects/FXAndroid/dist -PJFX_MAIN=fxandroid.FXAndroid Name the file createFXANDROID.bat it is actually a windows batch file. -the first line sets the path to the android SDK installed in the system -second line sets the output folder where the android gradle project will be created -third line sets the path to the JavaFX dalvix SDK (where you unpacked it) -the fourth line is the calls gradlew.bat shipped with JavaFX dalvix SDK, createProject command is called with the following parameters passed to it: -PNAME = name of the android project and name to be created -PPACKAGE = name of the android package to be created -PJFX_APP = location of the JavaFX application jar file -PJFX_MAIN = name of the JavaFX Main Class prefixed by the package name Save the createFXANDROID.bat file in the same location JavaFX dalvix SDK, under android tools. Double click to run. go to the output folder to see the new android gradle project
|
-Create a Simple JavaFX application: package fxandroid; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ScrollPane; import javafx.scene.control.TextArea; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.scene.text.Text; import javafx.stage.Stage; /** * * @author STEINACOZ-PC */ public class FXAndroid extends Application { @Override public void start(Stage primaryStage) { Text text = new Text(); TextArea textArea = new TextArea(); Button btn = new Button(); Circle circle = new Circle(); VBox vb = new VBox(); vb.setPadding(new Insets(20,20,20,20)); text.setText("Testing JavaFX port with ant" ;circle.setFill(Color.RED); circle.setRadius(60); btn.setText("PRINT" ;btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { textArea.setText("testing JavaFX application on Android" ;circle.setFill(Color.GREEN); } }); vb.getChildren().addAll(text,btn,textArea,circle); ScrollPane root = new ScrollPane(); root.setContent(vb); Scene scene = new Scene(root, 350, 550); primaryStage.setTitle("JAVAFX PORT" ;primaryStage.setScene(scene); primaryStage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } } Clean and build to create the jar file in the dist folder. We will be using only JavaFX Main class for this tutorial. FXML and FXML Controller will be added in the next tutorial. From the code and the Image, the application should explain itself.
|
Run this commands to verify if everything is ok
|
my other account was just banned now. - Download JDK 7 or 8 from oracle website and install. Add it to your Environment Variables. - Download Android Studio IDE, Android SDK comes with it Add the Android Studio SDK path to your Environment Variables. Add the Android Studio SDK/tools path to your Environment Variables. -Download JavaFX Dalvik SDK and unpack the Zip file to a good location on your system, preferrably under C:/ - Download Gradle and unpack the Zip file to good location add the path to your Enivironment Variables. - Download ant and unzip to a good location add the path to your Enivironment Variables. |
other proposed business methods: -generateBVN the generated BVN will be ten digits (123567890) -generateAcctNumber the generated account number will be six digits and four characters. The last two characters will MA if male and FE if female. 123456GKMA - male 123456CGFE - female -saveImage -returnImage -sendEmail |
- ATM unit In this unit, the customer has control over it. operations are authenticated with unique pins: -withdrawMoney (pin, amount) -transferMoney (pin, receiver's account number, amount) -changePIN (old pin, new pin) -viewBalance (pin) if you have any other business method in mind, please let me know. |
-Teller Unit In this unit, the bank staff performs the necessary operations: -credit/deposit money to customer's account -debit/withdraw from customer's account -transfer money between customers I will be proposing the following business methods for this unit: - depositMoney (account number, amount) - withdrawMoney (account number, amount) - transferMoney (sender's account number, receiver's account number, amount) if you have any other business method in mind, please let me know. |
- Customer Care Unit: In this unit, the following operations will be performed: - create new accounts for customers - update customer's account - delete customer's acoount - retrieve customer's account details and account balance. - send an email notification to the customer on each operation. I will be proposing the following business methods for this unit: - createNewAcct (customer) - deleteAcct (account number) - updateAcct (account number, customer) - acctDetails (account number) if you have any other business method in mind, please let me know. |
In order to digest all we have done, I will start a new project: - The application will simulate a banking system, all the operations performed in the bank which I know of (deposit, withdraw, balance, transfer, update account information, create new account, email notification etc). It will be divided into three units: - Customer Care Unit - teller unit - ATM unit |
-Netbeans IDE took away alot of stress and hassles here. -Remember, the database generates id field automatically so endeavor to leave the field blank to avoid throwing exceptions. -open create.xhmtl, change the id field: required="false" the SOURCE CODE is hosted on Github if you love fancy UI, you can edit the css/jsfcrud.css to suit your taste. |
-Create a new folder in InventoryBeer-JSF project folder named setup, add the jboss datasource file (jboss-ds.xml) which we have been using in the previous examples. -Add jboss-client.jar to the project's library and finally click on run. The server will generate the url for the web application: http://localhost:8050/InventoryBeer-JSF
|
- Generating JSF Pages From Entity Classes Now that the entity class have been created, we can now create the web interface for displaying and modifying the data. You will use the JSF Pages from Entity Classes wizard to generate JavaServer Faces pages. The code generated by the wizard is based on persistence annotations contained in the entity classes. For each entity class the wizard generates the following files. -a stateless session bean that extends AbstractFacade.java -a JSF session-scoped, managed bean -a directory containing four Facelets files for CRUD capabilities (Create.xhtml, Edit.xhtml, List.xhtml, and View.xhtml) The wizard also generates the following files. -the AbstractFacade.java class that contains the business logic for creation, retrieval, modification and removal of entity instances utility classes used by the JSF managed beans (JsfUtil, PaginationHelper) -a properties bundle for localized messages, and a corresponding entry in the project's Faces configuration file (A faces-config.xml file is created if one does not already exist.) -auxiliary web files, including a default stylesheet for rendered components, and a Facelets template file To generate the JSF pages: In the Projects window, right-click the project node and choose New > JSF Pages from Entity Classes to open the wizard. (If this option is not listed, choose Other. Then, in the File wizard, select the JavaServer Faces category, then JSF Pages from Entity Classes.) -The Available Entity Classes box lists the entity class contained in the project. -Click Add All to move all the classes to the Selected Entity Classes box. Click Next. In Step 3 of the wizard, Generate JSF Pages and Classes, type com.session for the JPA Session Bean Package. Type jsf for the JSF Classes Package. Enter 'resources/Bundle' into the Localization Bundle Name field. This will generate a package named resources which the Bundle.properties file will reside in. (If you leave this blank, the properties bundle will be created in the project's default package.) TIP: To let the IDE better accommodate your project conventions, you can customize any files generated by the wizard. Click the Customize Template link to modify the file templates used by the wizard. In general, you can access and make changes to all templates maintained by the IDE using the Template Manager (Tools > Templates). Click Finish. The IDE generates the stateless session beans in the com.session package, and the JSF session-scoped, managed beans in the jsf package. Each stateless session bean handles the operations for the corresponding entity class, including creating, editing, and destroying instances of the entity class via the Java Persistence API. Each JSF managed bean implements the javax.faces.convert.Converter interface and performs the work of converting instances of the corresponding entity class to String objects and vice versa. If you expand the Web Pages node, you can see that the IDE generated a folder for each of the entity classes. Each folder contains the files Create.xhtml, Edit.xhtml, List.xhtml and View.xhtml. The IDE also modified the index.xhtml file by inserting links to each of the List.xhtml pages. Each JSF managed bean is specific to the four corresponding Facelets files and includes code that invokes methods in the appropriate session bean. Expand the resources folder node to locate the default jsfcrud.css stylesheet that was generated by the wizard. If you open the application welcome page (index.xhtml) or the Facelets template file (template.xhtml) in the editor, you will see that it contains a reference to the stylesheet. <h:outputStylesheet name="css/jsfcrud.css"/> The Facelets template file is used by each of the four Facelets files for each entity class. If you expand the Source Packages node you can see the session beans, JSF managed beans, utility classes, and properties bundle that the wizard generated. The wizard also generated a Faces Configuration file (faces-config.xml) in order to register the location of the properties bundle. If you expand the Configuration Files node and open faces-config.xml in the XML editor, you can see that the following entry is included. <application> <resource-bundle> <base-name>/resources/Bundle</base-name> <var>bundle</var> </resource-bundle> </application> Also, if you expand the new resources package, you'll find the Bundle.properties file that contains messages for the client's default language. The messages have been derived from the entity class properties. TIP: To add a new property bundle, right-click the Bundle.properties file and choose Customize. The Customizer dialog enables you to add new locales to your application.
|
- Generating the Entity Classes from the Database -After connecting to a database in the IDE, you can use the Entity Classes from Database wizard to quickly generate entity classes based on the tables in the database. The IDE can generate entity classes for each table that you select, and can also generate any necessary entity classes for related tables. -In the Projects window, right-click the InventoryBeer-JSF project node, and choose New > Entity Classes from Database. (If this option is not listed, choose Other. Then, in the File wizard, select the Persistence category, then Entity Classes from Database.) -For datasource select the jdbc:postgresl://localhost:5432/postgresdb connection as the Database source from the drop down menu. -The tables in the postgresdb database appear in the Available Tables listbox. -Highlight the beers table, Click the Add button to select the table. Click Next. -Type com.entity as the Package name. -Confirm that the checkboxes to generate named queries and create a persistence unit are selected. Click Finish. - When you click Finish, the IDE generates the entity class in the com.entity package of the project.
|
- Creating Web Application Project: Choose File > New Project from the main menu. Select Web Application from the Java Web category. Click Next. Type InventoryBeer-JSF for the project name and set the project location. Click Next. Set the server to wildfly application server, leave the contextual path as default and set the Java EE Version to Java EE 6 Web or Java EE 7 Web. Click Next. In the Frameworks panel, select the JavaServer Faces option. Click Finish. When you click Finish, the IDE generates the web application project and opens index.xhtml in the editor.
|
- Creating Database: We already have a ready made postgres database named postgresDB, in case you have not created yours. Refer to the previous sections. |
we shall be using images in this section so as to encourage clarity. These are the steps we will be following in this section: - Creating the Database - Creating the Web Application Project - Generating the Entity Classes from the Database - Generating JSF Pages From Entity Classes |
In the next section, we will implement JavaServer Faces (JSF) which will perform CRUD (Create retrieve update and delete) operations on our database |
GITHUB project location for this Web Service demonstration. |
finally, add the lines of code you see in the main method, Run the project. NOTE: You can make modifications to the codes to show output in XML or JSON format depending on the format the consumer needs.
|
Select Web Service getAllBeers web method as shown in the figure below and drag it to code window of Inventory_ClientWS
|
- After creating the creating the file and other things, this is how your project tree will look like.
|
web services are based on the exchange of messages using non-proprietary protocol messages. The messages themselves are not sufficient to define the web service platform. We actually need a list of standard components, including the following: A language used to define the interfaces provided by a web service in a manner that is not dependent on the platform on which it is running or the programming language used to implement it A common standard format to exchange messages between web service providers and web service consumers A registry within which service definitions can be placed. The Web Service Description Language, also known as WSDL,is the de facto standard to provide a description of a web service contract exposed to clients. In particular, a WSDL document describes a web service in terms of the operations that it provides, and the data types that each operation requires as inputs and can return in the form of results. |
steinalb:-If you have DEPLOY ON SAVE enabled, the inventory-ejb will automatically deploy if not, clean and build then deploy. -Watch out for the location of the WSDL file generated by the server from the server console. -Highlight the new java project (Inventory_ClientWS); click on new > Web Service client -You can see the location of mine from my server console -check local file, add the WSDL file location, -create the package and click on finish.
|
- from netbeans create new project wizard, choose Java project; from category, choose Java application - Create a main class named Inventory_ClientWS inside package com.clientws (don't forget to create this package). |
To create the web service, we will reuse the inventory-ejb project. open it and add the following lines after the stateless annotation and after the override annotation of getAllbeers() respectively: @WebService(serviceName = "BeerService" ![]() @WebMethod(operationName = "getAllBeers" ![]() GITHUB repository for Inventory-ejb project |
Creating the BeerQueue: -open the wildfly installation folder: wildfly folder > bin folder: mine is C:\wildfly-10\bin -open (double click) on jboss-cli.bat -make sure your server is on and use the command connect. press enter -type this command when it have connected: /subsystem=messaging-activemq/server=default/jms-queue=BeerQueue/:add(entries=["java:/jboss/exported/jms/queue/BeerQueue"]) - The Queue will be created and also the JNDI binding name. the exported in the JNDI binding is meant for remote clients who don't have access to the JVM installed on the system where the server is located/running.
|
-what we do first is to create another user for the wildfly server in the applicationRealm -Create a JMS queue with name BeerQueue -Create our normal entity and persistence classes for persistence purposes. -Create a Message driven bean and other files then finally deploy. |
In this next section, I will be peeping into Message driven bean A message-driven bean is an enterprise bean that allows J2EE applications to process messages asynchronously. It acts as a JMS message listener, which is similar to an event listener except that it receives messages instead of events. The messages may be sent by any J2EE component—an application client, another enterprise bean, or a Web component—or by a JMS application or system that does not use J2EE technology. Message-driven beans currently process only JMS messages, but in the future they may be used to process other kinds of messages. What Makes Message-Driven Beans Different from Session and Entity Beans? The most visible difference between message-driven beans and session and entity beans is that clients do not access message-driven beans through interfaces. Unlike a session or entity bean, a message-driven bean has only a bean class. In several respects, a message-driven bean resembles a stateless session bean. • A message-driven bean’s instances retain no data or conversational state for a specific client. • All instances of a message-driven bean are equivalent, allowing the EJB container to assign a message to any message-driven bean instance. The container can pool these instances to allow streams of messages to be processed concurrently. • A single message-driven bean can process messages from multiple clients. The instance variables of the message-driven bean instance can contain some state across the handling of client messages—for example, a JMS API connection, an open database connection, or an object reference to an enterprise bean object. When a message arrives, the container calls the message-driven bean’s onMessage method to process the message. The onMessage method normally casts the message to one of the five JMS message types and handles it in accordance with the application’s business logic. The onMessage method may call helper methods, or it may invoke a session or entity bean to process the information in the message or to store it in a database. A message may be delivered to a message-driven bean within a transaction context, so that all operations within the onMessage method are part of a single transaction. If message processing is rolled back, the message will be redelivered. When to Use Message-Driven Beans Session beans and entity beans allow you to send JMS messages and to receive them synchronously, but not asynchronously. To avoid tying up server resources, you may prefer not to use blocking synchronous receives in a server-side component. To receive messages asynchronously, use a message-driven bean. |
;