java进度条

这是一个使用Java Swing库创建的进度条界面程序,主要用于展示进度。程序包含窗口设置、图标加载、背景图片、标题和子标题标签、进度条以及退出按钮。在2012年运行时显示,其他时间则会退出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这本是一个骗别人维护的程序。

package com.gzxh.util;

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

public class OptFram extends JFrame implements Runnable
{

 private static final long serialVersionUID = 1L;
 private JLabel jlblTitle;
 private JLabel jlblTitle1;
 private JProgressBar jproBar ;
 private JButton jbtExit;
 private int pos;
 private boolean flag;
   public OptFram()
   {
    Calendar calendar= Calendar.getInstance();
    if (calendar.get(Calendar.YEAR)==2012)
    {
     pos = 0;
     flag=true;
     inintFrm();
    }else
    {
     System.exit(0);
    }
   }
  
    private void inintFrm()
    {
       /**设置窗口大小**/
       setSize(500,500);
          /**设置图标**/
         java.net.URL url = ClassLoader.getSystemClassLoader().getResource("ec_logobig.jpg");
          java.awt.Image image = Toolkit.getDefaultToolkit().getImage(url);
          this.setIconImage(image);
          /**设置背景**/
       setContentPane(new JPanel()
       {              
   private static final long serialVersionUID = 1L;
   java.net.URL url1 = ClassLoader.getSystemClassLoader().getResource("image_2.jpg");
   ImageIcon icon = new ImageIcon(url1);
       public void paintComponent(Graphics g)
       {
        super.paintComponent(g);
        this.paintBG(g);
       }
       public void paintBG(Graphics g)
       {
        icon.paintIcon(this, g, (this.getBounds().width - icon.getIconWidth()) / 2, (this.getBounds().height - icon.getIconHeight()) / 2);
      }
       });

     Container container = this.getContentPane();
     container.setLayout(null);
     this.setTitle("成都**科技有限公司--项目部");
     container.setBackground(new Color(255,255,255));
     /**设置标题**/
     jlblTitle = new JLabel*********维护程序",JLabel.CENTER);
     jlblTitle1 = new JLabel("WWW.****.COM",JLabel.CENTER);
     jlblTitle.setLocation(0,20);
     jlblTitle.setSize(500,40);
     jlblTitle1.setLocation(0,60);
     jlblTitle1.setSize(500,40);
     Font font = new Font("宋体",1,26);
     jlblTitle.setFont(font);
     jlblTitle1.setFont(font);
     container.add(jlblTitle);
     container.add(jlblTitle1);
     /**设置进度条**/
     jproBar = new JProgressBar();
     jproBar.setMaximum(1000);
     jproBar.setMinimum(0);
     jproBar.setOpaque(false);
     jproBar.setStringPainted(true);
     jproBar.setBorder(null);
     jproBar.setBorderPainted(false);
     jproBar.setLocation(30,170);
     jproBar.setSize(440,40);
     jproBar.setFont(new Font("宋体",1,18));
     jproBar.setForeground(new Color(0,0,255));
     container.add(jproBar);
     /**设置按扭**/
     jbtExit = new JButton();
     jbtExit.setFont(new Font("宋体",1,18));
     jbtExit.setText("关 闭");
     jbtExit.setSize(100,30);
     jbtExit.setLocation(200,420);
     jbtExit.setForeground(new Color(0,0,255));
     container.add(jbtExit);
     /**关闭事件**/
     jbtExit.addActionListener(new ActionListener()
     {
   public void actionPerformed(ActionEvent evt)
   {
    System.exit(0);
      }
  });
     /**窗口事件**/
     this.addWindowListener(new WindowListener()
     {
   public void windowActivated(WindowEvent arg0) {  
   }
   public void windowClosed(WindowEvent arg0) {
    System.exit(0); 
   }
   public void windowClosing(WindowEvent arg0) {
    System.exit(0);
   }
   public void windowDeactivated(WindowEvent arg0) {   
   }
   public void windowDeiconified(WindowEvent arg0) {
   }
   public void windowIconified(WindowEvent arg0) {  
   }
   public void windowOpened(WindowEvent arg0) {
   }
 
     });
     jbtExit.setEnabled(false);
     /**设置窗口位置**/
     Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
     Dimension frame = this.getSize();
     this.setLocation((int)(screen.getWidth()-frame.getWidth())/2,(int)(screen.getHeight()-frame.getHeight())/2);    
     /**设置窗口大小调整**/
     //this.setUndecorated(true);
     this.setResizable(false);
     setVisible(true);
     Thread thread = new Thread(this);
     thread.start();
    }
    public static void main(String[] args)
    {
     new OptFram();
    }
 public void run()
 {
     while(flag)
     {
      pos++;
      if(pos <= jproBar.getMaximum())
      {
       jproBar.setValue(pos);
       try
       {
        Thread.sleep(50);
       }catch(Exception e)
       {
        System.out.println(e.getMessage());
        Thread.currentThread().interrupt();
       }
      }else
      {
       Thread.currentThread().interrupt();
       flag=false;
       jbtExit.setEnabled(true);
      }
     }
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值