Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label Java tutorial. Show all posts
Showing posts with label Java tutorial. Show all posts

Wednesday, 19 April 2017

Get af:richTextEditor value without HTML formatting and tags using jsoup library



af:richTextEditor
is used to format text in rich text using HTML formatting and it is used to get the formatted text. Previously I have posted about it
Cool Component - Using af:richTextEditor as text editor, HTML editor with custom toolbox in Oracle ADF

Wednesday, 15 March 2017

Fetch Tweets of a User using Twitter4J API and show in af:table in ADF & Java


In the previous blogs we learned about posting tweets on twitter timeline using Twitter4J API and sending direct meaages to followers using same API

This post is next in the series and about fetching a user tweets and showing in ADF Table , For this requirement we need to use same Consumer Key+ Secret and Access Token+Secret (Refer previous posts for this)

And In same way after authentication we can fetch a user tweets by using it's twitter handle. So for this requirement I have added a button to fetch tweets and a POJO based table to show fetched tweets in page

See the code to fetch tweets using user's twitter handle and it's retweets and favourites count, We can get tweets by passing page number as parameter and it returns a list of tweets


Thursday, 9 March 2017

Send Direct Message to followers using Twiter4J API in Oracle ADF and Java


My previous post was about tweeting using Twitter4J API from Oracle ADF Application . Twitter4J is a Java API that simplifies accessting twitter features in our application easily

In this I am going to show how to send DM (Direct Message) to anyone using their twitter handle and for this we need to use same consumer key, secret and access token, secret (How to access all these is described in previous post)

Tuesday, 7 March 2017

Post to twitter using Twitter4J API in Oracle ADF and Java


Hello All

In this post I am talking about how to post a tweet on your twitter timeline using Twitter4J Java API in your Oracle ADF Application
Using this API makes the process very simple , For accessing twitter we need Twitter API keys, It is called Consumer Key and Access Token

For this you need a twitter account and then follow these steps

Thursday, 2 March 2017

Generate permanent Facebook Page Access Token to access Graph API


Hello All,
Hope you are doing well

Earlier I have posted about using facebook graph api to get profile information, post status on facebook timeline and post as facebook page.

To Access Facebook graph API we need to use Access Token and each access token has it's expiry time (temporary access tokens) but to build an application we need a permanent access token so that our app doesn't stop working after a time and it is not very easy to get a permanent access token , there are some steps you need to follow to get one

Thursday, 16 February 2017

Post to Facebook Page Wall using restfb Graph API in ADF & Java


This is next post working with Facebook Graph API series, Previously I have posted about gettting access token and use it to get Facebook Profile detail and Posting status on your Facebook Timeline using restfb Facebook Graph API

Go through previous posts for better understanding of this blog post

Saturday, 11 February 2017

Post Status on Facebook Timeline using restfb Graph API in ADF & Java

Hello All

Previous post was about generating temporary access token and using it get Facebook profile detail usinf restfb Graph API , Go through previous post before this as graph api basics are described in that post

Now In this post I am talking about posting facebook status update so for this I am extending same sample application

Wednesday, 8 February 2017

Get Facebook profile detail using restfb Graph API in Java & ADF


Facebook is most popular social networking sites now a days and influencing our life in all aspect. Facebook gives us option to use it's Graph API to access it's features programmatically, The Graph API is primary way to read and write to facebook social graph using Access Tokens

In this post I am talking about how to access Facebook profile detail using restfb graph API . So First we need to know about Acsess Tokens

Monday, 23 May 2016

Execute batch file from Java Code using Runtime class

We can call any exe file from Java code using Runtime class, Runtime class extends Object class and introduced in JDK1.0

What docs says-

Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method.
An application cannot create its own instance of this class.

Here we will see how to execute .exe and .bat file from javacode, for executable files we just pass file path and Runtime class will invoke it. But for batch file we have to first open supporting application i;e Command Promt and then provide path for batch file

See Java Programs for both case:

Friday, 30 October 2015

Read data from Google Spreadsheet without authentication using Java

Google Spreadsheets provides a way to create, edit, save spreadsheets online.
The Google Sheets API (formerly called the Google Spreadsheets API) lets you develop client applications that read and modify worksheets and data in Google Sheets.
Read More about Sheets API

Let's see how to use this API to read data from Spreadsheet, here i am going to use Spreadsheet version 3.0 , if this link doesn't work then check on GitHub , from here you will get  client library for all Google APIs

Monday, 19 October 2015

Get domain information (WHOIS) using Apache Commons Net API- ADF & Java

We can get any domain information using Apache commons net library. It supports various protocols and WHOIS information is one of them

