/* * JSplash constructs a splash screen (JWindow). * parent is the parent frame for the window * filename is the JPEG/GIF file to show as the splash * timeout is time in milliseconds to display the splash */ public JSplash(JFrame parent, String filename, int timeout) { super(parent);
// Note, this code does no error checking ImageIcon image = new ImageIcon(filename); // The splash will be centered on the screen int w = image.getIconWidth() + 5; int h = image.getIconHeight() + 5; Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); int x = (screen.width - w) / 2; int y = (screen.height - h) / 2; setBounds(x, y, w, h);
// Listen for key strokes addKeyListener(this); // Listen for mouse events from here and parent addMouseListener(this); parent.addMouseListener(this); // Timeout after a while Timer timer = new Timer(0, this); timer.setRepeats(false); timer.setInitialDelay(timeout); timer.start(); }
// This method is called in order to block the application until // the splash screen times out or is dismissed. // This is a bit of a kludge, actually, and the actual affect // varies based on platform. public void block() { while(isVisible()) {} }
// Dismiss the window on a key press, ignore rest. public void keyTyped(KeyEvent event) {} public void keyReleased(KeyEvent event) {} public void keyPressed(KeyEvent event) { setVisible(false); dispose(); }
// Dismiss the window on a mouse click, ignore rest. public void mousePressed(MouseEvent event) {} public void mouseReleased(MouseEvent event) {} public void mouseEntered(MouseEvent event) {} public void mouseExited(MouseEvent event) {} public void mouseClicked(MouseEvent event) { setVisible(false); dispose(); }
// Dismiss the window on a timeout public void actionPerformed(ActionEvent event) { setVisible(false); dispose(); } public static void main(String[] args) { System.out.println("你 少 了 main 函数"); } }
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;public class JSplash extends JWindow
implements KeyListener, MouseListener, ActionListener {
/*
* JSplash constructs a splash screen (JWindow).
* parent is the parent frame for the window
* filename is the JPEG/GIF file to show as the splash
* timeout is time in milliseconds to display the splash
*/
public JSplash(JFrame parent, String filename, int timeout) {
super(parent);
// Note, this code does no error checking
ImageIcon image = new ImageIcon(filename);
// The splash will be centered on the screen
int w = image.getIconWidth() + 5;
int h = image.getIconHeight() + 5;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width - w) / 2;
int y = (screen.height - h) / 2;
setBounds(x, y, w, h);
getContentPane().setLayout(new BorderLayout());
JLabel picture = new JLabel(image);
getContentPane().add("Center", picture);
picture.setBorder(new BevelBorder(BevelBorder.RAISED));
// Listen for key strokes
addKeyListener(this);
// Listen for mouse events from here and parent
addMouseListener(this);
parent.addMouseListener(this);
// Timeout after a while
Timer timer = new Timer(0, this);
timer.setRepeats(false);
timer.setInitialDelay(timeout);
timer.start();
}
// This method is called in order to block the application until
// the splash screen times out or is dismissed.
// This is a bit of a kludge, actually, and the actual affect
// varies based on platform.
public void block() {
while(isVisible()) {}
}
// Dismiss the window on a key press, ignore rest.
public void keyTyped(KeyEvent event) {}
public void keyReleased(KeyEvent event) {}
public void keyPressed(KeyEvent event) {
setVisible(false);
dispose();
}
// Dismiss the window on a mouse click, ignore rest.
public void mousePressed(MouseEvent event) {}
public void mouseReleased(MouseEvent event) {}
public void mouseEntered(MouseEvent event) {}
public void mouseExited(MouseEvent event) {}
public void mouseClicked(MouseEvent event) {
setVisible(false);
dispose();
}
// Dismiss the window on a timeout
public void actionPerformed(ActionEvent event) {
setVisible(false);
dispose();
}
public static void main(String[] args)
{
System.out.println("你 少 了 main 函数");
}
}
哪位大虾可以帮我写完整的main程序,将这个效果运行出来呢~~~再次谢谢了~