Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Constructor Parameter Problem

Status
Not open for further replies.

viclap

Programmer
Oct 12, 2000
39
0
0
PH
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

class SplashWindow2 extends JWindow
{

public SplashWindow2(String filename, Frame f)
public SplashWindow2()
{
super(f);
//Frame f = new Frame();
JLabel l = new JLabel(new ImageIcon(filename));
this.getContentPane().add(l, BorderLayout.CENTER);
pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension labelSize = l.getPreferredSize();
setLocation(screenSize.width/2 - (labelSize.width/2),
screenSize.height/2 - (labelSize.height/2));
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
setVisible(false);
dispose();
}
});
setVisible(true);
}

public static void main(String args[])
{
//System.out.println("Splash window example");
new SplashWindow2("C:/Documents and Settings/vplapid/Desktop/Java/icms.jpg",????????);
}
}

I'm very new to Java and trying to make a splash window. I can't figure out what value or object to be pass on the parameter of the constructor.

Any help would be appreciated.
 
Well as your code stands, you've got no 'owner frame' to pass into the constructor of the JWindow super class. Just use the no-arg constructor.

Code:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class SplashWindow2 extends JWindow{

 public SplashWindow2(String filename){
   super();

   JLabel l = new JLabel(new ImageIcon(filename));
   this.getContentPane().add(l, BorderLayout.CENTER);
   pack();
   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
   Dimension labelSize = l.getPreferredSize();
   setLocation(screenSize.width/2 - (labelSize.width/2),
   screenSize.height/2 - (labelSize.height/2));
   addMouseListener(new MouseAdapter(){
      public void mousePressed(MouseEvent e){
         setVisible(false);
         dispose();
      }
   });
   setVisible(true);
 }

 public static void main(String args[]){
    //System.out.println("Splash window example");
    new SplashWindow2("C:/Documents and Settings/vplapid/Desktop/Java/icms.jpg",????????);
 }
}

I've removed your
Code:
 public SplashWindow2()
which was not needed, and was in the wrong place anyway.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top