WhoisClient class provides access of domain information
See what docs says -

The WhoisClient class implements the client side of the Internet Whois Protocol defined in RFC 954. To query a host you create a WhoisClient instance, connect to the host, query the host, and finally disconnect from the host. If the whois service you want to query is on a non-standard port, connect to the host at that port.

Download required library or if this link doesn't work then goto API page and download from there

This simple java method will fetch information of domain using Apache library

Monday, 5 October 2015

Allow user input in Jdeveloper for Java applications, Using Java Scanner Class to take input from console

Sometimes we have to take input from Keyboard when we use Scanner or BufferedReader class.
and to take input from Jdeveloper we have to change a setting to allow user input in Jdeveloper.

Let's take an example of java.util.Scanner class-

package client;

import java.util.Scanner;

public class UserInput {
    public UserInput() {
        super();
    }

    public static void main(String[] args) {
        System.out.println("Please Enter your Name-");
        Scanner sc = new Scanner(System.in);
        String name = sc.next();
        System.out.println("Your Name is " + name);
    }

}

Monday, 3 August 2015

Iterate over HashMap to get Key and Value in Java , Add records to HashMap


Iterating over HashMap is not same as other collections , It's a bit tricky than normal iteration ;)
See in this code -
How to add values to HashMap ?
and How to iterate over HashMap to get Key and Values?






package client;

import java.util.HashMap;
import java.util.Iterator;

public class IterateHashMap {
    public IterateHashMap() {
        super();
    }

    public static void main(String[] args) {
        HashMap<Integer, String> mapVal = new HashMap<Integer, String>();

        //Add values to Map
        mapVal.put(1, "value 1");
        mapVal.put(2, "value 2");
        mapVal.put(3, "value 3");
        mapVal.put(4, "value 4");

        //Create Iterator from keySet
        Iterator iter = mapVal.keySet().iterator();
        //Iterate over hashmap to get key
        while (iter.hasNext()) {
            int key = (Integer) iter.next();
            //Use this key to find value
            String value = mapVal.get(key).toString();
            System.out.println("**KEY**  " + key + " AND VALUE**  " + value);
        }

    }
}


Cheers :) Happy Learning

Sunday, 22 March 2015

Java Database Connectivity- JDBC Tutorial, PreparedStatement, ResultSet

JDBC is java based API or technology to access data from database and use in Java Desktop or Enterprize application. In short we can say JDBC is an interface between Java and Database, using JDBC you can interact with any of database as Oracle, MySQL, Access.
JDBC is released with JDK(Java Development Kit)1.1 on 19 Feb 1997 and It is a part of Java Standard Edition. if you know about DBMS(Database Management Systems) then you should know about Database Drivers, drivers are of 4 types.
  1. Type 1 Driver - JDBC-ODBC bridge
  2. Type 2 Driver - Native-API Driver
  3. Type 3 Driver - Network-Protocol Driver(MiddleWare Driver)
  4. Type 4 Driver - Native-Protocol Driver(Pure Java Driver)-Thin Driver
If you don't have java installed , follow the link below to donload it

JDK1.7- Download jdk1.7
Now we will learn that how to implement Database connection in Java. To start with JDBC you must have a little knowledge of DBMS and SQL(Structured Query Language) to interact with Database
here i will show you that how to connect with Oracle Database
Follow these steps to connect with Oracle Database



1. Load Driver (Thin Driver)

The very first step towards database connection is Loading Driver, as discussed we use pure java driver in JDBC connectivity there are two steps to load driver for connection

A. Using DriverManager class
The syntax is - DriverManager.registerDriver(DriverName);


  1.         try {
  2.             DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  3.            
  4.         } catch (SQLException e) {
  5.         }
  6.        

B. Using Class.Forname class
The syntax is - Class.forName(”DriverName”);

  1.         try {
  2.              Class.forName("oracle.jdbc.driver.OracleDriver");
  3.            
  4.         } catch (SQLException e) {
  5.         }
  6.        


2. Create Connection


Connection interface is inside java.sql package and extends Wrapper interface. now to create Connection we register driver with DriverManager class.
Syntax is- DriverManager.getConnection("url string", "username", "password");

  1.  try {
  2.      DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  3.      con=DriverManager.getConnection(
  4.      "jdbc:oracle:thin:@192.168.1.234:1521:XE", "hr", "hr");
  5.  } catch (SQLException e) {
  6.  }

You have to change url string with your ip address and SID according to your database setting

3. Execute PreparedStatement and return Resultset


