Hey I want to add the following method...
private static double Calculations(String Operator) { return }
... to this program as follows (down at the bottom of this snippet)
import javax.swing.*; import java.awt.event.*; import java.awt.*; class MyFrame extends JFrame { JTextField ScreenOut; JTextField ScreenIn; public MyFrame() { //frame settings setVisible (true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("trololo"); setLocation(300,300); setSize(300, 300); //declarations JButton[][] Keypad = new JButton[4][4]; String[][] KeypadLabels = {{"7","4","1","0"},{"8","5","2","C"},{"9","6","3","!"},{"+","-","*","="}}; JMenuBar Toolbar = new JMenuBar(); JMenu Options = new JMenu("Options"); JPanel Section1 = new JPanel(); JPanel Section2 = new JPanel(); JPanel Section3 = new JPanel(); //containers java.awt.Container c = getContentPane(); c.setLayout(new java.awt.FlowLayout()); ScreenOut = new JTextField("", 15); ScreenIn = new JTextField("", 15); Section1.setLayout(new java.awt.FlowLayout()); Section1.add(ScreenIn); Section2.setLayout(new java.awt.GridLayout(4,4)); Section3.setLayout(new java.awt.FlowLayout()); Section3.add(ScreenOut); c.add(Section1); c.add(Section2); c.add(Section3); Toolbar.add(Options); setJMenuBar(Toolbar); //keypad for (int col =0; col<4;col++) { for (int row = 0; row<4;row++) { Keypad[col][row] = new JButton(""); Section2.add(Keypad[col][row]);; Keypad[col][row].setLabel(KeypadLabels[row][col]); } } //add functionality to numbers for (int col=0;col<3;col++) { for (int row=0; row<3;row++) { Keypad[col][row].addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { JButton b = (JButton) e.getSource(); String Input = b.getLabel(); String Original = ScreenIn.getText(); ScreenIn.setText(Original + Input); } }); } } Keypad[3][0].addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String Input = "0"; String Original = ScreenIn.getText(); ScreenIn.setText(Original + "0"); } } ); //add functionailty to operators for (int count=0; count<4; count++) { Keypad[count][3].addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { JButton b = (JButton) e.getSource(); String s = b.getLabel(); // Calculations(s); } } ) ; } } //// private static double Calculations(String Operator) //// { //// return //// } //this is line 109 }//this is line 111
class calculator { public static void main(String Args[]) { MyFrame f1 = new MyFrame(); } }
Whenever I uncomment the method I get the following error
I don't understand why though, whats wrong?--------------------Configuration: <Default>--------------------
C:\Users\Peter\Documents\Peter\University\CSC 1011\Calculator\MyFrame.java:109: illegal start of expression
}
^
C:\Users\Peter\Documents\Peter\University\CSC 1011\Calculator\MyFrame.java:111: reached end of file while parsing
}
Process completed.
Thanks in advance