jmurguia
asked on
2 errors, please help
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(j avax.swing .WindowCon stants.EXI T_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.GroupL ayout layout = new org.jdesktop.layout.GroupL ayout(getC ontentPane ());
getContentPane().setLayout (layout);
layout.setHorizontalGroup(
layout.createParallelGroup (org.jdesk top.layout .GroupLayo ut.LEADING )
.add(layout.createSequenti alGroup()
.addContainerGap()
.add(layout.createParallel Group(org. jdesktop.l ayout.Grou pLayout.LE ADING)
.add(jTextField1, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 333, Short.MAX_VALUE)
.add(org.jdesktop.layout.G roupLayout .TRAILING, layout.createSequentialGro up()
.add(layout.createParallel Group(org. jdesktop.l ayout.Grou pLayout.LE ADING)
.add(jButton1, org.jdesktop.layout.GroupL ayout.PREF ERRED_SIZE , 64, org.jdesktop.layout.GroupL ayout.PREF ERRED_SIZE )
.add(jButton2, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 64, Short.MAX_VALUE)
.add(jButton3, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 64, Short.MAX_VALUE)
.add(jButton4, 0, 0, Short.MAX_VALUE))
.add(16, 16, 16)
.add(layout.createParallel Group(org. jdesktop.l ayout.Grou pLayout.TR AILING)
.add(jButton5, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 70, Short.MAX_VALUE)
.add(org.jdesktop.layout.G roupLayout .LEADING, jButton7, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 70, Short.MAX_VALUE)
.add(org.jdesktop.layout.G roupLayout .LEADING, jButton8, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 70, Short.MAX_VALUE)
.add(org.jdesktop.layout.G roupLayout .LEADING, jButton6, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 70, Short.MAX_VALUE))
.addPreferredGap(org.jdesk top.layout .LayoutSty le.RELATED )
.add(layout.createParallel Group(org. jdesktop.l ayout.Grou pLayout.LE ADING)
.add(layout.createSequenti alGroup()
.add(10, 10, 10)
.add(jButton12, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 80, Short.MAX_VALUE))
.add(layout.createSequenti alGroup()
.add(10, 10, 10)
.add(layout.createParallel Group(org. jdesktop.l ayout.Grou pLayout.LE ADING)
.add(jButton10, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 80, Short.MAX_VALUE)
.add(jButton11, 0, 0, Short.MAX_VALUE)
.add(org.jdesktop.layout.G roupLayout .TRAILING, jButton9, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 80, Short.MAX_VALUE))))
.add(23, 23, 23)
.add(layout.createParallel Group(org. jdesktop.l ayout.Grou pLayout.TR AILING, false)
.add(jButton13, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, Short.MAX_VALUE)
.add(jButton14, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, Short.MAX_VALUE)
.add(jButton15, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, Short.MAX_VALUE)
.add(jButton16, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 70, Short.MAX_VALUE))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup (org.jdesk top.layout .GroupLayo ut.LEADING )
.add(layout.createSequenti alGroup()
.addContainerGap()
.add(jTextField1, org.jdesktop.layout.GroupL ayout.PREF ERRED_SIZE , org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, org.jdesktop.layout.GroupL ayout.PREF ERRED_SIZE )
.addPreferredGap(org.jdesk top.layout .LayoutSty le.RELATED )
.add(layout.createParallel Group(org. jdesktop.l ayout.Grou pLayout.BA SELINE)
.add(jButton1, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 54, Short.MAX_VALUE)
.add(jButton13, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 54, Short.MAX_VALUE)
.add(jButton9, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 54, Short.MAX_VALUE)
.add(jButton5, org.jdesktop.layout.GroupL ayout.PREF ERRED_SIZE , 54, org.jdesktop.layout.GroupL ayout.PREF ERRED_SIZE ))
.add(17, 17, 17)
.add(layout.createParallel Group(org. jdesktop.l ayout.Grou pLayout.LE ADING)
.add(org.jdesktop.layout.G roupLayout .BASELINE, jButton14, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 51, Short.MAX_VALUE)
.add(org.jdesktop.layout.G roupLayout .BASELINE, jButton10, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 51, Short.MAX_VALUE)
.add(org.jdesktop.layout.G roupLayout .BASELINE, jButton2, org.jdesktop.layout.GroupL ayout.PREF ERRED_SIZE , 51, org.jdesktop.layout.GroupL ayout.PREF ERRED_SIZE )
.add(org.jdesktop.layout.G roupLayout .BASELINE, jButton6, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 51, Short.MAX_VALUE))
.add(15, 15, 15)
.add(layout.createParallel Group(org. jdesktop.l ayout.Grou pLayout.LE ADING)
.add(org.jdesktop.layout.G roupLayout .BASELINE, jButton11, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 51, Short.MAX_VALUE)
.add(org.jdesktop.layout.G roupLayout .BASELINE, jButton3, org.jdesktop.layout.GroupL ayout.PREF ERRED_SIZE , 51, org.jdesktop.layout.GroupL ayout.PREF ERRED_SIZE )
.add(org.jdesktop.layout.G roupLayout .BASELINE, jButton7, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 51, Short.MAX_VALUE)
.add(org.jdesktop.layout.G roupLayout .BASELINE, jButton15, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 51, Short.MAX_VALUE))
.add(14, 14, 14)
.add(layout.createParallel Group(org. jdesktop.l ayout.Grou pLayout.BA SELINE)
.add(org.jdesktop.layout.G roupLayout .LEADING, jButton4, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 49, Short.MAX_VALUE)
.add(jButton16, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 49, Short.MAX_VALUE)
.add(jButton12, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 49, Short.MAX_VALUE)
.add(jButton8, org.jdesktop.layout.GroupL ayout.DEFA ULT_SIZE, 49, Short.MAX_VALUE))
.addContainerGap())
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invoke Later(new Runnable() {
public void run() {
new WindowsCalcGUI().setVisibl e(true);
}
public void actionPerformed(ActionEven t 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.get Text());
first = false;
clearText = true;
lastOp = i; // save last
}
else // second selected
switch(lastOp)
{
case 10: // divide function
opl /= Double.parseDouble(lcd.get Text());
break;
case 11: // multiply function
opl *= Double.parseDouble(lcd.get Text());
break;
case 12: // subtract function
opl -= Double.parseDouble(lcd.get Text());
break;
case 13: // addition function
opl += Double.parseDouble(lcd.get Text());
//end switch (lastOp)
lcd.setText(calcPattern.fo rmat(opl)) ;
clearText = true;
break;{
if (second) //second selected
{
if(lcd.getText().length()= =0) opl = 0.0;
else opl = Double.parseDouble(lcd.get Text());
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
}
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(j
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.GroupL
getContentPane().setLayout
layout.setHorizontalGroup(
layout.createParallelGroup
.add(layout.createSequenti
.addContainerGap()
.add(layout.createParallel
.add(jTextField1, org.jdesktop.layout.GroupL
.add(org.jdesktop.layout.G
.add(layout.createParallel
.add(jButton1, org.jdesktop.layout.GroupL
.add(jButton2, org.jdesktop.layout.GroupL
.add(jButton3, org.jdesktop.layout.GroupL
.add(jButton4, 0, 0, Short.MAX_VALUE))
.add(16, 16, 16)
.add(layout.createParallel
.add(jButton5, org.jdesktop.layout.GroupL
.add(org.jdesktop.layout.G
.add(org.jdesktop.layout.G
.add(org.jdesktop.layout.G
.addPreferredGap(org.jdesk
.add(layout.createParallel
.add(layout.createSequenti
.add(10, 10, 10)
.add(jButton12, org.jdesktop.layout.GroupL
.add(layout.createSequenti
.add(10, 10, 10)
.add(layout.createParallel
.add(jButton10, org.jdesktop.layout.GroupL
.add(jButton11, 0, 0, Short.MAX_VALUE)
.add(org.jdesktop.layout.G
.add(23, 23, 23)
.add(layout.createParallel
.add(jButton13, org.jdesktop.layout.GroupL
.add(jButton14, org.jdesktop.layout.GroupL
.add(jButton15, org.jdesktop.layout.GroupL
.add(jButton16, org.jdesktop.layout.GroupL
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup
.add(layout.createSequenti
.addContainerGap()
.add(jTextField1, org.jdesktop.layout.GroupL
.addPreferredGap(org.jdesk
.add(layout.createParallel
.add(jButton1, org.jdesktop.layout.GroupL
.add(jButton13, org.jdesktop.layout.GroupL
.add(jButton9, org.jdesktop.layout.GroupL
.add(jButton5, org.jdesktop.layout.GroupL
.add(17, 17, 17)
.add(layout.createParallel
.add(org.jdesktop.layout.G
.add(org.jdesktop.layout.G
.add(org.jdesktop.layout.G
.add(org.jdesktop.layout.G
.add(15, 15, 15)
.add(layout.createParallel
.add(org.jdesktop.layout.G
.add(org.jdesktop.layout.G
.add(org.jdesktop.layout.G
.add(org.jdesktop.layout.G
.add(14, 14, 14)
.add(layout.createParallel
.add(org.jdesktop.layout.G
.add(jButton16, org.jdesktop.layout.GroupL
.add(jButton12, org.jdesktop.layout.GroupL
.add(jButton8, org.jdesktop.layout.GroupL
.addContainerGap())
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invoke
public void run() {
new WindowsCalcGUI().setVisibl
}
public void actionPerformed(ActionEven
{
//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()=
else opl = Double.parseDouble(lcd.get
first = false;
clearText = true;
lastOp = i; // save last
}
else // second selected
switch(lastOp)
{
case 10: // divide function
opl /= Double.parseDouble(lcd.get
break;
case 11: // multiply function
opl *= Double.parseDouble(lcd.get
break;
case 12: // subtract function
opl -= Double.parseDouble(lcd.get
break;
case 13: // addition function
opl += Double.parseDouble(lcd.get
//end switch (lastOp)
lcd.setText(calcPattern.fo
clearText = true;
break;{
if (second) //second selected
{
if(lcd.getText().length()=
else opl = Double.parseDouble(lcd.get
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
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oops.... forget about that last part of my message there
// Variables declaration - do not modify
There is no need for a { there