Parody Tik Tok
Parody Tik Tok

Reputation: 29

how to implement a class that i extended to Frame not JFrame?

i cant implement this class . the plan is after choosing units from the two sub Choice box then the button is clicked a result must appear in cmd. when i compile this class it has an error that says

HarderCode is not abstract and does not override abstract method itemStateChanged(java.awt.event.ItemEvent) in java.awt.event.ItemListener

import java.awt.event.ActionListener;

import java.awt.event.*;

import java.awt.*;

public class HarderCode extends Frame implements ItemListener,ActionListener{


    Choice Cb1;
    Choice Cb2;
    Choice Cb3;

    Label lbl1;
    Label lbl2;
    Label lbl3;
    Label lbl4;
    Label lbl5;

    TextField txt1;
//  TextField txt2;

    Button btn1;

/*  
    public HarderCode(){

        btn1 = new Button(" Click Me ! To Convert ");

        Cb1 = new Choice();
        Cb2 = new Choice();
        Cb3 = new Choice();

        int i;


        String [] Ctgy = {"Select A Category", "Volume", "Length", "Teperature", "Area", "Weigth"};




        for (i = 0; i < Ctgy.length; ++i) {
      Cb1.insert (Ctgy [i], i);
        }
                Cb2.add("Select Unit");
                Cb3.add("Select Unit");



        lbl1 = new Label(" 10000.00 ");
        lbl2 = new Label(" From ");
        lbl3 = new Label(" To ");
        lbl4 = new Label(" Result    :");
        lbl5 = new Label(" Value to be Converted ");

        txt1 = new TextField(7);
//      txt2 = new TextField(7);


        add(lbl1);
        add(lbl2);
        add(lbl3);
        add(lbl4);
        add(lbl5);
        add(txt1);
        add(Cb1);
        add(Cb2);
        add(Cb3);
        add(btn1);

        Cb1.addItemListener (this);
        Cb2.addItemListener (this);
        Cb3.addItemListener (this);
        btn1.addActionListener(this);

    }
    @Override
    public void itemStateChanged(ItemEvent e){

            int Selection;
            int Selection2;
            int Selection3;
        Selection = Cb1.getSelectedIndex();
        Selection2 = Cb2.getSelectedIndex();
        Selection3 = Cb3.getSelectedIndex();



        if(Selection == 0){

            Cb2.removeAll();
            Cb3.removeAll();

            String [] def1 = {"Select Unit",};
            String [] def2 = {"Select Unit",};

            for (int i = 0; i < def1.length; ++i) {
      Cb2.insert (def1 [i], i);
        }

         for (int i = 0; i < def2.length; ++i) {
      Cb3.insert (def2 [i], i);
    }
        }else if(Selection == 1){

                Cb2.removeAll();
                Cb3.removeAll();

        String [] temp1 = {"Select Unit", "Celsius", "Fahrenheit", "Kelvin"};
        String [] temp2 = {"Select Unit", "Celsius", "Fahrenheit", "Kelvin"};


                for (int i = 0; i < temp1.length; ++i) {
             Cb2.insert (temp1 [i], i);
            }

                 for (int i = 0; i < temp2.length; ++i) {
               Cb3.insert (temp2 [i], i);
            }
        }
    }

    public void paint(Graphics HarderCode){

        this.Cb1.setSize(270,20);//
        this.Cb1.setLocation(10,40);//

        this.Cb2.setSize(130,2);//
        this.Cb2.setLocation(10,95);//

        this.Cb3.setSize(130,2);//
        this.Cb3.setLocation(150,95);//

        this.lbl1.setSize(100,20);//
        this.lbl1.setLocation(150,230);//

        this.lbl2.setSize(50,20);//
        this.lbl2.setLocation(10,70);//

        this.lbl3.setSize(50,20);//
        this.lbl3.setLocation(150,70);//

        this.lbl5.setSize(130,20);//
        this.lbl5.setLocation(10,130);//

        this.txt1.setSize(130,20);//
        this.txt1.setLocation(150,130);//

        this.btn1.setSize(270,60);//
        this.btn1.setLocation(10,160);//

        this.lbl4.setSize(80,20);//
        this.lbl4.setLocation(40,230);//
    }

    public static void main (String[] args) {


        HarderCode HC = new HarderCode();

        HC.setTitle("MultiConverter Ver1.0");
        HC.setSize(290,300);
        HC.setResizable(false);
        HC.setVisible(true);

}
*/  
}

Upvotes: 0

Views: 683

Answers (2)

Jakub Zaverka
Jakub Zaverka

Reputation: 8874

It does nothing to do with being Frame or JFrame. You declared your class to implement ItemListener, but you did not implement its itemStateChanged method.

Upvotes: 1

Rahul Borkar
Rahul Borkar

Reputation: 2762

It should work, there is nothing wrong with the code. Thing is you are implementing ItemListener interface and if you have implemented any interface you must implement all methods of that interface. itemStateChanged is one of the method of ItemListener. So you must override it and provide the implementation for same in HarderCode class.

Upvotes: 1

Related Questions