We are asked to create a calculator but before I do that I must correct the codes given in order for me to know what I must add in my calculator but I do not know how to solve the "void cannot be referenced " error...how can I do that?
here's the code that I made....the error is line 80 and 87
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Button extends JFrame implements ActionListener
{
private static int width=600;
private static int height=300;
private JLabel[] labelJL = new JLabel[3];
private JTextField[] textJT = new JTextField[3];
private JButton[] AddClearExit = new JButton[3];
public Button()
{
Container pane = getContentPane();
setTitle("USING BUTTON EVENT");
setSize(width,height);
setLayout(null);
labelJL[0] = new JLabel("FIRST NUMBER",0);
labelJL[0].setLocation(150,20);
labelJL[0].setSize(100,20);
pane.add(labelJL[0]);
textJT[0] = new JTextField();
textJT[0].setLocation(260,20);
textJT[0].setSize(200,20);
pane.add(textJT[0]);
labelJL[1] = new JLabel("SECOND NUMBER",0);
labelJL[1].setLocation(150,50);
labelJL[1].setSize(100,20);
pane.add(labelJL[1]);
textJT[1] = new JTextField();
textJT[1].setLocation(260,50);
textJT[1].setSize(200,20);
pane.add(textJT[1]);
labelJL[2] = new JLabel("Total Sum",0);
labelJL[2].setLocation(150,80);
labelJL[2].setSize(100,20);
pane.add(labelJL[2]);
textJT[2] = new JTextField();
textJT[2].setLocation(260,80);
textJT[2].setSize(200,20);
textJT[2].setEditable(false);
pane.add(textJT[2]);
AddClearExit[0] = new JButton("Sum");
AddClearExit[0].setLocation(50,150);
AddClearExit[0].setSize(150,20);
AddClearExit[0].addActionListener(this);
pane.add(AddClearExit[0]);
AddClearExit[1] = new JButton("Clear");
AddClearExit[1].setLocation(210,150);
AddClearExit[1]. setSize(150,20);
AddClearExit[1].addActionListener(this);
pane.add(AddClearExit[1]);
AddClearExit[2] = new JButton("Exit");
AddClearExit[2].setLocation(370,150);
AddClearExit[2].setSize(150,20);
AddClearExit[2].addActionListener(this);
pane.add(AddClearExit[2]);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ae)
{
String temp = "";
long fn=0, sn=0;
try
{
fn=Long.parseLong(textJT[0].getText());
sn=Long.parseLong(textJT[0].getText());
}
catch (Exception ne)
{
for(int x=0;x<3;textJT[x].setText(temp).x++);
}
if(ae.getActionCommand().equals("Sum"))
temp+=sum(fn,sn);
if(ae.getActionCommand().equals("Clear"))
for(int x=0;x<3;textJT[x].setText(temp).x++);
if(ae.getActionCommand().equals("Exit"))
dispose();
textJT[2].setText(temp);
}
public long sum(long x,long y)
{
return x+y;
}
public static void main (String args[])
{
new Button();
}
}
thank you for the help......