Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Pomoc oko ispravka koda-kalkulator

[es] :: Java :: Pomoc oko ispravka koda-kalkulator

[ Pregleda: 1858 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

DavorPro

Član broj: 118716
Poruke: 55
87.252.137.*



Profil

icon Pomoc oko ispravka koda-kalkulator11.02.2007. u 17:45 - pre 209 meseci
Postovani forumasi i programeri molim za malo pomoci napravio sam kalkulator u GUI i on je funkcionalan a drugi sam radio
rucno no on ne radi pa ako neko zna di sam pogrijesio molim da mi pomogne a ujedno da to zajedno podjelimo sa svim ostalima. Prvi dio koda je iz GUI a drugi je rucno pisan kod.


Kalkulator:
Code:

import com.sun.org.apache.bcel.internal.verifier.statics.DOUBLE_Upper;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
import java.awt.*;
import java.awt.Event.*;
/*
 * Kalkulator.java
 *
 * Created on 2007. siječanj 30, 20:21
 */

/**
 *
 * @author  Davor
 */
public class Kalkulator extends javax.swing.JFrame {
    
    enum Operacija{Plus,Minus,Puta,Podjeljeno,Jednako,Nista}
    Operacija operacija=Operacija.Nista;
    Double prviBroj;
    Double drugiBroj;
    
    
    
    
    
    /** Creates new form Kalkulator */
    public Kalkulator() {
      
        initComponents();
        this.setTitle("Kalkulator");
        DISPLEJ.setEditable(false);
        DISPLEJ.setText("0");
        setVisible(true);
        this.repaint();// da ponovno ispise 
    }
    
    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
    private void initComponents() {
        DISPLEJ = new javax.swing.JTextField();
        jedan = new javax.swing.JButton();
        dva = new javax.swing.JButton();
        tri = new javax.swing.JButton();
        sedam = new javax.swing.JButton();
        sest = new javax.swing.JButton();
        pet = new javax.swing.JButton();
        cetri = new javax.swing.JButton();
        osam = new javax.swing.JButton();
        zarez = new javax.swing.JButton();
        tocka = new javax.swing.JButton();
        nula = new javax.swing.JButton();
        devet = new javax.swing.JButton();
        plus = new javax.swing.JButton();
        minus = new javax.swing.JButton();
        puta = new javax.swing.JButton();
        podljeljeno = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        brise = new javax.swing.JButton();
        BACKSPACE = new javax.swing.JButton();
        jednako = new javax.swing.JButton();
        MC = new javax.swing.JButton();
        MS = new javax.swing.JButton();
        MR = new javax.swing.JButton();
        MPlus = new javax.swing.JButton();
        labelaMemorija = new javax.swing.JLabel();
        sqrt = new javax.swing.JButton();
        jedanKroz = new javax.swing.JButton();
        plusMinus = new javax.swing.JButton();
        postotak = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        DISPLEJ.setBackground(new java.awt.Color(0, 0, 0));
        DISPLEJ.setFont(new java.awt.Font("Arial Black", 1, 18));
        DISPLEJ.setForeground(new java.awt.Color(51, 255, 0));
        DISPLEJ.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        DISPLEJ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DISPLEJActionPerformed(evt);
            }
        });

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

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

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

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

        sest.setText("6");
        sest.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sestActionPerformed(evt);
            }
        });

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

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

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

        zarez.setForeground(new java.awt.Color(255, 51, 51));
        zarez.setText(",");
        zarez.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zarezActionPerformed(evt);
            }
        });

        tocka.setForeground(new java.awt.Color(255, 51, 51));
        tocka.setText(".");
        tocka.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tockaActionPerformed(evt);
            }
        });

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

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

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

        minus.setForeground(new java.awt.Color(255, 51, 51));
        minus.setText("-");
        minus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                minusActionPerformed(evt);
            }
        });

        puta.setForeground(new java.awt.Color(255, 51, 51));
        puta.setText("*");
        puta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                putaActionPerformed(evt);
            }
        });

        podljeljeno.setForeground(new java.awt.Color(255, 0, 51));
        podljeljeno.setText("/");
        podljeljeno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                podljeljenoActionPerformed(evt);
            }
        });

        jLabel1.setForeground(new java.awt.Color(0, 0, 102));
        jLabel1.setText("CASIO");

        brise.setForeground(new java.awt.Color(51, 255, 0));
        brise.setText("c");
        brise.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                briseActionPerformed(evt);
            }
        });

        BACKSPACE.setText("BACKSPACE");
        BACKSPACE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BACKSPACEActionPerformed(evt);
            }
        });

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

        MC.setForeground(new java.awt.Color(255, 0, 0));
        MC.setText("MC");
        MC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MCActionPerformed(evt);
            }
        });

        MS.setForeground(new java.awt.Color(255, 51, 51));
        MS.setText("MS");
        MS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MSActionPerformed(evt);
            }
        });

        MR.setForeground(new java.awt.Color(255, 51, 51));
        MR.setText("MR");
        MR.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MRActionPerformed(evt);
            }
        });

        MPlus.setForeground(new java.awt.Color(255, 51, 51));
        MPlus.setText("M+");
        MPlus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MPlusActionPerformed(evt);
            }
        });

        labelaMemorija.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelaMemorija.setText("0");
        labelaMemorija.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        sqrt.setForeground(new java.awt.Color(51, 255, 0));
        sqrt.setText("sqrt");
        sqrt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sqrtActionPerformed(evt);
            }
        });

        jedanKroz.setForeground(new java.awt.Color(51, 255, 0));
        jedanKroz.setText("1/x");
        jedanKroz.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jedanKrozActionPerformed(evt);
            }
        });

        plusMinus.setForeground(new java.awt.Color(51, 255, 0));
        plusMinus.setText("+/-");
        plusMinus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                plusMinusActionPerformed(evt);
            }
        });

        postotak.setForeground(new java.awt.Color(102, 255, 0));
        postotak.setText("%");
        postotak.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                postotakActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(DISPLEJ, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(layout.createSequentialGroup()
                                        .add(jedan)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(dva)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(tri)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(cetri))
                                    .add(layout.createSequentialGroup()
                                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                                .add(devet)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(nula)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(tocka, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                                .add(pet)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(sest)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(sedam)))
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(zarez, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                                            .add(osam))))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(sqrt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 52, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jedanKroz, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 52, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(plusMinus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 52, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(25, 25, 25)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(MC)
                                    .add(MS)
                                    .add(MR)))))
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(plus)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(podljeljeno)
                                .add(6, 6, 6)
                                .add(minus)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(puta)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(postotak, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 52, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(layout.createSequentialGroup()
                                .add(labelaMemorija, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 42, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(18, 18, 18)
                                .add(BACKSPACE)
                                .add(30, 30, 30)
                                .add(jednako, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 27, Short.MAX_VALUE)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(brise, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(MPlus, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .add(layout.createSequentialGroup()
                        .add(128, 128, 128)
                        .add(jLabel1)))
                .addContainerGap())
        );

        layout.linkSize(new java.awt.Component[] {minus, plus, podljeljeno, puta}, org.jdesktop.layout.GroupLayout.HORIZONTAL);

        layout.linkSize(new java.awt.Component[] {cetri, devet, dva, jedan, nula, osam, pet, sedam, sest, tocka, tri, zarez}, org.jdesktop.layout.GroupLayout.HORIZONTAL);

        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jLabel1)
                .add(9, 9, 9)
                .add(DISPLEJ, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 43, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jedan)
                    .add(dva)
                    .add(tri)
                    .add(cetri)
                    .add(MC)
                    .add(sqrt))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(pet)
                    .add(sest)
                    .add(sedam)
                    .add(osam)
                    .add(MS)
                    .add(jedanKroz))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(devet)
                    .add(nula)
                    .add(tocka)
                    .add(zarez)
                    .add(MR)
                    .add(plusMinus))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(MPlus)
                            .add(postotak))
                        .add(12, 12, 12)
                        .add(brise))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(plus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(podljeljeno, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(minus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(puta, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(15, 15, 15)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(labelaMemorija, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 30, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jednako, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 32, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(BACKSPACE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 33, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(25, Short.MAX_VALUE))
        );

        layout.linkSize(new java.awt.Component[] {minus, plus, podljeljeno, puta}, org.jdesktop.layout.GroupLayout.VERTICAL);

        layout.linkSize(new java.awt.Component[] {cetri, devet, dva, jedan, nula, osam, pet, sedam, sest, tocka, tri, zarez}, org.jdesktop.layout.GroupLayout.VERTICAL);

        pack();
    }// </editor-fold>                        

    private void postotakActionPerformed(java.awt.event.ActionEvent evt) {                                         
drugiBroj=Double.parseDouble(DISPLEJ.getText());
Double rezultat=(prviBroj*drugiBroj)/100;
DISPLEJ.setText(""+rezultat);
    }                                        

    private void plusMinusActionPerformed(java.awt.event.ActionEvent evt) {                                          
DISPLEJ.setText(""+(Double.parseDouble(DISPLEJ.getText())));
    }                                         

    private void jedanKrozActionPerformed(java.awt.event.ActionEvent evt) {                                          
Double rezultat=1/Double.parseDouble(DISPLEJ.getText());
DISPLEJ.setText(""+rezultat);
    }                                         

    private void sqrtActionPerformed(java.awt.event.ActionEvent evt) {                                     
Double rezultat = Math.sqrt(Double.parseDouble(DISPLEJ.getText()));
DISPLEJ.setText(""+rezultat);
    }                                    

    private void MPlusActionPerformed(java.awt.event.ActionEvent evt) {                                      
Double a= Double.parseDouble(DISPLEJ.getText());
Double b= Double.parseDouble(labelaMemorija.getText());
double rezultat=a+b;
labelaMemorija.setText(""+rezultat);
    }                                     

    private void MCActionPerformed(java.awt.event.ActionEvent evt) {                                   
labelaMemorija.setText("0");
    }                                  

    private void MRActionPerformed(java.awt.event.ActionEvent evt) {                                   
    DISPLEJ.setText(labelaMemorija.getText());
    }                                  

    private void MSActionPerformed(java.awt.event.ActionEvent evt) {                                   
labelaMemorija.setText(DISPLEJ.getText());
    }                                  

    private void jednakoActionPerformed(java.awt.event.ActionEvent evt) {                                        
   drugiBroj=Double.parseDouble(DISPLEJ.getText());
      Double rezultat= 0.0;
      
      switch(operacija){
          case Plus:
          rezultat=prviBroj+drugiBroj;
          break;
          
          case Minus:
          rezultat=prviBroj-drugiBroj;
          break;
          
          case Puta:
          rezultat=prviBroj*drugiBroj;
          break;
          
          case Podjeljeno:
           rezultat=prviBroj/drugiBroj;
           break;
      }
      DISPLEJ.setText(""+rezultat);
           
    }                                       

    private void BACKSPACEActionPerformed(java.awt.event.ActionEvent evt) {                                          
    if(DISPLEJ.getText().length()==1){
        
        DISPLEJ.setText("0");
    }else{
        DISPLEJ.setText(DISPLEJ.getText().substring(0,DISPLEJ.getText().length()-1));
    }
    }                                         

    private void briseActionPerformed(java.awt.event.ActionEvent evt) {                                      
    DISPLEJ.setText("0");
    }                                     

    private void DISPLEJActionPerformed(java.awt.event.ActionEvent evt) {                                        
                 
    }                                       

    private void podljeljenoActionPerformed(java.awt.event.ActionEvent evt) {                                            
    operacija=Operacija.Podjeljeno;
      prviBroj=Double.parseDouble(DISPLEJ.getText());
      DISPLEJ.setText("0");
    }                                           

    private void plusActionPerformed(java.awt.event.ActionEvent evt) {                                     
    operacija=Operacija.Plus;
      prviBroj=Double.parseDouble(DISPLEJ.getText());
      DISPLEJ.setText("0");
    }                                    

    private void putaActionPerformed(java.awt.event.ActionEvent evt) {                                     
    operacija=Operacija.Puta;
      prviBroj=Double.parseDouble(DISPLEJ.getText());
      DISPLEJ.setText("0");
    }                                    

    private void minusActionPerformed(java.awt.event.ActionEvent evt) {                                      
 operacija=Operacija.Minus;
      prviBroj=Double.parseDouble(DISPLEJ.getText());
      DISPLEJ.setText("0");
    }                                     

    private void zarezActionPerformed(java.awt.event.ActionEvent evt) {                                      
  upisiBroj(evt);
    }                                     

    private void tockaActionPerformed(java.awt.event.ActionEvent evt) {                                      
 if(!DISPLEJ.getText().contains("."))DISPLEJ.setText(DISPLEJ.getText()+".");
    }                                     

    private void nulaActionPerformed(java.awt.event.ActionEvent evt) {                                     
  upisiBroj(evt);
    }                                    

    private void devetActionPerformed(java.awt.event.ActionEvent evt) {                                      
  upisiBroj(evt);
    }                                     

    private void osamActionPerformed(java.awt.event.ActionEvent evt) {                                     
  upisiBroj(evt);
    }                                    

    private void sedamActionPerformed(java.awt.event.ActionEvent evt) {                                      
  upisiBroj(evt);
    }                                     

    private void sestActionPerformed(java.awt.event.ActionEvent evt) {                                     
  upisiBroj(evt);
    }                                    

    private void petActionPerformed(java.awt.event.ActionEvent evt) {                                    
  upisiBroj(evt);
    }                                   

    private void cetriActionPerformed(java.awt.event.ActionEvent evt) {                                      
  upisiBroj(evt);
    }                                     

    private void triActionPerformed(java.awt.event.ActionEvent evt) {                                    
    upisiBroj(evt);
    }                                   

    private void dvaActionPerformed(java.awt.event.ActionEvent evt) {                                    
    upisiBroj(evt);
    }                                   

    private void jedanActionPerformed(java.awt.event.ActionEvent evt) {                                      
   upisiBroj(evt);
    }                                     
    private void upisiBroj(java.awt.event.ActionEvent evt){
        if(DISPLEJ.getText().startsWith("0")&DISPLEJ.getText().length()==1){
            DISPLEJ.setText("");
        }
     JButton b=(JButton)evt.getSource();  // ovdije smo kastali
     String textDugmeta=b.getText();
     DISPLEJ.setText(DISPLEJ.getText()+textDugmeta);
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
          Look.setLook(Look.windows);
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new Kalkulator();
            }
        });
    }
    
    // Variables declaration - do not modify                     
    private javax.swing.JButton BACKSPACE;
    private javax.swing.JTextField DISPLEJ;
    private javax.swing.JButton MC;
    private javax.swing.JButton MPlus;
    private javax.swing.JButton MR;
    private javax.swing.JButton MS;
    private javax.swing.JButton brise;
    private javax.swing.JButton cetri;
    private javax.swing.JButton devet;
    private javax.swing.JButton dva;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton jedan;
    private javax.swing.JButton jedanKroz;
    private javax.swing.JButton jednako;
    private javax.swing.JLabel labelaMemorija;
    private javax.swing.JButton minus;
    private javax.swing.JButton nula;
    private javax.swing.JButton osam;
    private javax.swing.JButton pet;
    private javax.swing.JButton plus;
    private javax.swing.JButton plusMinus;
    private javax.swing.JButton podljeljeno;
    private javax.swing.JButton postotak;
    private javax.swing.JButton puta;
    private javax.swing.JButton sedam;
    private javax.swing.JButton sest;
    private javax.swing.JButton sqrt;
    private javax.swing.JButton tocka;
    private javax.swing.JButton tri;
    private javax.swing.JButton zarez;
    // End of variables declaration                   
    
}
----------------------------------------------------------
//ovo treba dodati u src

