⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 splashtest.java

📁 本java源程序包括了大量的学习程序(共27章)方便大家学习
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;               //ActionEvent

public class SplashTest extends JFrame {
    private final static int WIDTH=400, HEIGHT=300;
    private final static int WIDTH1=450, HEIGHT1=120;
    private JWindow windowSplash;
    
    public SplashTest() {
       super("SplashTest");
       //获取屏幕的大小
       int screenWidth=(int)getToolkit().getScreenSize().getWidth();
       int screenHeight=(int)getToolkit().getScreenSize().getHeight();
       
       windowSplash();
       
       try{
          Thread.sleep(5000);
       } catch (InterruptedException e) {
          e.printStackTrace();
       }
       
       windowStop();
       
       //设置窗口大小
       setSize(WIDTH, HEIGHT);
       //设置内容面板背景色
       getContentPane().setBackground(Color.yellow);
       //设置窗口在屏幕在的显示位置
       setLocation((screenWidth-WIDTH)/2,(screenHeight-HEIGHT)/2);
       
       setVisible(true);
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String args[]) {
       SplashTest application = new SplashTest();
    }

    private void windowSplash() {
        windowSplash = new JWindow();
        MyJPanel panel=new MyJPanel();
        windowSplash.setSize(WIDTH1,HEIGHT1);
        windowSplash.getContentPane().add(panel);

        int screenWidth=(int)getToolkit().getScreenSize().getWidth();
        int screenHeight=(int)getToolkit().getScreenSize().getHeight();
        
        //设置windowSplash在屏幕上的显示位置
        windowSplash.setLocation((screenWidth-WIDTH1)/2,(screenHeight-HEIGHT1)/2);
        windowSplash.setVisible(true);
    }
    
    private void windowStop() {
        windowSplash.dispose();
    }

    private class MyJPanel extends JPanel implements ActionListener {
      private ImageIcon imageIcon;
      private JProgressBar progressbar;
      private Timer timer;
      
      public MyJPanel() {
    	  super();
    	  
          imageIcon=new ImageIcon("image1.jpg");
          //创建进度条
          progressbar = new JProgressBar();
          
          //设置最小值,最大值,初值
          progressbar.setMinimum(0);
          progressbar.setMaximum(100);
          progressbar.setValue(0);
          //显示进度条进度文本
          progressbar.setStringPainted(true);
          //显示进度条边框
          progressbar.setBorderPainted(true);
          
          //设置进度条大小,背景色,前景色
          progressbar.setPreferredSize(new Dimension(200,30));
          progressbar.setBackground(Color.WHITE);
          progressbar.setForeground(Color.YELLOW);
     
          add(progressbar);
          
          //创建定时器,时间间隔为50毫秒
          timer = new Timer(50,this);
          //启动定时器
          timer.start();
      }
      
      public void paintComponent(Graphics g) {
          super.paintComponent(g);
          imageIcon.paintIcon(this,g,0,0);
      }
      
      //处理定时器事件
      public void actionPerformed(ActionEvent e){
          if(e.getSource() == timer){
              int value = progressbar.getValue();
              
              if( value < 100){
                  value++;
                  progressbar.setValue(value);
              } else{
                  timer.stop();
              }
          }
      }          
   }   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -