문제
버튼을 누르면 자동으로 문이 열리는 과정을 모델링하는 문제입니다 이를 해결하는 프로그램의 다음 실행상태에 대해 빈칸을 채우세요
프로그램의 실행순서 및 실행상태
①
②
1 public static void main( String[] args ) {
2 frame.getContentPane().add( new AutomaticDoorPanel() );
Pb public AutomaticDoorPanel() {
Pe }
3 }
⑥
E001 // 이벤트 대기중
E002 // 문열기 버튼 클릭하기
③
Lb public void actionPerformed( ActionEvent event ) {
L1 if ( open == false ) {
L2 button.setText( "문닫기" );
④
Le }
E001 // 이벤트 대기중
E003 // 문닫기 버튼 클릭하기
⑤
Lb public void actionPerformed( ActionEvent event ) {
L1 if ( open == false ) {
L3 else {
L4 button.setText( "문열기" );
⑥
Le }
E001 // 이벤트 대기중
프로그램 코드
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 }
}
}