Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java eventhandler
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.
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 16-Mar-13 9:37am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You have
public void actionPerformed(ActionEvent e)
defined twice, with 2 different implementations.
 
[ha ha] No, actually you have defined it 3 times.
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 16 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100