Desain Form
Inputan
Source
package ResnponsiPrkDesktop;
import com.sun.org.apache.xpath.internal.operations.Variable;
import javax.swing.JOptionPane;
public class FormInputan extends javax.swing.JFrame {
public static String a;
public static String b;
public static String c;
public static String d;
public FormInputan() {
initComponents();
}
private void rdopersegipanjangActionPerformed(java.awt.event.ActionEvent
evt) {
if (rdopersegipanjang.isSelected()){
label1.setText("Panjang");
label2.setText("Lebar");
}
}
private void rdosegitigaActionPerformed(java.awt.event.ActionEvent evt)
{
if(rdosegitiga.isSelected()){
label1.setText("Alas");
label2.setText("Tinggi");
}
}
private void tmblkirimActionPerformed(java.awt.event.ActionEvent evt)
{
try {
int alas,tinggi;
alas=Integer.parseInt(txt1.getText());
tinggi=Integer.parseInt(txt2.getText());
if
(txt1.getText().equals("")&&(txt2.getText().equals(""))){
}
if
(rdopersegipanjang.isSelected()){
a=txt1.getText();
b=txt2.getText();
}else
if(rdosegitiga.isSelected()){
a=txt1.getText();
b=txt2.getText();
}
new FormTampilan().show();
} catch(NumberFormatException
e){
JOptionPane.showMessageDialog(null,"salah masukkan angka");
}
}
Desain Form Tampilan
Source Code Pada Form Tampilan
package ResnponsiPrkDesktop;
import javax.swing.JOptionPane;
public class FormTampilan extends javax.swing.JFrame {
public FormTampilan() {
initComponents();
}
private void formWindowActivated(java.awt.event.WindowEvent evt) {
// TODO add your handling
code here:
hasil1.setText(FormInputan.a);
hasil2.setText(FormInputan.b);
int hasil=Integer.parseInt(hasil1.getText())*Integer.parseInt(hasil2.getText());
hasil3.setText(Integer.toString(hasil));
}
private void
tmblTutupActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "terima kasih");
System.exit(0);// TODO add your
handling code here:
}
Hasil Running
JIKA DIPILIH SEGITIGA PADA RADIO BUTTON
JIKA DIPILIH Persegi Panjang PADA RADIO BUTTON
Jika salah masukkan data
Hasil Perhitungan
0 komentar:
Posting Komentar