JavaTutorial #11 : How to create Delegating SP aplication using java Netbeans IDE

Words
426
Reading
2 min
Listen
Play
8y

Repository

https://github.com/dmlloyd/openjdk

What Will I Learn?

  • You will learn about steemconnect link for delegating SP
  • You will learn how to create form for this aplication
  • You will learn how to combine data from the form in steemconnect link

Requirements

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

Difficulty

  • Basic

Tutorial Contents

Here, I will try to create an aplication for delegating SP to another user using java Netbeans IDE. This aplication contains a form to input the destination and number of SP to be delegated. When user press the delegate button, a new window will appear where the user is that required to login using steemconnect. For more details, you can see in the picture below.


Create a form
  • open Netbeans IDE software then create new project

  • Add new JFrame Form

  • Add JLabel, JTextField, JButton like following screenshot

Edit Source Code
  • Double click on button in form design

  • add some method, here I use delegate() method.

  • Left Click on hint simbol then double click on create method "delegate"

  • go to delegate() method

Adding code to delegate() method
  • Create 2 string variables to accomodate destination and amount delegation from user input.
String receiveUser=user.getText();
String sp=amount.getText();

getText() is a method to get text from user input. Data that taken using getText() mehtod are in String form

  • Add a code to open new JFrame Form for opening steemconnect login
        final JFrame frame=new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(1280,720);

frame the variable name for new JFrame. setDefaultCloseOperation is method to set the the exit button on right-top corner. setSize() is method to set the width and height of the new frame

Note : before adding the code above, you need to import package javax.swing.JFrame;

  • Initialize new JFX panel to open the mini browser
        final JFXPanel fxpanel=new JFXPanel();
        frame.add(fxpanel);
  • Then add following code under it
        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/delegateVestingShares?delegator=&delegatee="+receiveUser+"&vesting_shares="+sp+"%20SP");         
            }
        });
        frame.setVisible(true);

Platform.runLater is method to run some task on JFXpanel
@Override to implement all abstract method
public void run() is run method.
WebEngine engine; Inisialize web engine
WebView wv =new WebView(); inssialize web view
engine=wv.getEngine();get view from web engine
fxpanel.setScene(new Scene(wv));set scene on JFXpanel
engine.load("https://steemconnect.com/sign/delegateVestingShares?delegator=&delegatee="+receiveUser+"&vesting_shares="+sp+"%20SP"); load the url

Modify Steemconnect URL
  • Here we need steemconnect URL, and this url we need to modify. steemconnect URL for delegating steem power : https://steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=[UserDestination]&vesting_shares=0%[amount]SP

  • We modify [UserDestination] and [amount] as variable that get data from user input. So the RL become like this : "https://steemconnect.com/sign/delegateVestingShares?delegator=&delegatee="+receiveUser+"&vesting_shares="+sp+"%20SP"

Running aplication

Save the project and Click the play button to run the project


Curriculum

Proof of Work Done

https://gist.github.com/team2dev/cad5b352ce9d51725d83008e91b72ebc

JavaTutorial #11 : How to create Delegating SP aplication using ja... | Ecency