窗口与swing初步

建立一个启动界面程序

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class SplashWindow extends JWindow implements ActionListener{
    JLabel back=new JLabel(new ImageIcon("mon.gif"),JLabel.CENTER);//显示图形的标签
    JLabel begain=new JLabel("BEGAINING......");
    JLabel txtTime=new JLabel();//用来显示倒计时的标签
    JProgressBar progressBar=new JProgressBar(1,100);//进度条
    Timer timer;//时间组件
    JPanel p1=new JPanel();//创建JPanel面板
    JPanel p2=new JPanel();
    int n=100;
    
    public SplashWindow(){
        progressBar.setStringPainted(true);//允许进度条显示文本
        progressBar.setString("正在加载程序。。。。。");//设置进度条文本
        Container contentPane=getContentPane();//创建内容窗格
        contentPane.setLayout(null);
        setSize(200,200);//设置页面大小
        toFront();//使页面移动到最前面
        setLocation(200,200);
        back.setBounds(10,20,200,100);//设置图形的位置
        p1.setBounds(10,140,200,20);//设置面板的位置
        p2.setBounds(10,160,200,40);
        setVisible(true);
        p1.add(begain);
        p1.add(txtTime);//将标签添加到p1面板
        p2.add(progressBar);//将进度条添加到p2面板
        contentPane.add(back);//将图形添加到内容窗格
        contentPane.add(p1);//将p1面板添加到内容窗格
        contentPane.add(p2);//将p2面板添加到内容窗格
        timer=new javax.swing.Timer(100,this);//建立时间组件
        timer.addActionListener(this);//组册行为事件
        timer.start();//启动时间组件,开始计时
    }
    public void actionPerformed(ActionEvent e){//事件的方法
        if(--n>0){
            progressBar.setValue(100-n);//设置进度条的值
            txtTime.setText(Integer.toString(n));//设置倒计时
            timer.restart();
        }
        else{
            timer.stop();//停止计时
            dispose();//关闭当前窗口
        }
    }
    public static void main(String args[]){
        SplashWindow splashWindow=new SplashWindow();//建立窗口
    }
}
原文地址:https://www.cnblogs.com/ljs-666/p/7846222.html