
-----------------------------------
219
Sat Jun 18, 2011 8:00 pm

I need a little help for ready to program java? My program will not compile? Want to help please?
-----------------------------------
It says that The abstract method "void actionPerformed(java.awt.event.ActionEvent $1);", inherited from type "java.awt.event.ActionListener", is not implemented in the non-abstract class "SharifCalc"

I really don't know what to do? Making the layout is being so hard? How can I just make the layout with the buttons and everything? Thanks if you helped!





// The "SharifCalc" class.
import java.awt.*;
import javax.swing.*; // for GUI components
import java.awt.event.*; // for actions to be registered
import java.io.*; // For file input and output
import java.text.*; // For DecimalFormat and NumberFormat
import java.util.*;
import java.awt.event.ActionListener;

public class SharifCalc extends javax.swing.JFrame implements ActionListener
{
    //VARIABLES
    double firstNum, secondNum, answer;
    NumberFormat noFor = new DecimalFormat ("#0.00");

    //declaring panels
    JPanel jpnlTop = new JPanel ();
    JPanel jpnlBottom = new JPanel ();

    //GUI components for input
    JLabel title = new JLabel ("Sharif Calculator");
    JLabel title2 = new JLabel ("Welcome!");

    

    //Constructor
    public SharifCalc (String Title)
    {

        super (Title);
        jpnlTop.add (title);
        jpnlTop.add (title2);

        //sets the font of the titles
        title.setFont (new Font ("SansSerif", Font.BOLD, 22));
        title2.setFont (new Font ("SansSerif", Font.BOLD, 18));


        //sets the layout of the main panel and adds it
        jpnlTop.setLayout (new BoxLayout (jpnlTop, BoxLayout.Y_AXIS));
        jpnlBottom.setLayout (new BoxLayout (jpnlBottom, BoxLayout.X_AXIS));
        getContentPane ().setLayout (new BoxLayout (getContentPane (), BoxLayout.Y_AXIS));
        getContentPane ().add (jpnlTop);
        //background colour
        jpnlTop.setBackground (new Color (112, 190, 254));
        //will exit the program when the X button on the frame is clicked
        setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    }


    // Buttons

    JButton jbtnOne;
    JButton jbtnTwo;
    JButton jbtnThree;
    JButton jbtnFour;
    JButton jbtnFive;
    JButton jbtnSix;
    JButton jbtnSeven;
    JButton jbtnEight;
    JButton jbtnNine;
    JButton jbtnZero;
    JButton jbtnAdd;
    JButton jbtnSubtract;
    JButton jbtnDivide;
    JButton jbtnMultiply;
    JButton jbtnEqual;
    JButton jbtnClear;
    JButton jbtnDecimal;
    JButton jbtnSquare;
    JButton jbtnPercent;

    // TextField

    JTextField jtfDisplay;

    // CalcGui - Consturctor

    public SharifCalc ()
    {
        initComponents ();
        pack ();
    } // CalcGui - Consturctor


    private void initComponents ()
    {


        {

            // Button initilisation

            // Number Button

            jbtnOne = new JButton ("1");
            jbtnTwo = new JButton ("2");
            jbtnThree = new JButton ("3");
            jbtnFour = new JButton ("4");
            jbtnFive = new JButton ("5");
            jbtnSix = new JButton ("6");
            jbtnSeven = new JButton ("7");
            jbtnEight = new JButton ("8");
            jbtnNine = new JButton ("9");
            jbtnZero = new JButton ("0");

            // Operation Button

            jbtnAdd = new JButton ("+");
            jbtnSubtract = new JButton ("-");
            jbtnDivide = new JButton ("/");
            jbtnMultiply = new JButton ("*");
            jbtnEqual = new JButton ("=");
            jbtnClear = new JButton ("C");
            jbtnDecimal = new JButton (".");
            jbtnSquare = new JButton ("S");
            jbtnPercent = new JButton ("%");

            // TextField

            jtfDisplay = new JTextField (" ");
            jtfDisplay.setEnabled (false);

            // Panel Layout


            getContentPane ().setLayout (new GridLayout (4, 2));

            // Window Listener

            addWindowListener (new WindowAdapter ()
            {
                public void windowClosing (WindowEvent evt)
                {
                    System.exit (0);
                }
            }
            );

            // Set jpnlTop

            jpnlTop.setLayout (new GridLayout (1, 1));

            jpnlTop.add (jtfDisplay);

            getContentPane ().add (jpnlTop);


            // Set jpnlBottom

            jpnlBottom.setLayout (new GridLayout (8, 5));

            jpnlBottom.add (jbtnOne);
            jpnlBottom.add (jbtnTwo);
            jpnlBottom.add (jbtnThree);
            jpnlBottom.add (jbtnFour);
            jpnlBottom.add (jbtnFive);
            jpnlBottom.add (jbtnSix);
            jpnlBottom.add (jbtnSeven);
            jpnlBottom.add (jbtnEight);
            jpnlBottom.add (jbtnNine);
            jpnlBottom.add (jbtnZero);
            jpnlBottom.add (jbtnAdd);
            jpnlBottom.add (jbtnSubtract);
            jpnlBottom.add (jbtnDivide);
            jpnlBottom.add (jbtnMultiply);
            jpnlBottom.add (jbtnEqual);
            jpnlBottom.add (jbtnDecimal);
            jpnlBottom.add (jbtnClear);
            jpnlBottom.add (jbtnSquare);
            jpnlBottom.add (jbtnPercent);


            getContentPane ().add (jpnlBottom);

            // Button Declaration

            // Value button

            jbtnOne.addActionListener (this);
            jbtnTwo.addActionListener (this);
            jbtnThree.addActionListener (this);
            jbtnFour.addActionListener (this);
            jbtnFive.addActionListener (this);
            jbtnSix.addActionListener (this);
            jbtnSeven.addActionListener (this);
            jbtnEight.addActionListener (this);
            jbtnNine.addActionListener (this);
            jbtnZero.addActionListener (this);

            // Operation Button

            jbtnAdd.addActionListener (this);
            jbtnSubtract.addActionListener (this);
            jbtnDivide.addActionListener (this);
            jbtnEqual.addActionListener (this);
            jbtnMultiply.addActionListener (this);
            jbtnDecimal.addActionListener (this);
            jbtnClear.addActionListener (this);
            jbtnSquare.addActionListener (this);
            jbtnPercent.addActionListener (this);




        }




        // Place your code here
    } // main method
} // SharifCalc class

-----------------------------------
Tony
Sat Jun 18, 2011 8:31 pm

Re: I need a little help for ready to program java? My program will not compile? Want to help please?
-----------------------------------
Do just what it says
The abstract method "void actionPerformed(java.awt.event.ActionEvent $1);" ... is not implemented in ... class "SharifCalc"
Implement the missing method.
