0
import java.awt.*;
import java.awt.event.*;
class Calc extends Frame implements ActionListener
{
    Calc()
 {
    TextField t1,t2,t3;
    t1=new TextField();
    t2=new TextField(),
    t3=new TextField();
    Label l1=new Label("Number one"),l2=new Label("Number two"),l3=new Label("Answer :");
    Button b1=new Button("Add"),b2=new Button("Subtract"),b3=new Button("Exit");
    add(l1);
    add(l2);
    add(l3);
    add(t1);
    add(t2);
    add(t3);
    add(b1);
    add(b2);
    add(b3);
    setLayout("500");
    setVisible(True);
    setSize(400,350);
    setBackground(Color.GREEN);
    b1.addActionListener(this);
    b2.addActionListener(this);
    b3.addActionListener(this);
 }  
    public void actionPerfomed(ActionEvent e)
    {
        int n1=Integer.parseInt(t1.getText());
        int n2=Integer.parseInt(t2.getText());
        if(e.getSource==b1)
        {
            t3.setText(String.valueOf(n1+n2));
        }
        else if(e.getSource==b2)
        {
            t3.setText(String.valueOf(n1-n2));
        }
        else if(e.getSource==b3)
        System.exit(0);
    }
}
class GUIAmain
{
    public static void main(String args[])
    {
        new Calc();
    }
}

This is the error I'm getting:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
        Syntax error on tokens, delete these tokens
        The type Calc must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
        The method setLayout(LayoutManager) in the type Container is not applicable for the arguments (int)   
        True cannot be resolved to a variable
        t1 cannot be resolved
        t2 cannot be resolved
        getSource cannot be resolved or is not a field
        b1 cannot be resolved to a variable
        t3 cannot be resolved
        getSource cannot be resolved or is not a field
        b2 cannot be resolved to a variable
        t3 cannot be resolved
        getSource cannot be resolved or is not a field
        b3 cannot be resolved to a variable
        The method Exit(int) is undefined for the type System

        at Calc.<init>(Calc.java:1)
        at GUIAmain.main(GuiAmain.java:50)
khelwood
  • 52,115
  • 13
  • 74
  • 94

0 Answers0