0
import java.awt.Frame;
import java.awt.SplashScreen;
import javax.swing.JOptionPane;


public class NewFrame extends Frame
{

    public NewFrame() 
    {
        // TODO Auto-generated constructor stub
        SplashScreen splash = new SplashScreen(1000);
        System.out.println("This is working");

    }

/**
     * @param args
     */
    public static void main(String[] args) 
    {
        // TODO Auto-generated method stub
        //SplashScreen splash = new SplashScreen(2000);
        NewFrame newframe = new NewFrame();


    }

}

This is showing me error

The constructor SplashScreen(long) is not visible

And this is the Splash screen code

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;

class SplashScreen extends JWindow {
  private int duration;

  public SplashScreen(int d) {
    duration = d;

    JPanel content = (JPanel) getContentPane();
    content.setBackground(Color.white);
    int width = 450;
    int height = 115;
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screen.width - width) / 2;
    int y = (screen.height - height) / 2;
    setBounds(x, y, width, height);  
     content.add(new JLabel("Welcome to Company"), BorderLayout.CENTER);
    //Color oraRed = new Color(156, 20, 20, 255);
     Color oraRed = new Color(190, 10, 10, 255);
    content.setBorder(BorderFactory.createLineBorder(oraRed, 1));

    setVisible(true);

    try {
      Thread.sleep(duration);
    } catch (Exception e) {
    }
    setVisible(false);
  }
  public static void main(String[] args) {
    SplashScreen splash = new SplashScreen(10000);
  }
}

Constructors are public by default ,aren't they?

2
Contributors
1
Reply
20
Views
2 Years
Discussion Span
Last Post by JamesCherrill
1

No, they are package access by default, justlike ordinary methods.

The error message refers to a constructor with a long parameter, but the only constructor takes an int.

Creation or modification of Swing components should normally be done on the Swing thread. Sleeping during a constructor while changing a swing component's visibility, all on the main thread is asking for trouble...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.