Penjumlahan Integer

Ganti nama variable komponen  Klik kanan –> Change variable name

Menangani penekanan tombol button Events > Action > actionPerformed

code:

 public Penjumlahan() {
initComponents();
}
private String str = “Hasilnya adalah : “;
private int a,  b;

=================================================

private void btnHitungActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
a = Integer.parseInt(txtA.getText());
b = Integer.parseInt(txtB.getText());
int hasil = a + b;
lblHasil.setText(str + hasil);
}

 

** JLabel dan JTextField mempunyai method getText dan setText untuk mengambil dan mengeset text yang ditampilkan.

 

Java Middlet notes

 

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class awal extends MIDlet
implements CommandListener {
Form     f;
Command cmdOK;

public awal() {
f = new Form(“Kursus J2ME Malam”);
try {
Image img = Image.createImage(“/logo.png”);
f.append(img);
} catch(Exception e) {
System.out.println(e);
}
f.append(“\nKursus Malam”);
f.append(“\nPanas Cuuuyyyy”);
f.append(“\nKaga Pake AC”);

Ticker t = new Ticker(
“selamat Datang “+
“di Lab Aplikasi & Pemrograman” );
f.setTicker(t);

cmdOK=new Command(“OK”,Command.OK,1);

f.addCommand(cmdOK);
f.setCommandListener(this);
}
public void startApp() {
Display d = Display.getDisplay(this);
d.setCurrent(f);
}
public void pauseApp() { }
public void destroyApp(boolean b) { }

public void commandAction(Command c,
Displayable d ) {
if(c==cmdOK) {
notifyDestroyed();
}
}
}