GridLayout上的错误

时间:2014-03-06 23:13:50

标签: java swing layout import grid

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”上收到错误。我跟随我的班级书,它不解释我是否需要导入一些东西或声明它以使其工作。任何提示将不胜感激。

1 个答案:

答案 0 :(得分:1)

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

import java.awt.GridLayout;

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

import java.awt.*;

或明确写

new java.awt.GridLayout (1, 2)