JavaTutorial #13 : How to create Donate Page (USD, STEEM, SBD) in Java Aplication using Netbeans IDE

in #utopian-io5 years ago

Repository

https://github.com/dmlloyd/openjdk

What Will I Learn?

  • You will learn about steemconnect link to transfer SBD and STEEM
  • You will learn about Paypal link to transfer USD
  • You will learn how to create form for this application
  • You will learn how to combine data from the form to the link

Requirements

  • NetBeans IDE Software
  • Basic Knowledge about Java Programing and Netbeans

Difficulty

  • Basic

Tutorial Contents

In an application, a programmer usually provides a page for donations. Usually they use USD, Bitcoin, Etherium or other currencies. Here I will try to make a donation page for java application using USD, STEEM and SBD. for STEEM and SBD, I use steemconnect. As for USD, use Paypal. I hope this becomes a reference for those of you who are java language programmers.
Screen Shot 2018-11-10 at 15.48.23.png

Directly, Lets follow steps bellow to create this application :

Create a form
  • Open your Netbeans IDE and create new project
    Screen Shot 2018-11-10 at 14.53.24.png
    Screen Shot 2018-11-10 at 14.53.52.png

  • Delete donate.java class and create new JFrameForm
    Screen Shot 2018-11-10 at 14.54.19.png
    Screen Shot 2018-11-10 at 14.54.32.png

Design the Form
  • Add jLabel for the title
    Screen Shot 2018-11-10 at 14.56.19.png

  • Add TabbedPane to create donation tabs
    Screen Shot 2018-11-10 at 14.56.40.png

  • Add 3 panel on TabbedPane, For USD, STEEM and SBD donation
    Screen Shot 2018-11-10 at 14.57.19.png
    Screen Shot 2018-11-10 at 14.57.43.png

  • Create form for tab1, tab2, and tab3. Tab1 for USD, Tab2 for STEEM and tab3 for SBD. The form contain 2 textfield and 1 button, like image bellow :
    Screen Shot 2018-11-10 at 15.04.17.png

  • Rename the textfield and button with different variable name. You can see my variable
    Screen Shot 2018-11-10 at 16.15.34.png

Edit Source Code
  • open donate usd tab on design and double click on send button until appear like image bellow then add some method
    Screen Shot 2018-11-10 at 15.13.58.png

  • Right click on hint simbol on left side on code and click on add donateUsd method

  • Go to donateUSD() method and add the code bellow :

        String usdR=usdReceiver.getText();
        String usd=usdAmount.getText();
        final JFrame frame=new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(1280,720);
        final JFXPanel fxpanel=new JFXPanel();
        frame.add(fxpanel);
        Platform.runLater(new Runnable(){
            @Override
            public void run() {
                WebEngine engine;
                WebView wv =new WebView();
                engine=wv.getEngine();
                fxpanel.setScene(new Scene(wv));
                engine.load("https://www.paypal.me/"+usdR+"/"+usd+"USD");         
            }
        });
        frame.setVisible(true);


CodeExplanation
usdReceiver.getText()get text from receiver textfield
usdAmount.getText()get text from amount textfield
framethe variable name for new JFrame. You need to import package javax.swing.JFrame for using JFrame
setDefaultCloseOperationmethod to set the the exit button on right-top corner
setSize()method to set the width and height of the new frame
final JFXPanel fxpanel=new JFXPanel()Initialize new JFX panel
frame.add(fxpanel)add JfxPanel to JFrame
Platform.runLatermethod to run some task on JFXpanel
@Overrideto implement all abstract method
WebEngine engineInizialize web engine
WebView wv =new WebView()Inizialize new web view
engine=wv.getEngine()get view from web engine
fxpanel.setScene(new Scene(wv))set scene on JFXpanel
engine.loadload some url
https://www.paypal.me/"+usdR+"/"+usd+"USDPaypal.me link to get USD. Here we costume it with receiver and amount in input from form.
  • Now go to donate steem tab and double click on send button and add donateSteem() method then add this code in that method, like this :
private void donateSteem() {
        String steemR=steemReceiver.getText();
        String steem=steemAmount.getText();
        final JFrame frame=new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(1280,720);
        final JFXPanel fxpanel=new JFXPanel();
        frame.add(fxpanel);
        Platform.runLater(new Runnable(){
            @Override
            public void run() {
                WebEngine engine;
                WebView wv =new WebView();
                engine=wv.getEngine();
                fxpanel.setScene(new Scene(wv));
                engine.load("https://steemconnect.com/sign/transfer?from=you&to="+steemR+"&amount="+steem+"%20STEEM&memo=Donations");         
            }
        });
        frame.setVisible(true);
    }


CodeExplanation
steemReceiver.getText()get text from receiver textfield for STEEM
steemAmount.getText()get text from amount textfield for STEEM
https://steemconnect.com/sign/transfer?from=you&to="+steemR+"&amount="+steem+"%20STEEM&memo=Donationssteemconnect link for transferring STEEM to another account. here I costume the link for the to and amount value are from the user input and I set Donations for memo value.
  • Last one go to Donate SBD tab then do as you do on Donate SBD tab. and add the code bellow in donateSBD() method :
        String sbdR=sbdReceiver.getText();
        String sbd=sbdAmount.getText();
        final JFrame frame=new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(1280,720);
        final JFXPanel fxpanel=new JFXPanel();
        frame.add(fxpanel);
        Platform.runLater(new Runnable(){
            @Override
            public void run() {
                WebEngine engine;
                WebView wv =new WebView();
                engine=wv.getEngine();
                fxpanel.setScene(new Scene(wv));
                engine.load("https://steemconnect.com/sign/transfer?from=you&to="+sbdR+"&amount="+sbd+"%20SBD&memo=Donations");         
            }
        });
        frame.setVisible(true);


CodeExplanation
sbdReceiver.getText()get text from receiver textfield for SBD
sbdAmount.getText()get text from amount textfield for SBD
https://steemconnect.com/sign/transfer?from=you&to="+steemR+"&amount="+steem+"%20SBD&memo=Donationssteemconnect link for transferring SBD to another account. here I costume the link for the to and amount value are from the user input and I set Donations for memo value.
Testing and Running the App

save and run the project

  • Donate USD
    Screen Shot 2018-11-10 at 17.45.25.png
    Screen Shot 2018-11-10 at 17.45.58.png

  • Donate Steem
    Screen Shot 2018-11-10 at 17.48.53.png
    Screen Shot 2018-11-10 at 17.49.19.png

  • Donate SBD
    Screen Shot 2018-11-10 at 17.50.10.png
    Screen Shot 2018-11-10 at 17.50.28.png

Curriculum

Proof of Work Done

https://gist.github.com/team2dev/464e6f51fc8a291cdb320045605f979f

Sort:  

Thank you for your contribution @team2dev.
Below are the points we suggest for improvements to your tutorial:

  • We suggest you explain in more detail in your tutorial. It is important to have theory about what you are developing.

  • In code it is very important to have comments explaining what certain lines of code do. For the reader it facilitates the interpretation of the code that is developing.

  • Improve the structure of the tutorial.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you for your review, @portugalcoin! Keep up the good work!

Hi @team2dev!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @team2dev!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.28
TRX 0.11
JST 0.034
BTC 66077.75
ETH 3167.77
USDT 1.00
SBD 4.01