Rabu, 29 Januari 2014

bismillah,,,

pada kesempatan kali ini, saya hendak memposting program yang hendak saya presentasikan di lab
ICT BIT lhokseumawe.  yaitu program kalkulator sederhana.
karena berubung waktunya hampir dhuhur, jadi pengenalannya singkat saja ia..

Run maka programnya akan kluar seperti di atas.



ini scriptnya. silakan di copy.

private void plusButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_plusButtonActionPerformed
       int number1, number2;
        try {
            number1 = Integer.parseInt(
                    this.firstnumberText.getText());
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Bad first number",
                    "Error",JOptionPane.ERROR_MESSAGE);
            return;

        }
        try {
            number2 = Integer.parseInt(
                    this.secondnumberText.getText());
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Bad second number",
                    "Error",JOptionPane.ERROR_MESSAGE);
            return;

        }
        int answer = number1 + number2;
        this.answerLabel.setText(
                "The answer is: "+ answer);

    }//GEN-LAST:event_plusButtonActionPerformed

    private void minusButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_minusButtonActionPerformed
        int number1, number2;
        try {
            number1 = Integer.parseInt(
                    this.firstnumberText.getText());
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Bad first number",
                    "Error", JOptionPane.ERROR_MESSAGE);
            return;

        }
        try {
            number2 = Integer.parseInt(
                    this.secondnumberText.getText());
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Bad second number",
                    "Error", JOptionPane.ERROR_MESSAGE);
            return;

        }
        int answer = number1 - number2;
        this.answerLabel.setText(
                "The answer is: " + answer);
    }//GEN-LAST:event_minusButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CalculatorForm().setVisible(true);
            }
        });
    }

Related Posts by Categories

Categories: ,

0 komentar:

Posting Komentar