我看了一遍,我无法找到问题的解决方案。当我运行时,这是
无法解析javax.swing.JComponent类型。它是从所需的.class文件间接引用的
我在我的智慧结束,请帮助。
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();
}
}