/*
 * look.java
 *
 * Created on 2006. studeni 30, 11:07
 *
 */

/**
 *
 * @author Danijel Jelenić
 * @version 1.1
 */


import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
import javax.swing.*;
import java.awt.*;

public class look {
    
    public static final int windows = 0;
    public static final int unix    = 1;
    public static final int java    = 2;
    public static final int system  = 3;
    
    /**
     * Stvara novu instancu look klase
     * Privatni konstruktor - ne dozvoljava stvaranje novog objekta
     */
    private look() {
    }
    
    public static com.sun.java.swing.plaf.motif.MotifLookAndFeel getUnixLook(){
        return new com.sun.java.swing.plaf.motif.MotifLookAndFeel();
    }
    
    public static com.sun.java.swing.plaf.windows.WindowsLookAndFeel getWindowsLook(){
        return new com.sun.java.swing.plaf.windows.WindowsLookAndFeel();
    }
    
    public static javax.swing.plaf.metal.MetalLookAndFeel getJavaLook(){
        return new javax.swing.plaf.metal.MetalLookAndFeel();
    }
    
    
    /**
     * Metoda koja postavlja izgled aplikacije
     * <b>Primjer -<b> </br>
     * look.setLook(look.windows);
     * 
     * @param look int izgled prozora
     */
    public static void setLook(int look){
        try {
            switch(look){
                case 0:
                    javax.swing.UIManager.setLookAndFeel(getWindowsLook());
                    break;
                case 1:
                    javax.swing.UIManager.setLookAndFeel(getUnixLook());
                    break;
                case 2:
                    javax.swing.UIManager.setLookAndFeel(getJavaLook());
                    break;
                case 3:
                    javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
            }
        }catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    
    /**
     * Metoda koja postavlja izgled aplikacije sa parametrom trenutne forme
     * <b>Primjer -<b> </br>
     * look.setLook(this, look.windows);
     * 
     * @param look int izgled prozora
     * @param frame JFrame forma na koju se odnosi promjena (ako se odnosi na trenutnu anda se predaje parametar <b>this</b>)
     */
    public static void setLook(JFrame frame, int look){
        setLook(look);
        SwingUtilities.updateComponentTreeUI(frame);
    }
    
    
    /** Postavlja formu u centar ekrana i podeąava joj ąirinu i visinu
     * @param window je prozor koji treba centrirati
     */
    public static void centerFrame(Window window){
        window.setBounds((int)GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().getX()-window.getWidth()/2,(int)GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().getY()-window.getHeight()/2,window.getWidth(),window.getHeight());
    }

    static void setLook(WindowsLookAndFeel windowsLookAndFeel) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
    
    
}





------------------------------------------------------------------------
Rucno pisani kod.// Isto treba dodati u src Look.java od autora : D. Jelenic
-----------------------------------------------------------------------


Molim vas da ne obracate paznju na razmjestaj dugmica bitna je funkcionalnost 
/*
 * 
 *
 * Created on 2007. siječanj 27, 17:56
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *
 * @author Davor
 */
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
import java.awt.Event.*;

public class Calculator  extends JFrame{
    
   
    enum Operacija{Plus,Minus,Puta,Podjeljeno,Jednako,Nista}
    Operacija operacija=Operacija.Nista;
    Double prviBroj;
    Double drugiBroj;
      
      
      
