I took the following code from a 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 );
}
}
The f.add(l);
is highlighted and two errors are shown:
Being relatively new to java, I do not really understand what Eclipse is trying to tell me. What can I do to make it work?
edit: The code runs without the line f.add(l);
, so the problem is not that JFrame or JLabel are not found. After fiddeling around a little I got rid of the first error, but the second still remains. The component cannot be resolved, because it is indirectly referenced. What does that mean?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…