JAVA进度条演示

 
  1. import java.awt.*;
  2.  import javax.swing.*;
  3.  import javax.swing.event.ChangeEvent;
  4.  import javax.swing.event.ChangeListener;
  5.  import java.awt.event.*;
  6.  public class TestProgressbar {
  7.      public static void main(String[] args) {
  8.          MyFrame f=new MyFrame();
  9.          f.setVisible(true);
  10.      }
  11.  }
  12.  class MyFrame extends JFrame implements ActionListener,ChangeListener
  13.  {
  14.      private JProgressBar jpb;
  15.      private JButton b1,b2,b3;
  16.      //在构造方法内实现窗体的建立  
  17.      public MyFrame()
  18.      {
  19.          super("进度条演示");
  20.          this.setBounds(60,80, 600, 400);
  21.          this.setLayout(new FlowLayout());
  22.          this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  23.          jpb=new JProgressBar();
  24.          jpb.addChangeListener(this);
  25.          b1=new JButton("设置进度条的当前值为50,最小值为0,最大值为100");
  26.          b1.addActionListener(this);
  27.          b2=new JButton("得到进度条的当前值");
  28.          b2.addActionListener(this);
  29.          b3=new JButton("改变为80");
  30.          b3.addActionListener(this);
  31.          Container c=this.getContentPane();
  32.          c.add(jpb);
  33.          c.add(b1);
  34.          c.add(b2);
  35.          c.add(b3);
  36.      }
  37.      public void actionPerformed(ActionEvent e)
  38.      {
  39.          if(e.getSource()==b1)
  40.          {
  41.              jpb.setMinimum(0);
  42.              jpb.setMaximum(100);
  43.              jpb.setValue(50);
  44.          }
  45.          if(e.getSource()==b2)
  46.          {
  47.              JOptionPane.showMessageDialog(this, jpb.getValue()+"", "提示",JOptionPane.INFORMATION_MESSAGE);
  48.          }
  49.          if(e.getSource()==b3)
  50.          {
  51.              jpb.setValue(80);
  52.          }
  53.      }
  54.      public void stateChanged(ChangeEvent e) {
  55.          JOptionPane.showMessageDialog(this, jpb.getValue()+"", "提示",JOptionPane.INFORMATION_MESSAGE);
  56.      }
  57.  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值