im currently building a game who wants to be a millionaire..the interface is already done but there was an error..there was an incompatible types exception..here is my code..it says found java.lang.String but expected java.awt.event.ActionEvent..help please

public class MillionaireBoard extends JFrame implements ActionListener
{

    private MoneyLabels a;
    private JLabel A;
    private JPanel b;
    private JPanel B;
    private JButton c[];
    private String C[] = {
        "A", "B", "C", "D"
    };
    private JLabel d;
    private JButton D;
    private JPanel e;
    private int E;

    public MillionaireBoard()
    {
        super("Who Wants to Be a Millionaire ?");
        a = new MoneyLabels(1);
        A = new JLabel();
        String as[] = new String[5];
        as[0] = "Who is the current president of the USA?";
        as[1] = "George Bush";
        as[2] = "Prince Charles";
        as[3] = "Micheal Jordan";
        as[4] = "Barak Obama";
        char ac[] = new char[15];
        ac[0] = 'D';
        ac[1] = 'D';
        ac[2] = 'D';
        ac[3] = 'D';
        ac[4] = 'D';
        ac[5] = 'D';
        ac[6] = 'D';
        ac[7] = 'D';
        ac[8] = 'D';
        ac[9] = 'D';
        ac[10] = 'D';
        ac[11] = 'D';
        ac[12] = 'D';
        ac[13] = 'D';
        ac[14] = 'D';
        b = new JPanel(new BorderLayout());
        B = new JPanel(new GridLayout(2, 2));
        c = new JButton[4];
        d = new JLabel();
        D = new JButton();
        e = new JPanel(new BorderLayout(0, 0));
        E = 1;
        getContentPane().setLayout(new BorderLayout(0, 0));
        for(int i = 0; i < 4; i++)
        {
            c[i] = new JButton();
            c[i].setActionCommand(C[i]);
            c[i].setHorizontalAlignment(2);
            c[i].setForeground(Color.white);
            c[i].setBackground(Color.blue.darker());
            c[i].addActionListener(this);
            B.add(c[i]);
            B.setPreferredSize(new Dimension(500, 50));
        }

        d.setForeground(Color.white);
        d.setBackground(Color.green.darker());
        d.setOpaque(true);
        b.add(B, "South");
        A.setBackground(Color.cyan.darker());
        A.setOpaque(true);
        A.setForeground(Color.white);
        A.setHorizontalAlignment(0);
        A.setHorizontalTextPosition(0);
        A.setVerticalTextPosition(3);
        D.setBackground(Color.green);
        D.setForeground(Color.red.darker());
        e.add(d);
        e.add(D, "East");
        b.add(e, "Center");
        D.addActionListener(new GameButton(this));
        b.setPreferredSize(new Dimension(500, 100));
        getContentPane().add(A, "Center");
        getContentPane().add(b, "South");
        getContentPane().add(a, "East");
        a();
    }

    private void a()
    {
        A.setIcon(new ImageIcon("images/mill.jpg"));
        A.setText(GameUpdate.a);
        C();
        d.setForeground(Color.red.darker());
        d.setText("Click the start button to start the game");
        D.setText("start");
    }

    private void A()
    {
        QuestionSet.b = 0;
        a(QuestionSet.b());
        E = 0;
        a.c();
        a.a();
        A.setIcon(new ImageIcon("images/mill.jpg"));
        String s = "Question " + (E + 1) + " for " + a.B() + "!";
        A.setText(s);
        D.setText("quit");
    }

    private void b()
    {
        String s = a.A();
        A.setIcon(null);
        A.setText(GameUpdate.a(s));
        C();
        D.setText("restart");
        d.setForeground(Color.red.darker());
        d.setText("Click the restart button for a new game");
    }

    private void B()
    {
        String s = a.b();
        A.setIcon(null);
        A.setText(GameUpdate.A(s));
        C();
        D.setText("restart");
        d.setForeground(Color.red.darker());
        d.setText("Click the restart button for a new game");
    }

    private void c()
    {
        D();
        A.setIcon(new ImageIcon("images/mill.jpg"));
        String s = "Question " + (E + 1) + " for " + a.B() + "!";
        A.setText(s);
        D.setText("quit");
    }

    private void a(String as[])
    {
        d.setForeground(Color.white);
        d.setText("<html><h2>" + as[0] + "</h2></html>");
        d.setEnabled(true);
        for(int i = 1; i <= 4; i++)
        {
            c[i - 1].setText(C[i - 1] + ":   " + as[i]);
            c[i - 1].setEnabled(true);
        }

    }

    private void C()
    {
        d.setText("");
        for(int i = 1; i <= 4; i++)
        {
            c[i - 1].setText("");
            c[i - 1].setEnabled(false);
        }

    }

    private void d()
    {
        if(E == 14)
        {
            A.setText("<html><h1>Congratulations!</h1><h1>You becomes a millionaire!</h1></html");
            A.setIcon(null);
            D.setText("restart");
            C();
            d.setForeground(Color.red.darker());
            d.setText("Click the restart button for a new game");
            return;
        } else
        {
            A.setText(GameUpdate.A);
            A.setIcon(null);
            C();
            D.setText("next");
            d.setForeground(Color.red.darker());
            d.setText("Click the next button for next question");
            return;
        }
    }

    private void D()
    {
        E++;
        a.a();
        QuestionSet.a();
        a(QuestionSet.b());
        D.setText("quit");
    }

    public void actionPerformed(ActionEvent actionevent)
    {
        actionevent = actionevent.getActionCommand();//incompatible types occur
        if(actionevent.equals(QuestionSet.A()))
        {
            d();
        } else
        {
            B();
        }
    }
    static void a(MillionaireBoard b1)
    {
        b1.A();
    }
    static void A(MillionaireBoard b1)
    {
        b1.b();
    }
    static void b(MillionaireBoard b1)
    {
        b1.c();
    }
}

Recommended Answers

All 2 Replies

getActionCommand returns a String - the name of the command.
You try to assign that to actionevent - a parameter whose type is ActionEvent, and you can't assign a String to an ActionEvent.
You probably want to define a new String here, as in
String actionEventName = actionevent.getActionCommand();
then use that String in the subsequent code (although I haven't worked out how line 200 works, so I may have missed something here).

nice..tnx James..it solved my problem..ehehe..^_^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.