gpt4 book ai didi

java - GridLayout 错误

转载 作者:行者123 更新时间:2023-12-01 13:18:38 26 4
gpt4 key购买 nike

import java.awt.Container; //Container or *
import javax.swing.*; //JFrame, JLabel, *, or etc...

public class NumerologyEC extends JFrame
{
private static final int Width = 400;
private static final int Height = 300;

private JLabel word1;

public NumerologyEC()
{
setTitle ("Numerology Extra Credit");
word1 = new JLabel ("Enter a word: ", SwingConstants.RIGHT);

Container pane = getContentPane();
pane.setLayout (new GridLayout (1, 2));

pane.add(word1);

setSize(Width, Height);
setVisible (true);
setDefaultCloseOperation (EXIT_ON_CLOSE);
}

public static void main (String[] args)
{
NumerologyEC rectObject = new NumerologyEC();
}
}

我不断收到“new GridLayout”错误。我正在关注我的类(class)的这本书,它没有解释我是否需要导入某些内容或声明它才能使其工作。任何提示将不胜感激。

最佳答案

您还需要导入GridLayout。添加此导入

import java.awt.GridLayout;

或者您可以将导入更改为以下内容以导入包中的所有内容

import java.awt.*;

或者明确写

new java.awt.GridLayout (1, 2)

关于java - GridLayout 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22238222/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com