0

I have looked all over and i could not find a solution to my problem. When I run this is get

The type javax.swing.JComponent cannot be resolved. It is indirectly referenced from required .class files

I am at my wits end, please help.

    import java.awt.*;
    import javax.swing.*;
    import java.awt.GridLayout;

    public class calc extends JFrame
    {
        JTextField display;
        JPanel buttonPanel;
        JButton buttons[];

        calc()
        {
            super("Calculator");

            display = new JTextField();
            buttons = new JButton[16];
            buttons[0] = new JButton("7");
            buttons[1] = new JButton("8");  
            buttons[2] = new JButton("9");
            buttons[3] = new JButton("/");  
            buttons[4] = new JButton("4");
            buttons[5] = new JButton("5");  
            buttons[6] = new JButton("6");
            buttons[7] = new JButton("*");  
            buttons[8] = new JButton("1");
            buttons[9] = new JButton("2");  
            buttons[10] = new JButton("3");
            buttons[11] = new JButton("-"); 
            buttons[12] = new JButton("0");
            buttons[13] = new JButton("."); 
            buttons[14] = new JButton("=");
            buttons[15] = new JButton("+");     

            buttonPanel = new JPanel();
            buttonPanel.setLayout(new GridLayout(4,4,5,5));

            for(int i = 0, j = 0; i < 16; i++)
            {
                buttons[i].setFont(new Font("SanSerif", Font.BOLD, 16));
                if (i % 4 == 0)
                    j++;
                if(j++ % 2 == 0)
                {
                    buttons[i].setBackground(Color.BLACK);
                    buttons[i].setForeground(Color.WHITE);
                } else {
                    buttons[i].setBackground(Color.WHITE);
                    buttons[i].setForeground(Color.BLACK);
                }

                buttonPanel.add(buttons[i]);
             }
            add(display, BorderLayout.NORTH);
            add(buttonPanel, BorderLayout.CENTER);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(250, 250);
            setVisible(true);
        }

        public static void main(String[] args) 
        {
            calc Calc = new calc();
        }
    }
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

0 Answers0