JAVA 프로그래밍

문제

버튼을 누르면 자동으로 문이 열리는 과정을 모델링하는 문제입니다 실행순서를 클릭하세요 
 

프로그램 코드

E001	// 이벤트 대기중
E002	// 문열기 버튼 클릭하기
E003	// 문닫기 버튼 클릭하기

	import javax.swing.*;
	 
	public class AutomaticDoorGUIMain
	{
1		public static void main( String[] args ) {
			JFrame frame = new JFrame( "자동문" );
2			frame.getContentPane().add( new AutomaticDoorPanel() );
			frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
			frame.pack();
			frame.setVisible(true);
3		}
	}

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

	public class AutomaticDoorPanel extends JPanel
	{
		private JPanel door;
		private JButton button;
		private boolean open;

Pb		public AutomaticDoorPanel() {
			door = this;
			open = false;
			setBackground( Color.cyan );
			setPreferredSize( new Dimension( 250, 400 ) );
			
			button = new JButton( "문열기" );
			button.addActionListener( new ClickListener() );
			add( button );
Pe		}

		private class ClickListener implements ActionListener {
			@Override
Lb			public void actionPerformed( ActionEvent event ) {
L1				if ( open == false ) {
					open = true;
					door.setBackground( Color.white );
L2					button.setText( "문닫기" );
				}
L3				else {
					open = false;
					door.setBackground( Color.cyan );
L4					button.setText( "문열기" );
				}
Le			}
		}
	}








 
실행 순서