guys i'm having problem with ActionListener can anyone please tell me some solution!!!
i want to make a calculator using swing!!!
m using netbeans 7.2 for this program it'll give an error that class is not abstract so you cannot implements abstract ActionListener!!
after that i'll use notepad to edit it and then wen i'l compile it it'll give 25 ERRORS
cannot find symbol
.addActionListener(this);
please help me !! i'm new to java and m unable to assign actions the GUI i've made!!! please solve my problem!! ASAP!!!
i want to make a calculator using swing!!!
Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**
*
* @author SudhiR
*/
class Calci implements ActionListener
{
char op;
String value="",cv="";
int ctr=0;
Double v1,v2,ans;
Frame fr;
MenuBar mBar;
Menu f,e;
MenuItem q,c,p;
JButton num0,num1,num2,num3,num4,num5,num6,num7,num8,num9,bDot,bAdd,bSub,bDiv,bMul,bSqrt,bPer,clear,bCE,back,equals,inv;
TextField txt;
Panel p1,p2,p3,p4,p5;
Calci(){
fr=new Frame("Calculator");
fr.setDefaultCloseOperation(Frame.EXIT_ON_CLOSE);
txt=new TextField(35);
txt.setText("0");
txt.setEnabled(false);
mBar=new MenuBar();
f=new Menu("File");
e=new Menu("Edit");
q=new MenuItem("Quit");
c=new MenuItem("Copy");
p=new MenuItem("Paste");
num0=new JButton("0");
num1=new JButton("1");
num2=new JButton("2");
num3=new JButton("3");
num4=new JButton("4");
num5=new JButton("5");
num6=new JButton("6");
num7=new JButton("7");
num8=new JButton("8");
num9 =new JButton("9");
bAdd=new JButton("+");
bSub=new JButton("-");
bDiv=new JButton("/");
bMul=new JButton("*");
bSqrt=new JButton("Sqrt");
bPer=new JButton("%");
clear=new JButton("C");
bCE=new JButton("CE");
back=new JButton("BackSpace");
equals=new JButton("=");
bDot=new JButton(".");
inv=new JButton("+/-");
p1=new Panel();
p2=new Panel();
p3=new Panel();
p4=new Panel();
p5=new Panel();
mBar.add(f);
mBar.add(e);
f.add(q);
e.add(c);
e.add(p);
p1.add(back);
p1.add(clear);
p1.add(bCE);
p2.add(num7);
p2.add(num8);
p2.add(num9);
p2.add(bAdd);
p2.add(bMul);
p3.add(num4);
p3.add(num5);
p3.add(num6);
p3.add(bSub);
p3.add(bDiv);
p4.add(num1);
p4.add(num2);
p4.add(num3);
p4.add(bDot);
p4.add(inv);
p5.add(num0);
p5.add(equals);
p5.add(bSqrt);
p5.add(bPer);
p1.setLayout(new GridLayout(1,3,2,2));
p2.setLayout(new GridLayout(1,5,2,2));
p3.setLayout(new GridLayout(1,5,2,2));
p4.setLayout(new GridLayout(1,5,2,2));
p5.setLayout(new GridLayout(1,4,2,2));
fr.setLayout(new GridLayout(6,1));
fr.setMenuBar(mBar);
fr.setResizable(false);
fr.setSize(300,300);
fr.add(txt);
fr.add(p1);
fr.add(p2);
fr.add(p3);
fr.add(p4);
fr.add(p5);
fr.setVisible(true);
}
public void op()
{
num0.addActionlistener(new ActionListener());
num0.addActionlistener(this);
num1.addActionlistener(this);
num2.addActionlistener(this);
num3.addActionlistener(this);
num4.addActionlistener(this);
num5.addActionlistener(this);
num6.addActionlistener(this);
num7.addActionlistener(this);
num8.addActionlistener(this);
num9.addActionlistener(this);
bAdd.addActionlistener(this);
bSub.addActionlistener(this);
bMul.addActionlistener(this);
bDiv.addActionlistener(this);
bSqrt.addActionlistener(this);
bPer.addActionlistener(this);
equals.addActionlistener(this);
clear.addActionlistener(this);
back.addActionlistener(this);
bCE.addActionlistener(this);
inv.addActionlistener(this);
bDot.addActionlistener(this);
q.addActionlistener(this);
c.addActionlistener(this);
p.addActionlistener(this);
}
//Menu Items//
if(ae.getSource()==q)
{
System.exit(0);
}
else if(ae.getSource()==c)
{
cv+=value;
}
else if(ae.getSource()==p)
{
value+=cv;
}
}
m using netbeans 7.2 for this program it'll give an error that class is not abstract so you cannot implements abstract ActionListener!!
after that i'll use notepad to edit it and then wen i'l compile it it'll give 25 ERRORS
cannot find symbol
.addActionListener(this);
please help me !! i'm new to java and m unable to assign actions the GUI i've made!!! please solve my problem!! ASAP!!!