자바

 

 

class MdiExam

package java21_oracle.menu;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JInternalFrame;
import javax.swing.JProgressBar;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
//SDI(Single Document Interface ) - 폼 안에 자식폼을 배치할 수 없음
//MDI(Multiple Document Interface) - 폼 안에 자식폼 배치 가능
//JInterFrame
public class MdiExam extends JFrame implements Runnable {

	private JPanel contentPane;
	private JProgressBar pb;
	private JLabel lblResult;
	private int sum;
	
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MdiExam frame = new MdiExam();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MdiExam() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 609, 477);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JInternalFrame internalFrame = new JInternalFrame("New JInternalFrame");
		internalFrame.setIconifiable(true);
		internalFrame.setMaximizable(true);
		internalFrame.setClosable(true);
		internalFrame.setBounds(88, 68, 311, 335);
		contentPane.add(internalFrame);
		internalFrame.getContentPane().setLayout(null);
		
		pb = new JProgressBar();
		pb.setStringPainted(true);
		pb.setBounds(12, 31, 271, 47);
		internalFrame.getContentPane().add(pb);
		
		JButton btnStart = new JButton("start");
		btnStart.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			
				//백그라운드 스레드 생성
				Thread th=new Thread(MdiExam.this);
				//기존 스레드 daemon
				th.setDaemon(true);
				//백그라운드 스레드 시작 요청
				th.start();
			}
		});
		btnStart.setBounds(101, 122, 97, 23);
		internalFrame.getContentPane().add(btnStart);
		
		lblResult = new JLabel("");
		lblResult.setBounds(44, 179, 225, 40);
		internalFrame.getContentPane().add(lblResult);
		internalFrame.setVisible(true);
	}
	
	
	
	@Override
	public void run() {
		sum =0;
		for(int i=0; i<=100; i++){
		
			pb.setValue(i);
			sum +=i;
			lblResult.setText("1부터 " +i +" 까지 합 : " + sum);
			try {
				Thread.sleep(30);
			} catch (InterruptedException e) {
				
				e.printStackTrace();
			}
		}
		
		
	}
	
	
	
	
	
	
}

 

 

 

 

 

 

about author

PHRASE

Level 60  머나먼나라

The fish always goes bad from head downwards.

댓글 ( 0)

댓글 남기기

작성
  •    
  •