         JTextField display = new  JTextField();
         JButton jedan = new JButton();
         JButton dva= new JButton();
         JButton tri= new JButton();
         JButton cetri= new JButton();
         JButton pet= new JButton();
         JButton sest= new JButton();
         JButton sedam= new JButton();
         JButton osam= new JButton();
         JButton devet= new JButton();
         JButton nula= new JButton();
         JButton plus= new JButton();
         JButton minus= new JButton();
         JButton podjeljeno= new JButton();
         JButton puta= new JButton();
         JButton jedanKrozX= new JButton();
         JButton sqrt= new JButton();
         JButton tocka= new JButton();
         JButton zarez= new JButton();
         JButton  pMin= new JButton();
         JButton postotak= new JButton();
         JButton jednako= new JButton();
         JButton c= new JButton();
         JButton ce= new JButton();
         JButton memoriyC= new JButton();
         JButton memoryR= new JButton();
         JButton memoryS= new JButton();
         JButton memoryPlus= new JButton();
         JButton backSpace= new JButton();
         JLabel label= new JLabel();
         JLabel labelDva= new JLabel();     
                
//     display.addActionListener(new java.awt.event.ActionListener() {
//            public void actionPerformed(java.awt.event.ActionEvent evt) {
//                ActionPerformed(evt);
//     
    
   
    public Calculator() {
        
      
        initComponents();
        this.setTitle("Kalkulator");
        display.setEditable(false);
        display.setText("0");
        setVisible(true);
        this.repaint();
        
        
  //   inicirajKomponente.setOpaque(true);
   
    }
   
