- import java.awt.*;
- import javax.swing.*;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
- import java.awt.event.*;
- public class TestProgressbar {
- public static void main(String[] args) {
- MyFrame f=new MyFrame();
- f.setVisible(true);
- }
- }
- class MyFrame extends JFrame implements ActionListener,ChangeListener
- {
- private JProgressBar jpb;
- private JButton b1,b2,b3;
- //在构造方法内实现窗体的建立
- public MyFrame()
- {
- super("进度条演示");
- this.setBounds(60,80, 600, 400);
- this.setLayout(new FlowLayout());
- this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- jpb=new JProgressBar();
- jpb.addChangeListener(this);
- b1=new JButton("设置进度条的当前值为50,最小值为0,最大值为100");
- b1.addActionListener(this);
- b2=new JButton("得到进度条的当前值");
- b2.addActionListener(this);
- b3=new JButton("改变为80");
- b3.addActionListener(this);
- Container c=this.getContentPane();
- c.add(jpb);
- c.add(b1);
- c.add(b2);
- c.add(b3);
- }
- public void actionPerformed(ActionEvent e)
- {
- if(e.getSource()==b1)
- {
- jpb.setMinimum(0);
- jpb.setMaximum(100);
- jpb.setValue(50);
- }
- if(e.getSource()==b2)
- {
- JOptionPane.showMessageDialog(this, jpb.getValue()+"", "提示",JOptionPane.INFORMATION_MESSAGE);
- }
- if(e.getSource()==b3)
- {
- jpb.setValue(80);
- }
- }
- public void stateChanged(ChangeEvent e) {
- JOptionPane.showMessageDialog(this, jpb.getValue()+"", "提示",JOptionPane.INFORMATION_MESSAGE);
- }
- }
JAVA进度条演示
最新推荐文章于 2024-05-31 10:46:10 发布