The Java swing component cannot be resolved

I got the following code from the tutorial:

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

public class SwingGUI {

    public static void main( String[] args )
      {
        JFrame f = new JFrame( "test" );
        f.setDefaultCloSEOperation( JFrame.EXIT_ON_CLOSE );
        f.setSize( 1500,900 );
        JLabel l = new JLabel( String.format( "%tT",new Date() ) );
        f.add(l);
        f.setVisible( true );
      }
}

f.add(l); Highlight and display two errors:

>The method add (component) in the container type is not applicable to the parameter (jlabel) > cannot resolve javax swing. JComponent type It is from what is needed Class file indirectly referenced

As a relatively new Java, I really don't understand what eclipse is trying to tell me What can I do to make it work?

Edit: the code does not have f.add (L); Line, so the problem is not that JFrame or jlabel cannot be found After a little tinkering, I got rid of the first mistake, but the second still exists Component cannot be resolved because it is indirectly referenced What'd you mean by that?

Solution

Obviously, the problem is not the code, because it applies to everyone else So I decided to delete and reinstall Java and eclipse, etvoil à! Now it works Thank you for your feedback

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>