    public void  initComponents(){
        this.setBounds(100,100,310,470);
        this.setTitle(" CALCULATOR XP");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.getContentPane().setLayout(null);
        this.getContentPane().setBackground(Color.BLACK);
      
        
        
        this.getContentPane().add(display);
        display.setHorizontalAlignment(JLabel.RIGHT);
        display.setBackground(Color.BLUE);
        display.setForeground(Color.green);
        display.setBounds(10,40,275,30);
        display.setText("0");
        display.setFont(new Font("Arial",Font.BOLD,20));
        display.setEditable(false);
        this.repaint();
        
         this.getContentPane().add(jedan);
          this.getContentPane().add(dva);
           this.getContentPane().add(tri);
            this.getContentPane().add(cetri);
             this.getContentPane().add(pet);
              this.getContentPane().add(sest);
               this.getContentPane().add(sedam);
                this.getContentPane().add(osam);
                 this.getContentPane().add(devet);
                  this.getContentPane().add(nula);
                   this.getContentPane().add(jednako);
                    this.getContentPane().add(backSpace);  
                      this.getContentPane().add(plus);
                       this.getContentPane().add(minus);
                        this.getContentPane().add(podjeljeno);
                         this.getContentPane().add(puta);
                          this.getContentPane().add(ce);
                           this.getContentPane().add(c);
                            this.getContentPane().add(memoryS);
                             this.getContentPane().add(memoryR);
                              this.getContentPane().add(memoryPlus);
                                this.getContentPane().add(jedanKrozX);
                                 this.getContentPane().add(tocka);
                                  this.getContentPane().add(zarez);
                                   this.getContentPane().add(sqrt);
                                    this.getContentPane().add( pMin);
                                     this.getContentPane().add(postotak);
                                      this.getContentPane().add(label);
                                       this.getContentPane().add(labelDva);
                                      
        jedan.setBounds(10,80,45,30);
        dva.setBounds(10,120,45,30);
        tri.setBounds(10,160,45,30);
        cetri.setBounds(10,200,45,30);
        pet.setBounds(10,240,45,30);
       sedam.setBounds(10,280,45,30);
      
        
             
             nula.setBounds(65,80,45,30);
             plus.setBounds(65,120,45,30);
             minus.setBounds(65,160,45,30);
             puta.setBounds(65,200,45,30);
             podjeljeno.setBounds(65,240,45,30);
             jednako.setBounds(65,280,100,30);
            
             
             devet.setBounds(120,80,45,30);
             sqrt.setBounds(120,120,45,30);
             tocka.setBounds(120,160,45,30);
             zarez.setBounds(120,200,45,30);
             backSpace.setBounds(120,240,45,30);
           
             
             
             memoryS.setBounds(230,80,55,30);
             memoryR.setBounds(230,120,55,30);
             memoryPlus.setBounds(230,160,55,30);
             jedanKrozX.setBounds(230,200,55,30);
             ce.setBounds(230,240,55,30);
             label.setBounds(230,280,55,30);
             
              sest.setBounds(175,80,45,30);
              osam.setBounds(175,120,45,30);
              postotak.setBounds(175,160,45,30);
              c.setBounds(175,200,45,30);
             
             labelDva.setBounds(10,400,230,20);
             labelDva.setText("ASUS");
             labelDva.setForeground(Color.RED);
             labelDva.setFont(new Font("Arial",Font.BOLD,40));
             labelDva.setHorizontalAlignment(JLabel.CENTER);
             
             label.setBackground(Color.green);
             label.setForeground(Color.RED);
             label.setHorizontalAlignment(JLabel.CENTER);
             label.setText("0");
             label.setFont(new Font("Arial",Font.BOLD,20));
            
          
             
             jednako.setText("=");
             osam.setText("8");
             ce.setText("CE");
             jedanKrozX.setText("1/x");
             memoryPlus.setText("M+");
             memoryR.setText("MR");
             memoryS.setText("MS");
             c.setText("C");
             backSpace.setText("BS");
             zarez.setText(",");
             tocka.setText(".");
             sqrt.setText("Sqrt");
             devet.setText("9");
             osam.setText("8");
             sedam.setText("7");
             sest.setText("6");
             pet.setText("5");
             cetri.setText("4");
             tri.setText("3");        
             dva.setText("2");
             jedan.setText("1");
             nula.setText("0");
             plus.setText("+");
             minus.setText("-");
             podjeljeno.setText("/");
             postotak.setText("%");
             pMin.setText("+/-");
             puta.setText("*");
              jedan.setText("1");
             
              
              
              
              
        
           pack();
        this.setVisible(true);
    }
    private void postotakActionPerformed(java.awt.event.ActionEvent evt) {                                         
drugiBroj=Double.parseDouble(display.getText());
Double rezultat=(prviBroj*drugiBroj)/100;
display.setText(""+rezultat);
    }                                        

