Вы находитесь на странице: 1из 9

/*

* To change this template, choose Tools | Templates


* and open the template in the editor.
*/

/*
* Kalkulator.java
*
* Created on 03.06.2010., 21:35:12
*/

/**
*
* @author Kristian
*/
public class Kalkulator extends javax.swing.JFrame {
int prvi_broj=0;
int drugi_broj=0;
int ukupno=0;
int br_click_plus=0;
int br_click_minus=0;
/** Creates new form Kalkint temp;
int ukupno;ulator */
public Kalkulator() {
initComponents();
}

/** This method is called from within the constructor to


* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-
BEGIN:initComponents
private void initComponents() {

display = new javax.swing.JTextField();


jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
plus = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
minus = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
jButton10 = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();
jButton12 = new javax.swing.JButton();
jednako = new javax.swing.JButton();
brisanje = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Kalkulator");

display.setEditable(false);
display.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N

jButton1.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N


jButton1.setText("7");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jButton2.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N


jButton2.setText("8");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jButton3.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N


jButton3.setText("9");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

plus.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N


plus.setText("+");
plus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
plusActionPerformed(evt);
}
});

jButton5.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N


jButton5.setText("4");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});

jButton6.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N


jButton6.setText("5");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});

jButton7.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N


jButton7.setText("6");
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});
minus.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
minus.setText("-");
minus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
minusActionPerformed(evt);
}
});

jButton9.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N


jButton9.setText("1");
jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton9ActionPerformed(evt);
}
});

jButton10.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N


jButton10.setText("2");
jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton10ActionPerformed(evt);
}
});

jButton11.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N


jButton11.setText("3");
jButton11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton11ActionPerformed(evt);
}
});

jButton12.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N


jButton12.setText("0");
jButton12.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton12ActionPerformed(evt);
}
});

jednako.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N


jednako.setText("=");
jednako.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jednakoActionPerformed(evt);
}
});

brisanje.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N


brisanje.setText("C");
brisanje.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
brisanjeActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILIN
G, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addComponent(jButton5,
javax.swing.GroupLayout.PREFERRED_SIZE, 64,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton6,
javax.swing.GroupLayout.PREFERRED_SIZE, 64,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton7,
javax.swing.GroupLayout.PREFERRED_SIZE, 64,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(minus,
javax.swing.GroupLayout.PREFERRED_SIZE, 64,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addComponent(jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE, 64,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2,
javax.swing.GroupLayout.PREFERRED_SIZE, 64,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3,
javax.swing.GroupLayout.PREFERRED_SIZE, 64,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(plus,
javax.swing.GroupLayout.PREFERRED_SIZE, 64,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addComponent(jButton12,
javax.swing.GroupLayout.PREFERRED_SIZE, 64,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jednako,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addComponent(jButton9,
javax.swing.GroupLayout.PREFERRED_SIZE, 64,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton10,
javax.swing.GroupLayout.PREFERRED_SIZE, 64,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton11,
javax.swing.GroupLayout.PREFERRED_SIZE, 64,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(brisanje,
javax.swing.GroupLayout.PREFERRED_SIZE, 64,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(display,
javax.swing.GroupLayout.Alignment.LEADING))
.addContainerGap(20, Short.MAX_VALUE))
);
layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(display, javax.swing.GroupLayout.PREFERRED_SIZE,
49, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELIN
E)
.addComponent(jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2,
javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton3,
javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(plus,
javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELIN
E)
.addComponent(jButton5,
javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton6,
javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton7,
javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(minus,
javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELIN
E)
.addComponent(jButton9,
javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton10,
javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton11,
javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(brisanje,
javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELIN
E)
.addComponent(jButton12,
javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jednako,
javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(24, Short.MAX_VALUE))
);

pack();
}// </editor-fold>//GEN-END:initComponents

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt)


{//GEN-FIRST:event_jButton9ActionPerformed
display.setText(display.getText()+"1");
}//GEN-LAST:event_jButton9ActionPerformed

private void jButton12ActionPerformed(java.awt.event.ActionEvent evt)


{//GEN-FIRST:event_jButton12ActionPerformed
display.setText(display.getText()+"0");
}//GEN-LAST:event_jButton12ActionPerformed

private void jednakoActionPerformed(java.awt.event.ActionEvent evt)


{//GEN-FIRST:event_jednakoActionPerformed
drugi_broj=(Integer.parseInt(String.valueOf(display.getText())));
if(br_click_plus > 0){
ukupno=prvi_broj+drugi_broj;

}
else{
ukupno=prvi_broj-drugi_broj;
}
display.setText(String.valueOf(ukupno));
ukupno=0;
prvi_broj=0;
drugi_broj=0;
br_click_plus=0;
br_click_minus=0;
}//GEN-LAST:event_jednakoActionPerformed

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt)


{//GEN-FIRST:event_jButton10ActionPerformed
display.setText(display.getText()+"2");
}//GEN-LAST:event_jButton10ActionPerformed

private void jButton11ActionPerformed(java.awt.event.ActionEvent evt)


{//GEN-FIRST:event_jButton11ActionPerformed
display.setText(display.getText()+"3");
}//GEN-LAST:event_jButton11ActionPerformed

private void brisanjeActionPerformed(java.awt.event.ActionEvent evt)


{//GEN-FIRST:event_brisanjeActionPerformed
display.setText("");
ukupno=0;
prvi_broj=0;
drugi_broj=0;
br_click_plus=0;
br_click_minus=0;

}//GEN-LAST:event_brisanjeActionPerformed

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt)


{//GEN-FIRST:event_jButton5ActionPerformed
display.setText(display.getText()+"4");
}//GEN-LAST:event_jButton5ActionPerformed

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt)


{//GEN-FIRST:event_jButton6ActionPerformed
display.setText(display.getText()+"5");
}//GEN-LAST:event_jButton6ActionPerformed

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt)


{//GEN-FIRST:event_jButton7ActionPerformed
display.setText(display.getText()+"6");
}//GEN-LAST:event_jButton7ActionPerformed

private void minusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-


FIRST:event_minusActionPerformed
br_click_minus++;

if (br_click_plus + br_click_minus > 1){


drugi_broj=(Integer.parseInt(String.valueOf(display.getText())));
if(br_click_minus==2){
ukupno=prvi_broj-drugi_broj;
}
else{
ukupno=prvi_broj+drugi_broj;
}
display.setText("");
prvi_broj=ukupno;
ukupno=0;
br_click_plus=0;
br_click_minus=1;
}
else{
prvi_broj=(Integer.parseInt(String.valueOf(display.getText())));
display.setText("");
}

}//GEN-LAST:event_minusActionPerformed

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


{//GEN-FIRST:event_jButton1ActionPerformed
display.setText(display.getText()+"7");
}//GEN-LAST:event_jButton1ActionPerformed

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


{//GEN-FIRST:event_jButton2ActionPerformed
display.setText(display.getText()+"8");
}//GEN-LAST:event_jButton2ActionPerformed

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


{//GEN-FIRST:event_jButton3ActionPerformed
display.setText(display.getText()+"9");
}//GEN-LAST:event_jButton3ActionPerformed

private void plusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-


FIRST:event_plusActionPerformed
br_click_plus++;

if (br_click_plus + br_click_minus > 1){


drugi_broj=(Integer.parseInt(String.valueOf(display.getText())));
if(br_click_plus==2){
ukupno=prvi_broj+drugi_broj;
}
else{
ukupno=prvi_broj-drugi_broj;
}
display.setText("");
prvi_broj=ukupno;
ukupno=0;
br_click_plus=1;
br_click_minus=0;
}
else{
prvi_broj=(Integer.parseInt(String.valueOf(display.getText())));
display.setText("");
}
}//GEN-LAST:event_plusActionPerformed

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

// Variables declaration - do not modify//GEN-BEGIN:variables


private javax.swing.JButton brisanje;
private javax.swing.JTextField display;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton12;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton9;
private javax.swing.JButton jednako;
private javax.swing.JButton minus;
private javax.swing.JButton plus;
// End of variables declaration//GEN-END:variables

Вам также может понравиться