Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

2 errors, please help

Posted on 2007-03-21
7
Medium Priority
?
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 14

Accepted Solution

by:
xberry earned 172 total points
ID: 18767165
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:Mayank S
Mayank S earned 164 total points
ID: 18767411
>> 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:Mayank S
ID: 18767420
>> {    
    // Variables declaration - do not modify          

There is no need for a { there
0
 
LVL 20

Assisted Solution

by:gatorvip
gatorvip earned 164 total points
ID: 18770753
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
ID: 18770755
oops.... forget about that last part of my message there
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

618 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