我正在使用 netbeans 编译器 7.11 版。我正在尝试创建一个 GridLayout,但它在我编写代码以创建布局按钮的行中显示错误。
它给出了以下错误
no suitable constructor found for JButton(Java.lang.String.java.lang.String)
Constructor javax.swing.JButton.JButton(java.lang.String,javax.swing.Icon)is not applicable
(actual argument Java.lang.String cannot be converted to javax.swing.Icon by method
invocation conversion)
Constructor javax.swing.JButton.JButton(javax.swing.Action)is not applicable
(actual and formal argument lists differ in length)
Constructor javax.swing.JButton.JButton(java.lang.String)is not applicable
(actual and formal argument lists differ in length)
Constructor javax.swing.JButton.JButton(javax.swing.Icon)is not applicable
(actual and formal argument lists differ in length)
Constructor javax.swing.JButton.JButton()is not applicable
(actual and formal argument lists differ in length)
它从第 7 行到第 11 行显示了这些错误。下面是我输入 Java Netbeans 编译器的代码。
import java.awt.*;
import javax.swing.*;
public class Griddemo extends JFrame{
public Griddemo()
{
setLayout(new GridLayout(3,2));
add(new JButton("Row-1","Col-1")); ---- line7
add(new JButton("Row-1","Col-2")); ---- line8
add(new JButton("Row-2","Col-1")); ---- line9
add(new JButton("Row-2","Col-2")); ---- line10
add(new JButton("Row-3","Col-1")); ---- line11
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public static void main(String args[])
{
new Griddemo();
}
}