AIbridge 라이브러리 간단한 적금앱, tinyDB 사용해서 간단하게 저장, 불러오기

라이브러리를 추가 해주기
http://www.appinventor.org/content/java-bridge/introduction/intro-android-studio <- 다운로드 위치




// you need the following imports in all Java Bridge apps

//저의 깃헙 주소 : https://github.com/ndgndg91import com.google.appinventor.components.runtime.Button;
import com.google.appinventor.components.runtime.Component;
import com.google.appinventor.components.runtime.EventDispatcher;
import com.google.appinventor.components.runtime.Form;
import com.google.appinventor.components.runtime.HandlesEventDispatching;
import com.google.appinventor.components.runtime.HorizontalArrangement;
import com.google.appinventor.components.runtime.Label;
import com.google.appinventor.components.runtime.ListPicker;
import com.google.appinventor.components.runtime.TextBox;
import com.google.appinventor.components.runtime.TinyDB;

import java.util.regex.*;


// import any components you are going to use in your app. In this case, just Button
// you can use the following header for all appspublic class MainActivity extends Form implements HandlesEventDispatching
{

    // declare all your components as instance variables    private Label Label1,Label2,Label3,Label4;
    private Button calculation, savebutton;
    private TextBox tb1,tb2,tb3,tb4;
    private double amount, times;
    private double interest;
    private double totalamount;
    private String value;
    private TinyDB tinyDB;

    protected void $define()
    {
        // create the button component        this.ScreenOrientation("portrait");
        this.Title("Calculation");
        this.BackgroundColor(COLOR_WHITE);
        this.Scrollable(true);
        tinyDB = new TinyDB(this);
        Label1 = new Label(this); Label1.Text("월 적금액 입력하시오");
        tb1 = new TextBox(this); tb1.Width(480);
        Label2 = new Label(this); Label2.Text("적금 횟수(개월수)");
        tb2 = new TextBox(this); tb2.Width(480);
        Label3 = new Label(this); Label3.Text("복리 년 이자율 %");
        tb3 = new TextBox(this); tb3.Width(480);
        calculation = new Button(this); calculation.Text("만기 수령액 계산");
        Label4 = new Label(this); Label4.Text("적금 만기시 수령하는 총액");
        tb4 = new TextBox(this); tb4.Width(480);
        savebutton = new Button(this); savebutton.Text("데이터저장");
        try {
            tb1.Text(String.valueOf(tinyDB.GetValue("amount", "")));
            tb2.Text(String.valueOf(tinyDB.GetValue("times", "")));
            tb3.Text(String.valueOf(tinyDB.GetValue("interest", "")));
            tb4.Text(String.valueOf(tinyDB.GetValue("totalamount", "")));
        }
        catch (Exception e){

        }
        EventDispatcher.registerEventForDelegation( this, "ButtonClick", "Click" );
    }
    public boolean dispatchEvent(Component component, String componentName, String eventName, Object[] params )
    {
        if (component.equals(calculation) && eventName.equals("Click")) {
            Calculating();
            return true;
        }
        if (component.equals(savebutton) && eventName.equals("Click")) {
            Storevalue();
            return true;
        }

        return false;
    }


    public void Calculating(){
        amount = Double.parseDouble(tb1.Text());
        times = Double.parseDouble(tb2.Text());
        interest = Double.parseDouble(tb3.Text());
        for(int i =0; i<times; i++){
            totalamount = amount + totalamount*(1+interest/1200);
        }
        value = String.valueOf(totalamount);
        tb4.Text(value);
    }
    public void Storevalue(){
        tinyDB.StoreValue("amount",String.valueOf(amount));
        tinyDB.StoreValue("times",String.valueOf(times));
        tinyDB.StoreValue("interest",String.valueOf(interest));
        tinyDB.StoreValue("totalamount",String.valueOf(totalamount));
    }
}

댓글

이 블로그의 인기 게시물

Spring Boot Actuator readiness, liveness probes on k8s

About Kafka Basic

sneak peek jitpack

About idempotent

About G1 GC

About ZGC

About JVM Warm up

I need to know a little JVM

HackerRank Java Between Two Sets

Java - HashMap (feat. LinkedList, Tree.. maybe Later)