    private void plusMinusActionPerformed(java.awt.event.ActionEvent evt) {                                          
display.setText(""+(Double.parseDouble(display.getText())));
    }                                         

    private void jedanKrozActionPerformed(java.awt.event.ActionEvent evt) {                                          
Double rezultat=1/Double.parseDouble(display.getText());
display.setText(""+rezultat);
    }                                         

    private void sqrtActionPerformed(java.awt.event.ActionEvent evt) {                                     
Double rezultat = Math.sqrt(Double.parseDouble(display.getText()));
display.setText(""+rezultat);
    }                                    

    private void MPlusActionPerformed(java.awt.event.ActionEvent evt) {                                      
Double a= Double.parseDouble(display.getText());
Double b= Double.parseDouble(label.getText());
double rezultat=a+b;
label.setText(""+rezultat);
    }                                     

    private void MCActionPerformed(java.awt.event.ActionEvent evt) {                                   
label.setText("0");
    }                                  

    private void MRActionPerformed(java.awt.event.ActionEvent evt) {                                   
    display.setText(label.getText());
    }                                  

    private void MSActionPerformed(java.awt.event.ActionEvent evt) {                                   
label.setText(display.getText());
    }                                  

    private void jednakoActionPerformed(java.awt.event.ActionEvent evt) {                                        
   drugiBroj=Double.parseDouble(display.getText());
      Double rezultat= 0.0;
      
      switch(operacija){
          case Plus:
          rezultat=prviBroj+drugiBroj;
          break;
          
          case Minus:
          rezultat=prviBroj-drugiBroj;
          break;
          
          case Puta:
          rezultat=prviBroj*drugiBroj;
          break;
          
          case Podjeljeno:
           rezultat=prviBroj/drugiBroj;
           break;
      }
      display.setText(""+rezultat);
           
    }                                       

