对于基本的课程作业,我们必须使JUST成为基本计算器的GUI,但是有3个错误一直困扰着我,而对于我的生活,我无法弄明白。
C:\Users\Novus\Desktop\STC Notes\OO Scripts\CalcGUI.java:62: error: no suitablemethod found for add(String,GridLayout)
Mathpane.add("Center", Numgrid);
^
method Container.add(String,Component) is not applicable
(argument mismatch; GridLayout cannot be converted to Component)
method Container.add(Component,int) is not applicable
(argument mismatch; String cannot be converted to Component)
method Container.add(Component,Object) is not applicable
(argument mismatch; String cannot be converted to Component)
C:\Users\Novus\Desktop\STC Notes\OO Scripts\CalcGUI.java:63: error: no suitable method found for add(String,GridLayout)
Mathpane.add ("East", Signsgrid);
^
method Container.add(String,Component) is not applicable
(argument mismatch; GridLayout cannot be converted to Component)
method Container.add(Component,int) is not applicable
(argument mismatch; String cannot be converted to Component)
method Container.add(Component,Object) is not applicable
(argument mismatch; String cannot be converted to Component)
C:\Users\Novus\Desktop\STC Notes\OO Scripts\CalcGUI.java:72: error: no suitable method found for add(String,BorderLayout)
Finalpane.add("Center", MathBorder);
^
method Container.add(String,Component) is not applicable
(argument mismatch; BorderLayout cannot be converted to Component)
method Container.add(Component,int) is not applicable
(argument mismatch; String cannot be converted to Component)
method Container.add(Component,Object) is not applicable
(argument mismatch; String cannot be converted to Component)
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
这些是错误,这是代码
import javax.swing.*;
import java.awt.*;
class Calculator
{
public static void main (String args[])
{
JFrame = new CalcGUI();
Jframe.setSize(420,720);
JFrame.setVisible(true);
}
}
和第二部分
import javax.swing.*;
import java.awt.*;
public class CalcGUI extends JFrame
{
BorderLayout FinalBorder = new BorderLayout();
GridLayout Numgrid = new GridLayout(4,3,15,15);
GridLayout Signsgrid = new GridLayout(5,1,7,7);
BorderLayout MathBorder = new BorderLayout();
JPanel Finalpane = new JPanel();
JPanel Mathpane = new JPanel();
JPanel Signpane = new JPanel();
JPanel Numpane = new JPanel();
JLabel Casio = new JLabel("Casio", JLabel.CENTER);
JTextField txt_InputNum = new JTextField();
JButton Btn7 = new JButton("7");
JButton Btn8 = new JButton("8");
JButton Btn9 = new JButton("9");
JButton Btn4 = new JButton("4");
JButton Btn5 = new JButton("5");
JButton Btn6 = new JButton("6");
JButton Btn1 = new JButton("1");
JButton Btn2 = new JButton("2");
JButton Btn3 = new JButton("3");
JButton Btn_deci = new JButton(".");
JButton Btn0 = new JButton("0");
JButton Btn_clear = new JButton("C");
JButton Btn_mult = new JButton("*");
JButton Btn_div = new JButton("/");
JButton Btn_add = new JButton("+");
JButton Btn_minus = new JButton("-");
JButton Btn_equals = new JButton("=");
public CalcGUI ()
{
super ("Calculator");
Numpane.setLayout(Numgrid);
Numpane.add(Btn7);
Numpane.add(Btn8);
Numpane.add(Btn9);
Numpane.add(Btn4);
Numpane.add(Btn5);
Numpane.add(Btn6);
Numpane.add(Btn1);
Numpane.add(Btn2);
Numpane.add(Btn3);
Numpane.add(Btn_deci);
Numpane.add(Btn0);
Numpane.add(Btn_clear);
Signpane.setLayout(Signsgrid);
Signpane.add(Btn_mult);
Signpane.add(Btn_div);
Signpane.add(Btn_add);
Signpane.add(Btn_minus);
Signpane.add(Btn_equals);
Mathpane.setLayout(MathBorder);
Mathpane.add("Center", Numgrid);
Mathpane.add ("East", Signsgrid);
//super ("Calculator");
//setDefaultCloseOperation(JFrame (EXIT_ON_CLOSE));
Finalpane.setLayout(FinalBorder);
Finalpane.add("North", txt_InputNum);
Finalpane.add("Center", MathBorder);
Finalpane.add("South", Casio);
setContentPane(Finalpane);
}
}
我仍然处于非常基本的java级别,所以请保持简单的提示或答案,谢谢!