java swing 진행 바 확정

2331 단어
package toolbar;

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

public class JProgressbar extends JFrame {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JProgressbar probar = new JProgressbar();
		probar.setVisible(true);
	}
	public JProgressbar() {
		super();
		Container c = getContentPane();
		c.setLayout(new FlowLayout());
		setTitle("   ");
		setBounds(100, 100, 500, 375);
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		
		final JLabel label = new JLabel();
		label.setForeground(new Color(255,0,0));
		label.setText("welcome to use update automaticlly");

		c.add(label, new FlowLayout());
		final JProgressBar progressBar = new JProgressBar();
/*		progressBar.setStringPainted(true);//         
		progressBar.setIndeterminate(true);//           
		progressBar.setString("     ......");//       
*/
		getContentPane().add(progressBar, new FlowLayout());
		
		final JButton button = new JButton();
		button.setText("  ");
		button.setEnabled(false);
		button.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				System.exit(0);
			}
		});
		

		getContentPane().add(button, new FlowLayout());
		Progress pro = new Progress(progressBar, button);//               
		Thread t1 = new Thread(pro,"  1");
		t1.start();
		
	}
	class Progress implements Runnable {
		private final int[] progressValue = { 6, 18, 27, 39, 51, 66, 81, 100 };
		private JProgressBar progressbar;
		private JButton jbutton;

		public Progress(JProgressBar progressbar, JButton jbutton) {
			this.progressbar=progressbar;
			this.jbutton=jbutton;
		}

		@Override
		public void run() {
			// TODO Auto-generated method stub
			for (int i = 0; i < progressValue.length; i++) {
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				System.out.println(progressValue[i]); 
				progressbar.setValue(progressValue[i]);
				System.out.println("2");
			}
			progressbar.setIndeterminate(false);
			progressbar.setString("    ");
			jbutton.setEnabled(true);
		}

	}
}


좋은 웹페이지 즐겨찾기