    private void BACKSPACEActionPerformed(java.awt.event.ActionEvent evt) {                                          
    if(display.getText().length()==1){
        
        display.setText("0");
    }else{
        display.setText(display.getText().substring(0,display.getText().length()-1));
    }
    }                                         

    private void briseActionPerformed(java.awt.event.ActionEvent evt) {                                      
    display.setText("0");
    }                                     

    private void DISPLEJActionPerformed(java.awt.event.ActionEvent evt) {                                        
                 
    }                                       

    private void podljeljenoActionPerformed(java.awt.event.ActionEvent evt) {                                            
    operacija=Operacija.Podjeljeno;
      prviBroj=Double.parseDouble(display.getText());
      display.setText("0");
    }                                           

    private void plusActionPerformed(java.awt.event.ActionEvent evt) {                                     
    operacija=Operacija.Plus;
      prviBroj=Double.parseDouble(display.getText());
      display.setText("0");
    }                                    

    private void putaActionPerformed(java.awt.event.ActionEvent evt) {                                     
    operacija=Operacija.Puta;
      prviBroj=Double.parseDouble(display.getText());
      display.setText("0");
    }                                    

    private void minusActionPerformed(java.awt.event.ActionEvent evt) {                                      
 operacija=Operacija.Minus;
      prviBroj=Double.parseDouble(display.getText());
      display.setText("0");
    }                                     