Now we see that how to execute SQL query using PreparedStatement and store its result in ResultSet object
Here i am getting username and password from LOGIN_DET table (you can use your own query here)

  1.         Connection con;
  2.         try {
  3.             DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  4.             con = DriverManager.getConnection("
  5.            jdbc:oracle:thin:@192.168.1.241:1521:eadf", "hr", "hr");
  6.             PreparedStatement psmt = con.prepareStatement("SELECT * FROM LOGIN_DET");
  7.             ResultSet rs = psmt.executeQuery();
  8.             if (rs.next()) {
  9.                 while (rs.next()) {
  10.                 System.out.println("Username is--" + rs.getString(1)
  11.                + "and Password is-->" + rs.getString(2) +
  12.                "Email Id is--->" + rs.getString("E_ID"));
  13.                 }
  14.             }
  15.             psmt.close();
  16.             con.close();
  17.         } catch (SQLException e) {
  18.         }


This is the brief overview of using JDBC with Oracle Database, For others you have to change only DriverName respectively
Happy Learning :)

Monday, 20 October 2014

Send SMS from Oracle ADF Application using Horizon SMS API

This post is about using SMS API to send SMS text to mobile from an Oracle ADF application
there are various SMS Gateway to send SMS using java and all java API's can be used with Oracle ADF

here i am using sms horizon (a bulk sms provider in india) see this SMS API integration with Java and Oracle ADF, follow the steps
First create an account with SMS Horizon - http://www.smshorizon.in/ or User Login- SMS Horizon

you can purchase a trial package to test your code, they provide 200 sms for Rs 25 only. So After purchasing trial pack you will get and API Key and username



Login to your account and see your dashboard-



you will see your API key in this type of box-



