Solved

2 errors, please help

Posted on 2007-03-21
7
162 Views
Last Modified: 2013-11-23
I get 2 errors at the very end where it wants 2 more "}' expected. And for the life of me I can't find where they go. Can someone end my misery? They are at the very end at "}//end invokeLater and the very last one "}".

import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;

public class WindowsCalcGUI extends javax.swing.JFrame {

    private Button keys [];
    private Panel keypad;
    private TextField lcd;
    private double opl;
    private boolean first;
    private boolean foundkey;
    private boolean clearTex;
    private int lastOp;
    private DecimalFormat calcPattern;
     
    /** Creates new form WindowsCalcGUI */
    public WindowsCalcGUI() {
        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.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
    private void initComponents() {
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jButton15 = new javax.swing.JButton();
        jButton16 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("7");

        jButton2.setText("4");

        jButton3.setText("1");

        jButton4.setText("0");

        jButton5.setText("8");

        jButton6.setText("5");

        jButton7.setText("2");

        jButton8.setText(".");

        jButton9.setText("9");

        jButton10.setText("6");

        jButton11.setText("3");

        jButton12.setText("=");

        jButton13.setText("/");

        jButton14.setText("+");

        jButton15.setText("-");

        jButton16.setText("*");

        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()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 64, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jButton2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)
                            .add(jButton3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)
                            .add(jButton4, 0, 0, Short.MAX_VALUE))
                        .add(16, 16, 16)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jButton5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jButton7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jButton8, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jButton6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(10, 10, 10)
                                .add(jButton12, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(10, 10, 10)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jButton10, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                    .add(jButton11, 0, 0, Short.MAX_VALUE)
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jButton9, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))))
                        .add(23, 23, 23)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(jButton13, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jButton14, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jButton15, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jButton16, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)
                    .add(jButton13, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)
                    .add(jButton9, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)
                    .add(jButton5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 54, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(17, 17, 17)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.BASELINE, jButton14, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.BASELINE, jButton10, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.BASELINE, jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 51, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(org.jdesktop.layout.GroupLayout.BASELINE, jButton6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE))
                .add(15, 15, 15)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.BASELINE, jButton11, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.BASELINE, jButton3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 51, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(org.jdesktop.layout.GroupLayout.BASELINE, jButton7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.BASELINE, jButton15, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE))
                .add(14, 14, 14)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jButton4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
                    .add(jButton16, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
                    .add(jButton12, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
                    .add(jButton8, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE))
                .addContainerGap())
        );
        pack();
    }// </editor-fold>                        
   
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new WindowsCalcGUI().setVisible(true);
            }
   public void actionPerformed(ActionEvent e)
   {
       //menu clicks
       String arg = e.getActionCommand();
       if (arg=="Exit")
           System.exit(0);
       
       if (arg == "Clear")
       {
           clearText = true;
           first = true;
           opl = 0.0;
           lcd.setTest("");
           lcd.requestFocus();
       }
       {
       //buttons clicked
       foundKey = false;
       
       //clicked key
       for (int i=0; i<keys.length && !foundKey; i++);
       {
            if(e.getSource() == keys [i])
            {
                foundKey=true;
                        switch(i)
                        {
                            //number and decimal buttons
                            case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15:
                                if(clearText)
                                {
                                    lcd.setText("");
                                    clearText = false;// !clearText;
                                   
                                    lcd.setText(lcd.getText() + keys[i].getLabel());
                               
                                break;
                               
                        }
                        // buttons operated
                                case 10: case 11: case 12: case 13: case 14:
                                clearText = true;
                               
                            if (first) //first selected
                            {
                                if(lcd.getText().length()==0) opl = 0.0;
                                else opl = Double.parseDouble(lcd.getText());
                               
                                first = false;
                                clearText = true;
                                lastOp = i; // save last
                            }
                            else  // second selected
                                switch(lastOp)
                                {
                                    case 10: // divide function
                                        opl /= Double.parseDouble(lcd.getText());
                                        break;
                                    case 11: // multiply function
                                        opl *= Double.parseDouble(lcd.getText());
                                        break;
                                    case 12: // subtract function
                                        opl -= Double.parseDouble(lcd.getText());
                                        break;
                                    case 13: // addition function
                                        opl += Double.parseDouble(lcd.getText());
                                        //end switch (lastOp)
                                        lcd.setText(calcPattern.format(opl));
                                        clearText = true;
                                        break;{
                                                             if (second) //second selected
                            {
                                if(lcd.getText().length()==0) opl = 0.0;
                                else opl = Double.parseDouble(lcd.getText());
                               
                                first = false;
                                clearText = true;
                                lastOp = i; // save last
                            }
                            else  // second selected
                                switch(lastOp){
                                   
                                }
                                                                                                         
       //buttons clicked
       foundKey = false;
       
       //clicked key
       for (int i=0; i<keys.length && !foundKey; i++);
       {
            if(e.getSource() == keys [i])
            {
                foundKey=true;
                        switch(i)
                        {  
                            //number and decimal buttons
                            case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15:
                                if(clearText)
                                {
                                    lcd.setText("");
                                    clearText = false;// !clearText;
                                   
                                    lcd.setText(lcd.getText() + keys[i].getLabel());
                               
                                break;
                                }
                                {
                                 if(i==12)first = true;//perform operation
                                 
                                 else lastOp = i; //save operation
                                 {  
                                break;                              
                                }//end if
                        }//end for
                        }
            }
       }
                                        }//end break
                                }//end switch
                        }//end switch
            }//end if
       }//end for
       }
   }//end actionPerformed
        }//end invokeLater
       
   
   
       {    
    // Variables declaration - do not modify                    
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton16;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration                  
       }
0
Comment
Question by:jmurguia
  • 2
  • 2
7 Comments
 
LVL 14

Accepted Solution

by:
xberry earned 43 total points
Comment Utility
I did run you code in Eclipse and the error message about the }
disappeared after I had them placed at following points in order to close your class definitions:

1.) after }//end invokeLater

and the

2.) at the very end of your code

but actually, my chain of errors doesn't end with those two } (sorry to say so)

and you really should structure your code and run it through a good debugging tool

0
 
LVL 30

Assisted Solution

by:mayankeagle
mayankeagle earned 41 total points
Comment Utility
>> if (arg=="Exit")
>> System.exit(0);
>> if (arg == "Clear")

You should use .equals () or .equalsIgnoreCase instead of == for comparing strings. That will not give a compilation error and will be even more hard to debug.
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
>> {    
    // Variables declaration - do not modify          

There is no need for a { there
0
 
LVL 20

Assisted Solution

by:gatorvip
gatorvip earned 41 total points
Comment Utility
You need a closing } at the very end of your code, and you need to close out the third switch statement. Good thing you placed comments on the closing brackets, you will see which one is missing.

this part is probably mis-labeled:
{
 if(i==12)first = true;//perform operation
                                 
 else lastOp = i; //save operation
 {  
 break;                              
 }//end if


If you have Notepad++, you can paste your code in there to see how your brackets match up (it makes your life much easier).

On a related note, you may want to restructure your code because it's terrible to read. However, you have
0
 
LVL 20

Expert Comment

by:gatorvip
Comment Utility
oops.... forget about that last part of my message there
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now