    private void zarezActionPerformed(java.awt.event.ActionEvent evt) {                                      
  upisiBroj(evt);
    }                                     

    private void tockaActionPerformed(java.awt.event.ActionEvent evt) {                                      
 if(!display.getText().contains("."))display.setText(display.getText()+".");
    }                                     

    private void nulaActionPerformed(java.awt.event.ActionEvent evt) {                                     
  upisiBroj(evt);
    }                                    

    private void devetActionPerformed(java.awt.event.ActionEvent evt) {                                      
  upisiBroj(evt);
    }                                     

    private void osamActionPerformed(java.awt.event.ActionEvent evt) {                                     
  upisiBroj(evt);
    }                                    

    private void sedamActionPerformed(java.awt.event.ActionEvent evt) {                                      
  upisiBroj(evt);
    }                                     

    private void sestActionPerformed(java.awt.event.ActionEvent evt) {                                     
  upisiBroj(evt);
    }                                    

    private void petActionPerformed(java.awt.event.ActionEvent evt) {                                    
  upisiBroj(evt);
    }                                   

    private void cetriActionPerformed(java.awt.event.ActionEvent evt) {                                      
  upisiBroj(evt);
    }                                     

    private void triActionPerformed(java.awt.event.ActionEvent evt) {                                    
    upisiBroj(evt);
    }                                   

