0% found this document useful (0 votes)
42 views5 pages

BP1 M2 Tugas Gani Applet

The document describes code for two Java applets: 1. An arithmetic calculator applet that allows users to perform basic math operations like addition, subtraction, multiplication, and division. 2. An animation applet that loads an airplane image and uses a for loop to draw the image across the screen at intervals to create a simple animation effect.

Uploaded by

Gani Rivadri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views5 pages

BP1 M2 Tugas Gani Applet

The document describes code for two Java applets: 1. An arithmetic calculator applet that allows users to perform basic math operations like addition, subtraction, multiplication, and division. 2. An animation applet that loads an airplane image and uses a for loop to draw the image across the screen at intervals to create a simple animation effect.

Uploaded by

Gani Rivadri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Nama:GaniRi

vadr
i

Ni
m :20210810116

Kel
as:TI
NFC-
2021-
03

TugasModul2

 Buatf
il
eappletbarudengannama
BP1_M2_Tugas1_Nama_AppletePer
hit
unganPer
hit
unganAri
tmati
ka
yangt
erdi
ridari(
Penjuml
ahan,Pengur
angan,Per
kal
ian,Pembagi
an)

public class BP1_M2_tugas1_gani_AppletePerhitungan extends


Applet{

Label LabelTombol;

boolean DigitAwal = true;

float Temp = 0.0f;

String operator = "="

public void init () {

setLayout (new BorderLayout ());

add ("North", LabelTombol = new Label ("O ",


Label.RIGHT) );

LabelTombol.setForeground
(Color.red) ;

Panel p = new Panel ();

p.setLayout (new GridLayout (4, 4)


);

p.setForeground (Color.blue) ;

Tombol (p, "789/") ;

Tombol1 (p, "456*") ;

Tombol (p, "123 -") ;

Tombol (p, " .0=+") ;


add ("Center", p); }

public void hitung (String s) {

float nilai = new Float (s) .intValue ();

char c = operator.charAt (0);

switch (c) {

case '=' :

Temp = nilai;

break;

case '+' :

Temp += nilai;

break;

case '-' :

Temp -= nilai;

break;

case '*' :

Temp *= nilai;

break;

case '/' :

Temp /= nilai;

break; }

LabelTombol.setText (String.valueOf(Temp));

public void Tombol (Panel p, String


strTombol) {

int jumlah :
strTombol.length();
for (int i-0; icjumlah; i++) {

But ton b = new Button

strTombol.oubstring (i, i+1));

b.addactionListener(new
AppletKalkulator. PenanganTombol ());

p.add (b);

class PenanganTombol inplements


ActionListener {

public void actionPerformed (ActionEvent


e) {

string s = e.getactioncommand ();

if (0123456789.". indexof (s)!=-1) {

if (DigitAwal) {

DigitAwal = false;

LabelTombol.setText (s);

} else {

LabelTombol.setText
(LabelTombol.getText () +s);

else {

if (!DigitAwal) {

hitung (Labelfombol.getText ());

DigitAmal = true;

operator = s;

}
}

}
 Buatf
il
eappl
etbarudengannama
BP1_M2_Tugas2_Nama_Appl
eteAni
masiBuatdengankr
easianda

public class BP1_M2_Tugas_gani_AppletAnimation extends


Applet {

public void init()

setSize (1200, 800);

public void paint (Graphics g)

int x, y;

Image img = getImage (getCodeBase (),


"airplane3.gif");

for (x-0;x<800;x++)

g.drawImage (img, x, 0, null);

try{

Thread.sleep(20);

catch (InterruptedException ie)

You might also like