Page 135 - 24JAM_Pintar_Pemrograman_Android__1-libre
P. 135
24 JAM!! Pintar Pemrograman Android
16: import android.widget.ImageButton;
17: import android.widget.TextView;
18:
19: public class hargaDiskon extends Activity {
20: EditText harga, diskon;
21: TextView hargabaru, hmt;
22: Editable isiharga, isidiskon;
23: Button reset;
24: ImageButton htng;
25: String sharga, sdiskon;
26:
27: /** Called when the activity is first created. */
28: @Override
29: public void onCreate(Bundle savedInstanceState) {
30: super.onCreate(savedInstanceState);
31: setContentView(R.layout.main);
32:
33: hargabaru = (TextView) findViewById(R.id.hasil);
34: harga = (EditText) findViewById(R.id.harga);
35: diskon = (EditText) findViewById(R.id.diskon);
36: hmt = (TextView) findViewById(R.id.hemat);
37: reset = (Button) findViewById(R.id.reset);
38: reset.setOnClickListener(new reset());
39: htng = (ImageButton) findViewById(R.id.imageButton1);
40: htng.setOnClickListener(new itung());
41:
42: }
43:
44: private class itung implements OnClickListener {
45: public void onClick(View v) {
46: try {
47: Double h =
48: Double.parseDouble(harga.getText().toString());
49: Double d =
50: Double.parseDouble(diskon.getText().toString());
51: Double nd = (d / 100) * h;
52: double hsl = h - nd;
53: Number irit = h - hsl;
54: DecimalFormat df = new DecimalFormat("@@##");
55: hargabaru.setText("Rp." + df.format(hsl) + ",00");
56: hmt.setText("Wow!! Kamu Hemat Rp."
57: + df.format(irit) + " !!");
58: } catch (Exception e) {
59: };
60: }
61: }
62:
63: public class reset implements OnClickListener {
64: public void onClick(View v) {
65: hargabaru.setText("");
66: harga.setText("");
67: diskon.setText("");
68: hmt.setText("");
69: }
70: }
71:
72: public boolean onCreateOptionsMenu(Menu menu) {
73: super.onCreateOptionsMenu(menu);
74: menu.add(0, 0, 0, "Tutorial");
75: menu.add(0, 1, 0, "Info");
76: menu.add(0, 2, 0, "Keluar");
77: return true;
78: }
79:
80: public boolean onOptionsItemSelected(MenuItem item) {
81:
Dapatkan materi terbaru di 135
www.omayib.com