    private void dvaActionPerformed(java.awt.event.ActionEvent evt) {                                    
    upisiBroj(evt);
    }                                   

    private void jedanActionPerformed(java.awt.event.ActionEvent evt) {                                      
   upisiBroj(evt);
    }                                     
    private void upisiBroj(java.awt.event.ActionEvent evt){
        if(display.getText().startsWith("0")&display.getText().length()==1){
            display.setText("");
        }
     JButton b=(JButton)evt.getSource();  // ovdije smo kastali
     String textDugmeta=b.getText();
     display.setText(display.getText()+textDugmeta);
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        look.setLook(look.windows);
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new Calculator();
            }
        });
    }
}



[Ovu poruku je menjao hyle dana 12.02.2007. u 08:48 GMT+1]
 
Odgovor na temu

djalfirevic

Član broj: 76932
Poruke: 497
*.dynamic.sbb.co.yu.



Profil

icon Re: Pomoc oko ispravka koda-kalkulator11.02.2007. u 21:29 - pre 209 meseci
Druze moze li samo jedna molba... Kada postujes kod, obavezno ga 'umotaj' u
Code:
tagove. Daleko je preglednije, a i kada se uradi copy-paste bude fino tabovano...
 
Odgovor na temu

sale83
Australia
Sydney

Član broj: 41625
Poruke: 729
*.ispone.net.au.



+30 Profil

icon Re: Pomoc oko ispravka koda-kalkulator12.02.2007. u 08:22 - pre 209 meseci
Jos bolje je da UPLODUJE fajlove uz poruku (sve u zip) kad je upitanju DUGACAK kod sa vise klasa....

Poz
sale
Sto mozes danas ne ostavljaj za sutra!
 
Odgovor na temu

[es] :: Java :: Pomoc oko ispravka koda-kalkulator

[ Pregleda: 1858 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.