0% found this document useful (0 votes)
28 views2 pages

Latihan 1 GUI

This Java application allows a user to perform basic mathematical operations on two numbers. The user can enter two numbers, select an operation from a dropdown menu, and click a button to calculate the result. The result is displayed in a text field. It also includes buttons to reset the fields or exit the application.
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)
28 views2 pages

Latihan 1 GUI

This Java application allows a user to perform basic mathematical operations on two numbers. The user can enter two numbers, select an operation from a dropdown menu, and click a button to calculate the result. The result is displayed in a text field. It also includes buttons to reset the fields or exit the application.
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/ 2

 

 
package jaavaapplicatio on2; 
 
import javvax.swing.JOp ptionPane; 
 
public class NewJFrame extends javvax.swing.JFraame { 
 
    public N NewJFrame() { 
        initCo omponents();; 
    } 
 
    private void btnHitungActionPerfformed(java.aawt.event.ActtionEvent evtt) {                                           
        doub ble a,b,c = 0; 
         
        a = Double.parseD Double(txtAnggka1.getText(()); 
        b = Double.parseD Double(txtAnggka2.getText(()); 
         
        if(jCo omboBox1.gettSelectedInde ex() == 0){ 
            c = a + b; 
        }else if(jComboBoxx1.getSelecte edIndex() == 1
1){ 
            c = a ‐ b; 
        }else if(jComboBoxx1.getSelecte edIndex() == 2
2){ 
            c = a * b; 
        }else if(jComboBoxx1.getSelecte edIndex() == 3
3){ 
            c = a / b; 
        } 
         
        txtHaasil.setText(Double.toString(c)); 
    }                                          
 
    private void txtAngkka1KeyTyped((java.awt.event.KeyEvent eevt) {                                    
        if(! Ch haracter.isDiggit(evt.getKeyyChar())){ 
            evtt.consume(); 
        } 
    }                                   
 
    private void txtAngkka2KeyTyped((java.awt.event.KeyEvent eevt) {                                    
        if(! Character.isDigit(evt.getKeyChar())){ 
            evt.consume(); 
        } 
    }                                   
 
    private void btnResetActionPerformed(java.awt.event.ActionEvent evt) {                                          
        txtAngka1.setText(""); 
        txtAngka2.setText(""); 
        txtHasil.setText(""); 
        jComboBox1.setSelectedIndex(‐1); 
    }                                         
 
    private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if(JOptionPane.showConfirmDialog(this, "Are You Sure ?", "Exit",  
                JOptionPane.YES_NO_OPTION,  
                JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION){ 
            System.exit(0); 
        } 
    }                                        
 
    public static void main(String args[]) { 
        java.awt.EventQueue.invokeLater(new Runnable() { 
            public void run() { 
                new NewJFrame().setVisible(true); 
            } 
        }); 
    } 
 
    // Variables declaration ‐ do not modify                      
    private javax.swing.JButton btnExit; 
    private javax.swing.JButton btnHitung; 
    private javax.swing.JButton btnReset; 
    private javax.swing.JComboBox jComboBox1; 
    private javax.swing.JLabel jLabel1; 
    private javax.swing.JLabel jLabel2; 
    private javax.swing.JLabel jLabel3; 
    private javax.swing.JLabel jLabel4; 
    private javax.swing.JTextField txtAngka1; 
    private javax.swing.JTextField txtAngka2; 
    private javax.swing.JTextField txtHasil; 
    // End of variables declaration                    

You might also like