0% found this document useful (0 votes)
40 views3 pages

Latihan Java Swing

This document contains code for two Java Swing programs. The first program defines a class called "kombo" that contains code to perform mathematical operations like addition, subtraction, multiplication and division based on the selected option in a combo box. It takes two integer values as input and displays the result. The second program defines a class called "oprt" that contains code to perform various arithmetic operations like multiplication, division, addition, subtraction, increment, decrement and modulus on two integer values input by the user and displays the results. It also allows the user to clear the input fields and confirms with the user before exiting the program.

Uploaded by

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

Latihan Java Swing

This document contains code for two Java Swing programs. The first program defines a class called "kombo" that contains code to perform mathematical operations like addition, subtraction, multiplication and division based on the selected option in a combo box. It takes two integer values as input and displays the result. The second program defines a class called "oprt" that contains code to perform various arithmetic operations like multiplication, division, addition, subtraction, increment, decrement and modulus on two integer values input by the user and displays the results. It also allows the user to clear the input fields and confirms with the user before exiting the program.

Uploaded by

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

Praktikum : Latihan Java Swing

Kode :
public class kombo extends javax.swing.JFrame {

/** Creates new form kombo */


public kombo() {
initComponents();
}
@SuppressWarnings("unchecked")

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {


int bil1 = Integer.parseInt(tfBil1.getText());
int bil2 = Integer.parseInt(tfBil2.getText());
double hasil = 0;
int op = cbOperator.getSelectedIndex();
switch(op){
case 0 : hasil = bil1 + bil2 ;
break ;
case 1 : hasil = bil1 - bil2 ;
break ;
case 2 : hasil = bil1 * bil2 ;
break ;
case 3 : hasil = bil1 / bil2 ;
break ; }
tfHasil.setText(String.valueOf(hasil));
// TODO add your handling code here:
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new kombo().setVisible(true);
}
});
}
}

1
Praktikum : Latihan Java Swing

Kode :

import javax.swing.JOptionPane;

public class oprt extends javax.swing.JFrame {


public int bil1;
public int bil2;
public long tambah;
public int kurang;
public long kali;
public double bagi;
public int naik;
public int turun;
public int sisa;

/** Creates new form oprt */


public oprt() {
initComponents();
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {


jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");

2
Praktikum : Latihan Java Swing

jTextField7.setText("");
jTextField8.setText("");
jTextField9.setText("");
jTextField1.requestFocus();

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {


bil1=Integer.parseInt(jTextField1.getText());
bil2=Integer.parseInt(jTextField2.getText());
kali=bil1*bil2;
jTextField3.setText(String.valueOf(kali));
bagi=bil1/bil2;
jTextField5.setText(String.valueOf(bagi));
tambah=bil1+bil2;
jTextField4.setText(String.valueOf(tambah));
kurang=bil1-bil2;
jTextField6.setText(String.valueOf(kurang));
sisa=bil1%bil2;
jTextField7.setText(String.valueOf(sisa));
naik=++bil1;
jTextField8.setText(String.valueOf(naik));
turun=--bil2;
jTextField9.setText(String.valueOf(turun));

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {


if (JOptionPane.showConfirmDialog(null, "Yakin ingin keluar ?", "Konfirmasi",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
this.dispose();
// TODO add your handling code here:
}

public static void main(String args[]) {


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new oprt().setVisible(true);
}
});
}
}

You might also like