Mengenal Bahasa Pemerograman JAVA (2) : “Membuat Program dengan Input GUI”

import javax.swing.*; //meng-import semua class javax.swing (GUI) kedalam program
public class GUI_LuasKeliLingkaran{
public static void main(String args[]){
String type=JOptionPane.showInputDialog(“Masukan Nilai Jari-jari!”); //sintax untuk menampilkan dialog input
int jari=Integer.parseInt(type); //merubah tipe data String ke integer (variable “type” yg bertipe String berubah menjadi variable “jari” bertipe data integer)
double luas=3.14*jari*jari;
double kel=2*(3.14*jari);
JOptionPane.showMessageDialog(null,”Luas = 3.14 x “+jari+” x “+jari+” = “+luas,”info”,JOptionPane.INFORMATION_MESSAGE); //menampilkan dialog output 
JOptionPane.showMessageDialog(null,”Keliling = 2 x (3.14 x “+jari+”)=”+kel,”info”,JOptionPane.INFORMATION_MESSAGE);
System.exit(0); //akhir program
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s