【发布时间】:2014-04-09 21:35:40
【问题描述】:
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();
}
}
我在“新 GridLayout”上不断收到错误消息。我正在为我的课学习这本书,它没有解释我是否需要导入某些东西或声明它以使其工作。任何提示将不胜感激。
【问题讨论】:
-
如果您使用 IDE,例如 Eclipse、NetBeans 或 IntelliJ IDEA,它可以帮助您添加必要的导入(在 IDEA 中,可以键入 Alt-Enter,在 Eclipse 中,Shift-Ctrl-O )。
标签: java swing layout import grid