Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem to compiling this code im new to java and did'nt understand waht is problem please help me code is attached.
Java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Cal implements ActionListener{
JFrame frm;
Container c;
JLabel lb1,lb2,lb3;
JTextField tf1,tf2,tf3;
JButton exit,add,clear;
public void iniGUi(){
	
		frm=new JFrame("Calculator");
		c=frm.getContentPane();
		c.setLayout(new FlowLayout());
		lb1=new JLabel("Enter First Number");
		lb2=new JLabel("Enter Second Number");
		lb3=new JLabel("Result");
		tf1=new JTextField(10);
		tf2=new JTextField(10);
		tf3=new JTextField(10);
		exit=new JButton("Exit");
		clear=new JButton("Clear");
		add=new JButton("Add");
		c.add(lb1);
		c.add(tf1);
		c.add(lb2);
		c.add(tf2);
		c.add(lb3);
		c.add(tf3);
		c.add(add);
		c.add(clear);
		c.add(exit);
		add.addActionListener(this);
		clear.addActionListener(this);
		exit.addActionListener(this);
		frm.setVisible(true);
		frm.setSize(800,300);
		frm.setDefaultCloseOperation(frm.EXIT_ON_CLOSE);
}
public Cal(){
	iniGUi();
	}
public void actionPerformed(ActionEvent e){
System.exit(0);
}
public void actionPerformed(ActionEvent e){
	tf1.setText("");
	tf2.setText("");
	tf3.setText("");
	}
public void actionPerformed(ActionEvent e){
	double a,b,c;
	a=Double.parseDouble(tf1.getText());
	b=Double.parseDouble(tf2.getText());
	c=a+b;
	tf3.setText(String.valueOf(c));
	}
	public static void main (String[] args) {
	Cal ob=new Cal();
}
}

"Error is actionPerformed is already defined in class Cal"
Posted

1 solution

You have
Java
public void actionPerformed(ActionEvent e)
defined twice, with 2 different implementations.

[ha ha] No, actually you have defined it 3 times.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900