- Pertama buka notepad
- Masukan codingan seperti ini :
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
class coba{
static double a = 0;
static double b = 0;
static double c = 0;
public static void main(String[] arg){
final JFrame jendela = new JFrame();
jendela.setTitle("Rumus Segitiga");
jendela.setSize(300,300);
jendela.setVisible(true);
jendela.setLayout(null);
jendela.setDefaultCloseOperation(2);
JLabel labelx = new JLabel();
labelx.setText("Created by HamiPragusti ^_^");
labelx.setSize(200,20);
labelx.setLocation(100,220);
JLabel labelA = new JLabel();
labelA.setText("Nilai Alas :");
labelA.setSize(100,20);
labelA.setLocation(10,10);
JLabel labelB = new JLabel();
labelB.setText("Nilai Tinggi :");
labelB.setSize(100,20);
labelB.setLocation(10,30);
JLabel labelC = new JLabel();
labelC.setText("Nilai Miring :");
labelC.setSize(100,20);
labelC.setLocation(10,50);
final JTextField inputA = new JTextField();
inputA.setColumns(20);
inputA.setLocation(120,10);
inputA.setSize(70,20);
final JTextField inputB = new JTextField();
inputB.setColumns(20);
inputB.setLocation(120,30);
inputB.setSize(70,20);
final JTextField inputC = new JTextField();
inputC.setColumns(20);
inputC.setLocation(120,50);
inputC.setSize(70,20);
JButton tombol = new JButton();
tombol.setText("Hasil Luas");
tombol.setSize(100,20);
tombol.setLocation(50,100);
JButton tombol2 = new JButton();
tombol2.setText("Hasil Keliling");
tombol2.setSize(100,20);
tombol2.setLocation(50,120);
final JLabel labelHasil = new JLabel();
labelHasil.setSize(100,20);
labelHasil.setLocation(10,140);
final JLabel labelHasil2 = new JLabel();
labelHasil2.setSize(100,20);
labelHasil2.setLocation(10,160);
jendela.getContentPane().add(labelx);
jendela.getContentPane().add(labelA);
jendela.getContentPane().add(labelB);
jendela.getContentPane().add(labelC);
jendela.getContentPane().add(inputA);
jendela.getContentPane().add(inputB);
jendela.getContentPane().add(inputC);
jendela.getContentPane().add(labelHasil);
jendela.getContentPane().add(labelHasil2);
jendela.getContentPane().add(tombol);
jendela.getContentPane().add(tombol2);
tombol.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
a = Double.parseDouble(inputA.getText());
b = Double.parseDouble(inputB.getText());
double hasil = a * b / 2;
String cetak = "Hasil : "+hasil;
labelHasil.setText(cetak);
}
});
tombol2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
a = Double.parseDouble(inputA.getText());
b = Double.parseDouble(inputB.getText());
c = Double.parseDouble(inputC.getText());
double hasil = a + b + c;
String cetak = "Hasil : "+hasil;
labelHasil2.setText(cetak);
}
});
}
}
- Buka CMD compil program tersebut
Tidak ada komentar:
Posting Komentar