java swing component cannot be resolved

前端 未结 9 2043
灰色年华
灰色年华 2020-12-11 16:43

I took the following code from a tutorial:

import javax.swing.*;
import java.util.Date;

public class SwingGUI {

    public static void main( String[] args          


        
9条回答
  •  北荒
    北荒 (楼主)
    2020-12-11 17:14

    Just guessing, but it matches the problem you describe:

    This problem can arise when your own package contains a class that is called JLabel. The local class will then shadow the imported JLabel-class from the javax.swing-package and it might not have the same class-hierarchy as the original class.

    To sum it up: it usaually is a bad idea to name ones own classes like existing JDK-classes.

提交回复
热议问题