Now first step is complete and second and last step is implement code in your managed bean
you can find Sample API files (code to use API in Java, C#, PHP etc) from there

So for this i have a created a Fusion Web Application and a page in it


created a managed bean and actionListener for this Send button
this url is used to send sms and it returns msgId of sent message

http://smshorizon.co.in/api/sendsms.php?user=******&apikey=*****8&mobile=xxyy&message=xxyy&senderid=xxyy&type=txt


See the ActionListener code -


    /**Method to send SMS using SMS Horizon API
     * @param actionEvent
     */
    public void sendSMSAction(ActionEvent actionEvent) {
        // get mobile number value using component binding
        if (mobNoBind.getValue() != null) {
            // Replace with your username
            String user = "userId";

            // Replace with your API KEY (We have sent API KEY on activation email, also available on panel)
            String apikey = "your_api_key";

            // Replace with the destination mobile Number to which you want to send sms
            String mobile = mobNoBind.getValue().toString();

            // Replace if you have your own Sender ID, else donot change
            String senderid = "WEBSMS";

            // Replace with your Message content
            String message = "SMS API -Oracle ADF";

            // For Plain Text, use "txt" ; for Unicode symbols or regional Languages like hindi/tamil/kannada use "uni"
            String type = "txt";

            //Prepare Url
            URLConnection myURLConnection = null;
            URL myURL = null;
            BufferedReader reader = null;

            //encoding message
            String encoded_message = URLEncoder.encode(message);

            //Send SMS API
            String mainUrl = "http://smshorizon.co.in/api/sendsms.php?";

            //Prepare parameter string
            StringBuilder sbPostData = new StringBuilder(mainUrl);
            sbPostData.append("user=" + user);
            sbPostData.append("&apikey=" + apikey);
            sbPostData.append("&message=" + encoded_message);
            sbPostData.append("&mobile=" + mobile);
            sbPostData.append("&senderid=" + senderid);
            sbPostData.append("&type=" + type);

            //final string
            mainUrl = sbPostData.toString();
            System.out.println("URL to Send SMS-" + mainUrl);
            try {
                //prepare connection
                myURL = new URL(mainUrl);
                myURLConnection = myURL.openConnection();
                myURLConnection.connect();
                reader = new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));
                //reading response
                String response;
                while ((response = reader.readLine()) != null) {
                    //print response
                    System.out.println(response);
                }
                System.out.println(response);
                //finally close connection
                reader.close();


            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public void setMobNoBind(RichInputText mobNoBind) {
        this.mobNoBind = mobNoBind;
    }

    public RichInputText getMobNoBind() {
        return mobNoBind;
    }

you can check status of each SMS in your account that it is delivered of not, other than this you can also check status of msg in your code also using this url

http://smshorizon.co.in/api/status.php?user=*****&apikey=*********&msgid=xxyy

pass msgId returned from previous url and it will return you status of message as- PENDING , DELIVERED etc
see imports used in code-


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

import javax.faces.event.ActionEvent;

import oracle.adf.view.rich.component.rich.input.RichInputText;

Thanks :) Happy Learning

Friday, 23 May 2014

Reading html source of a webpage (url) using Oracle ADF (af:richTextEditor) & Java

This post is about a common question asked in java-

How to read page source of a website ? or how to get html source of an url?

so for that there is a simple piece of code to read html source of a webpage using it's url, and i have added  af:richTextEditor (ADF Faces component for ricj text formatting) to show html form of url source

  • I have a page with one input text to capture url entered by user, a button to fetch html source of that webpage and a af:richTextEditor to show source code in editing mode and in html mode 


  • See how to get webpage source from an url using java and save it to a html file (download a webpage ), Bind inputText and richInputText to managed bean and craete a actionListener on button to get source

  •     // Input text Binding to get URL
        private RichInputText webPageUrlBind;
        // RickInput text Binding to set Source
        private RichTextEditor richTextBind;
        public void setWebPageUrlBind(RichInputText webPageUrlBind) {
            this.webPageUrlBind = webPageUrlBind;
        }
    
        public RichInputText getWebPageUrlBind() {
            return webPageUrlBind;
        }
    
        public void setRichTextBind(RichTextEditor richTextBind) {
            this.richTextBind = richTextBind;
        }
    
        public RichTextEditor getRichTextBind() {
            return richTextBind;
        }
        /**Method to get html source of url (webpage) and set this to rickTextEditor
         * @param actionEvent
         */
        public void getSourceCodeAction(ActionEvent actionEvent) {
            URL url = null;
    
            try {
                if (webPageUrlBind.getValue() != null) {
                    // Define your URL- Get value from input text using binding
                    url = new URL(webPageUrlBind.getValue().toString());
                }
                URLConnection conn = url.openConnection();
    
                // open the stream and put it into BufferedReader
                BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    
                String inputLine;
                String sourceCode = "";
    
                //Save html file (HTML Source Code of given URL)
                String fileName = "D:/web-content.html";
                File file = new File(fileName);
    
                if (!file.exists()) {
                    file.createNewFile();
                }
    
                //use FileWriter to write file
                FileWriter fw = new FileWriter(file.getAbsoluteFile());
                BufferedWriter bw = new BufferedWriter(fw);
                System.out.println("Printing WebPage source on console, Please wait...\n");
                while ((inputLine = br.readLine()) != null) {
                    System.out.println(inputLine);
                    bw.write(inputLine);
                    sourceCode = sourceCode.concat(inputLine);
                }
    
                bw.close();
                br.close();
                richTextBind.setValue(sourceCode);
                AdfFacesContext.getCurrentInstance().addPartialTarget(richTextBind);
                System.out.println("\n\nYour file is save in D drive! Congratulations ");
    
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
    
        }
    




  • now click on button and see , here i am getting source code of this blog http://oracleadf-java.blogspot.in/


  • now switch RichTextMode to see html preview of this source, it is exactly looking like live webpage, it shows one can practice in this ADF Faces's rickTextEditor to learn html tags


  • and see in D drive of your system a file named web-content created , it contains whole source of this webpage
 Cheers - Happy Learning :)

Thursday, 20 June 2013

Bing language Translation API integration with Java- microsoft-translator-java-api

Google Translation is very popular and widely used for language translation as it is now paid service,
so i  came to know about Microsoft Translator (Bing Translator), it is providing free API up to 2000,000 character/Month to translate.

Key features and point-
  • Provides java wrapper around microsoft translator (Bing Translator)
  • Developed as alternative of Google Translator
  • Follow coding standard, naming, functionality and usage patterns of widely used google translation API
This is very very simple to use -Follow steps




  • First Download JAR for API- http://code.google.com/p/microsoft-translator-java-api/  with all dependencies
  • Now obtain client secret key and client id in order to access API , see this http://msdn.microsoft.com/en-us/library/hh454950.aspx
  • After this create a simple java class and just write this code-
  • Don't forget to add JAR in your project's class path

  • package translation;
    
    import com.memetix.mst.language.Language;
    import com.memetix.mst.translate.Translate;
    
    public class MicrosoftTranslator {
        public static void main(String[] args) throws Exception {
            
            Translate.setClientId("secret client id");
            Translate.setClientSecret("secret key");
    
    
            String translatedText = Translate.execute("hello", Language.ENGLISH, Language.FRENCH);
            System.out.println(translatedText);
        }
    }
    

  • Enter your key and id in code, you can change language with available list, and run this code
  • To use this in web application , you must handle SSL certificate

Wednesday, 5 June 2013

Download file from url using Oracle ADF & Java- Download Manager

In this tutorial i will show you how to download a file from its url (web)-
as- http://www.tutorialspoint.com/java/java_tutorial.pdf
This will work as a simple download manager, you can add file url to download it and save it.
This tutorial makes use of FileHandling and java.net.URL class in java.

  • User Interface is very simple to design as it have only one input text and one button, so create a fusion web application , and a bounded taskflow with a page fragment in it
  • Now drag a Input text to enter url and a button to perform action on it from Componenet palette .
  • Bind input text to bean to get its value from page

  •  private RichInputText fileUrlBind;
    
        public void setFileUrlBind(RichInputText fileUrlBind) {
            this.fileUrlBind = fileUrlBind;
        }
    
        public RichInputText getFileUrlBind() {
            return fileUrlBind;
        }
    
  • Now create actionListener to managed bean and write code for downloading file from given url- see code

  •     public void DownloadFileButton(ActionEvent actionEvent) {
            try {
                if (fileUrlBind.getValue() != null) {
                    String fileUrl = fileUrlBind.getValue().toString();
                    if (fileUrl.startsWith("http://")) {
                        String msgNm = fileUrl.substring(7);
    
                        cnctmsgBind.setValue("Connecting to " + msgNm + "....");
    
                        URL url = new URL(fileUrl);
                        url.openConnection();
                        InputStream reader = url.openStream();
    
    
                        FileOutputStream writer =
                            new FileOutputStream("C:/javadrive." + fileUrl.substring(fileUrl.lastIndexOf(".")));
                        byte[] buffer = new byte[153600];
                        int totalBytesRead = 0;
                        int bytesRead = 0;
    
                       
                        dwnldMsgBind.setValue("Reading file 150KB blocks at a time");
                        while ((bytesRead = reader.read(buffer)) > 0) {
                            writer.write(buffer, 0, bytesRead);
                            buffer = new byte[153600];
                            totalBytesRead += bytesRead;
                        }
                     
                        alerMsgBind.setValue("File is downloaded successfully, look at your c drive :-)");
                        writer.close();
                        reader.close();
                    } else {
                        FacesMessage errMsg = new FacesMessage("Something went wrong");
                        errMsg.setSeverity(FacesMessage.SEVERITY_ERROR);
                        errMsg.setDetail("Example- http://www.javadrive.co.in/java.pdf");
                        FacesContext context = FacesContext.getCurrentInstance();
                        context.addMessage(fileUrlBind.getClientId(), errMsg);
                    }
                }
            } catch (MalformedURLException e) {
                FacesMessage errMsg = new FacesMessage("Something went wrong");
                errMsg.setSeverity(FacesMessage.SEVERITY_ERROR);
                FacesContext context = FacesContext.getCurrentInstance();
                context.addMessage(null, errMsg);
                e.printStackTrace();
            } catch (IOException e) {
                FacesMessage errMsg = new FacesMessage("Something went wrong");
                errMsg.setSeverity(FacesMessage.SEVERITY_ERROR);
                FacesContext context = FacesContext.getCurrentInstance();
                context.addMessage(null, errMsg);
                e.printStackTrace();
            }
    
    
        }
    
    




  • Now Run your application and see downloaded file in your c drive as path is hard coded in bean


  •  See your downloaded file in c drive


Tuesday, 4 June 2013

Fun - Develop Tic Tac Toe game in Oracle ADF/Java

Tic Tac Toe or Naughty Cross is a paper-pencil game for two players and simple in  concept.
I have developed a application on ADF, using JSF page and unbounded adfc-config.xml .
There is nothing to explain, see the sample application at bottom of this post
  • Tic Tac Toe game has 9 square to enter values 0 or X, so for that i have used 9 buttons and images of 0 and X



  • And create a managed bean for all nine buttons, to execute proper conditions for each move
     
  • See managed bean code and conditions for player's move(only Java Code is needed to do this)



  • package ticTacToeADF.view;
    
    import javax.faces.event.ActionEvent;
    
    import oracle.adf.view.rich.component.rich.nav.RichCommandButton;
    
    public class TictactoeBean {
    
        public TictactoeBean() {
        }
        private static String one = "     ";
        private static String two = "     ";
        private static String three = "     ";
        private static String four = "     ";
        private static String five = "     ";
        private static String six = "     ";
        private static String seven = "     ";
        private static String eight = "     ";
        private static String nine = "     ";
        private static boolean check = false;
        private String Result = "";
        private static boolean oneDis = false;
        private static boolean twoDis = false;
        private static boolean threeDis = false;
        private static boolean fourDis = false;
        private static boolean fiveDis = false;
        private static boolean sixDis = false;
        private static boolean sevenDis = false;
        private static boolean eightDis = false;
        private static boolean nineDis = false;
    
    
        public void Button1(ActionEvent actionEvent) {
            if (check == false) {
                this.setOne("X");
    
                check = true;
                this.setOneDis(true);
                System.out.println("Check is--------->" + check);
                if (one.equalsIgnoreCase(two) && two.equalsIgnoreCase(three)) {
                    this.setResult(one + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (one.equalsIgnoreCase(five) && five.equalsIgnoreCase(nine)) {
                    this.setResult(one + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (one.equalsIgnoreCase(four) && four.equalsIgnoreCase(seven)) {
                    this.setResult(one + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
    
    
            } else {
                this.setOne("0");
    
                check = false;
                this.setOneDis(true);
                System.out.println("Check is--------->" + check);
                if (one.equalsIgnoreCase(two) && two.equalsIgnoreCase(three)) {
                    this.setResult(one + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (one.equalsIgnoreCase(five) && five.equalsIgnoreCase(nine)) {
                    this.setResult(one + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (one.equalsIgnoreCase(four) && four.equalsIgnoreCase(seven)) {
                    this.setResult(one + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
    
            }
    
        }
    
        public void Button2(ActionEvent actionEvent) {
            if (check == false) {
                this.setTwo("X");
                check = true;
                this.setTwoDis(true);
                System.out.println("Check is--------->" + check);
                if (two.equalsIgnoreCase(five) && five.equalsIgnoreCase(eight)) {
                    this.setResult(two + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (two.equalsIgnoreCase(one) && one.equalsIgnoreCase(three)) {
                    this.setResult(two + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            } else {
                this.setTwo("0");
                check = false;
                this.setTwoDis(true);
                System.out.println("Check is--------->" + check);
                if (two.equalsIgnoreCase(five) && five.equalsIgnoreCase(eight)) {
                    this.setResult(two + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (two.equalsIgnoreCase(one) && one.equalsIgnoreCase(three)) {
                    this.setResult(two + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            }
        }
    
        public void Button3(ActionEvent actionEvent) {
            if (check == false) {
                this.setThree("X");
                check = true;
                this.setThreeDis(true);
                System.out.println("Check is--------->" + check);
    
                if (three.equalsIgnoreCase(six) && six.equalsIgnoreCase(nine)) {
                    this.setResult(three + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (three.equalsIgnoreCase(five) && five.equalsIgnoreCase(seven)) {
                    this.setResult(three + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (three.equalsIgnoreCase(one) && one.equalsIgnoreCase(two)) {
                    this.setResult(three + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
    
            } else {
                this.setThree("0");
                check = false;
                this.setThreeDis(true);
                System.out.println("Check is--------->" + check);
    
                if (three.equalsIgnoreCase(six) && six.equalsIgnoreCase(nine)) {
                    this.setResult(three + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (three.equalsIgnoreCase(five) && five.equalsIgnoreCase(seven)) {
                    this.setResult(three + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (three.equalsIgnoreCase(one) && one.equalsIgnoreCase(two)) {
                    this.setResult(three + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            }
        }
    
        public void Button4(ActionEvent actionEvent) {
            if (check == false) {
                this.setFour("X");
                check = true;
                this.setFourDis(true);
                System.out.println("Check is--------->" + check);
    
                if (four.equalsIgnoreCase(one) && one.equalsIgnoreCase(seven)) {
                    this.setResult(four + " wins");
                    finishgame();
                    System.out.println("four wins");
                } else if (four.equalsIgnoreCase(five) && five.equalsIgnoreCase(six)) {
                    this.setResult(four + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
    
            } else {
                this.setFour("0");
                check = false;
                this.setFourDis(true);
                System.out.println("Check is--------->" + check);
    
                if (four.equalsIgnoreCase(one) && one.equalsIgnoreCase(seven)) {
                    this.setResult(four + " wins");
                    finishgame();
                    System.out.println("four wins");
                } else if (four.equalsIgnoreCase(five) && five.equalsIgnoreCase(six)) {
                    this.setResult(four + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            }
        }
    
        public void Button5(ActionEvent actionEvent) {
            if (check == false) {
                this.setFive("X");
                check = true;
                this.setFiveDis(true);
                System.out.println("Check is--------->" + check);
    
                if (one.equalsIgnoreCase(five) && five.equalsIgnoreCase(nine)) {
                    this.setResult(five + " wins");
                    finishgame();
                    System.out.println("One wins");
    
                } else if (two.equalsIgnoreCase(five) && five.equalsIgnoreCase(eight)) {
                    this.setResult(five + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
    
                else if (four.equalsIgnoreCase(five) && five.equalsIgnoreCase(six)) {
                    this.setResult(five + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (five.equalsIgnoreCase(three) && three.equalsIgnoreCase(seven)) {
                    this.setResult(five + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            } else {
                this.setFive("0");
                check = false;
                this.setFiveDis(true);
                System.out.println("Check is--------->" + check);
    
                if (one.equalsIgnoreCase(five) && five.equalsIgnoreCase(nine)) {
                    this.setResult(five + " wins");
                    finishgame();
                    System.out.println("One wins");
    
                } else if (two.equalsIgnoreCase(five) && five.equalsIgnoreCase(eight)) {
                    this.setResult(five + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
    
                else if (four.equalsIgnoreCase(five) && five.equalsIgnoreCase(six)) {
                    this.setResult(five + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (five.equalsIgnoreCase(three) && three.equalsIgnoreCase(seven)) {
                    this.setResult(five + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
    
            }
        }
    
        public void Button6(ActionEvent actionEvent) {
            if (check == false) {
                this.setSix("X");
                check = true;
                this.setSixDis(true);
                System.out.println("Check is--------->" + check);
    
                if (four.equalsIgnoreCase(five) && five.equalsIgnoreCase(six)) {
                    this.setResult(six + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (three.equalsIgnoreCase(six) && six.equalsIgnoreCase(nine)) {
                    this.setResult(six + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            } else {
                this.setSix("0");
                check = false;
                this.setSixDis(true);
                System.out.println("Check is--------->" + check);
    
                if (four.equalsIgnoreCase(five) && five.equalsIgnoreCase(six)) {
                    this.setResult(six + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (three.equalsIgnoreCase(six) && six.equalsIgnoreCase(nine)) {
                    this.setResult(six + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            }
        }
    
        public void Button7(ActionEvent actionEvent) {
            if (check == false) {
                this.setSeven("X");
                check = true;
                this.setSevenDis(true);
                System.out.println("Check is--------->" + check);
    
                if (four.equalsIgnoreCase(one) && one.equalsIgnoreCase(seven)) {
                    this.setResult(four + " wins");
                    finishgame();
                    System.out.println("four wins");
                } else if (five.equalsIgnoreCase(three) && three.equalsIgnoreCase(seven)) {
                    this.setResult(seven + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (seven.equalsIgnoreCase(eight) && eight.equalsIgnoreCase(nine)) {
                    this.setResult(seven + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            } else {
                this.setSeven("0");
                check = false;
                this.setSevenDis(true);
                System.out.println("Check is--------->" + check);
                if (four.equalsIgnoreCase(one) && one.equalsIgnoreCase(seven)) {
                    this.setResult(four + " wins");
                    finishgame();
                    System.out.println("four wins");
                } else if (five.equalsIgnoreCase(three) && three.equalsIgnoreCase(seven)) {
                    this.setResult(seven + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (seven.equalsIgnoreCase(eight) && eight.equalsIgnoreCase(nine)) {
                    this.setResult(seven + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            }
        }
    
        public void Button8(ActionEvent actionEvent) {
            if (check == false) {
                this.setEight("X");
                check = true;
                this.setEightDis(true);
                System.out.println("Check is--------->" + check);
                if (eight.equalsIgnoreCase(two) && two.equalsIgnoreCase(five)) {
                    this.setResult(eight + " wins");
                    finishgame();
                    System.out.println("four wins");
                } else if (eight.equalsIgnoreCase(seven) && seven.equalsIgnoreCase(nine)) {
                    this.setResult(eight + " wins");
                    finishgame();
                    System.out.println("One wins");
    
                }
            } else {
                this.setEight("0");
                check = false;
                this.setEightDis(true);
                System.out.println("Check is--------->" + check);
                if (eight.equalsIgnoreCase(two) && two.equalsIgnoreCase(five)) {
                    this.setResult(eight + " wins");
                    finishgame();
                    System.out.println("four wins");
                } else if (eight.equalsIgnoreCase(seven) && seven.equalsIgnoreCase(nine)) {
                    this.setResult(eight + " wins");
                    finishgame();
                    System.out.println("One wins");
    
                }
            }
        }
    
        public void Button9(ActionEvent actionEvent) {
            if (check == false) {
                this.setNine("X");
                check = true;
                this.setNineDis(true);
                System.out.println("Check is--------->" + check);
                if (nine.equalsIgnoreCase(one) && one.equalsIgnoreCase(five)) {
                    this.setResult(nine + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (three.equalsIgnoreCase(six) && six.equalsIgnoreCase(nine)) {
                    this.setResult(six + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (eight.equalsIgnoreCase(seven) && seven.equalsIgnoreCase(nine)) {
                    this.setResult(eight + " wins");
                    finishgame();
                    System.out.println("One wins");
    
                }
            } else {
                this.setNine("0");
                check = false;
                this.setNineDis(true);
                System.out.println("Check is--------->" + check);
    
                if (nine.equalsIgnoreCase(one) && one.equalsIgnoreCase(five)) {
                    this.setResult(nine + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (three.equalsIgnoreCase(six) && six.equalsIgnoreCase(nine)) {
                    this.setResult(six + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (eight.equalsIgnoreCase(seven) && seven.equalsIgnoreCase(nine)) {
                    this.setResult(eight + " wins");
                    finishgame();
                    System.out.println("One wins");
    
                }
            }
        }
    
        public void setOne(String one) {
            this.one = one;
        }
    
        public String getOne() {
            return one;
        }
    
        public void setTwo(String two) {
            this.two = two;
        }
    
        public String getTwo() {
            return two;
        }
    
        public void setThree(String three) {
            this.three = three;
        }
    
        public String getThree() {
            return three;
        }
    
        public void setFour(String four) {
            this.four = four;
        }
    
        public String getFour() {
            return four;
        }
    
        public void setFive(String five) {
            this.five = five;
        }
    
        public String getFive() {
            return five;
        }
    
        public void setSix(String six) {
            this.six = six;
        }
    
        public String getSix() {
            return six;
        }
    
        public void setSeven(String seven) {
            this.seven = seven;
        }
    
        public String getSeven() {
            return seven;
        }
    
        public void setEight(String eight) {
            this.eight = eight;
        }
    
        public String getEight() {
            return eight;
        }
    
        public void setNine(String nine) {
            this.nine = nine;
        }
    
        public String getNine() {
            return nine;
        }
    
        public void setResult(String Result) {
            this.Result = Result;
        }
    
        public String getResult() {
            return Result;
        }
    
        public void ResetButton(ActionEvent actionEvent) {
            this.one = "     ";
            this.two = "     ";
            this.three = "     ";
            this.four = "     ";
            this.five = "     ";
            this.six = "     ";
            this.seven = "     ";
            this.eight = "     ";
            this.nine = "     ";
            this.check = false;
            this.oneDis = false;
            this.twoDis = false;
            this.threeDis = false;
            this.fourDis = false;
            this.fiveDis = false;
            this.sixDis = false;
            this.sevenDis = false;
            this.eightDis = false;
            this.nineDis = false;
    
        }
    
        public void finishgame() {
            this.oneDis = true;
            this.twoDis = true;
            this.threeDis = true;
            this.fourDis = true;
            this.fiveDis = true;
            this.sixDis = true;
            this.sevenDis = true;
            this.eightDis = true;
            this.nineDis = true;
        }
    
        public void setOneDis(boolean oneDis) {
            this.oneDis = oneDis;
        }
    
        public boolean isOneDis() {
            return oneDis;
        }
    
        public void setTwoDis(boolean twoDis) {
            this.twoDis = twoDis;
        }
    
        public boolean isTwoDis() {
            return twoDis;
        }
    
        public void setThreeDis(boolean threeDis) {
            this.threeDis = threeDis;
        }
    
        public boolean isThreeDis() {
            return threeDis;
        }
    
        public void setFourDis(boolean fourDis) {
            this.fourDis = fourDis;
        }
    
        public boolean isFourDis() {
            return fourDis;
        }
    
        public void setFiveDis(boolean fiveDis) {
            this.fiveDis = fiveDis;
        }
    
        public boolean isFiveDis() {
            return fiveDis;
        }
    
        public void setSixDis(boolean sixDis) {
            this.sixDis = sixDis;
        }
    
        public boolean isSixDis() {
            return sixDis;
        }
    
        public void setSevenDis(boolean sevenDis) {
            this.sevenDis = sevenDis;
        }
    
        public boolean isSevenDis() {
            return sevenDis;
        }
    
        public void setEightDis(boolean eightDis) {
            this.eightDis = eightDis;
        }
    
        public boolean isEightDis() {
            return eightDis;
        }
    
        public void setNineDis(boolean nineDis) {
            this.nineDis = nineDis;
        }
    
        public boolean isNineDis() {
            return nineDis;
        }
    
    
    }
    

  • Download and Run this sample application-Sample ADF Application