문제
가위바위보 게임의 GUI 문제입니다 이를 해결하는 다음 프로그램에 대해 빈칸을 채우세요
코드 빈칸 채우기
import javax.swing.*;
import rpsGame.RockPaperScissorsPanel;
public RockPaperScissorsGUIMain
{
public static void main( String[] args ) {
final String imagePath = "C:\\Users\\user\\Downloads\\JAVA-main\\src\\rpsGame\\image\\";
frame = new ( "가위바위보" );
frame.getContentPane().( new RockPaperScissorsPanel( imagePath ) );
frame.setDefaultCloseOperation( .EXIT_ON_CLOSE );
frame.pack();
frame.setVisible( true );
}
}
package rpsGame;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public RockPaperScissorsPanel
{
protected final int SCISSORS = 0, ROCK = 1, PAPER = 2, QUESTIONMARK = 3;
protected final int BASE = 0, WIN = 1;
protected imgPlayerA, imgPlayerB, strPlayers;
protected [] button;
protected [][] image;
protected timer;
public RockPaperScissorsPanel( final String imgPath ) {
image = new [4][2];
image[SCISSORS ][BASE] = new ( new ( imgPath + "scissors.gif" ).().getScaledInstance( 200, 200, Image.SCALE_SMOOTH ) );
image[SCISSORS ][WIN] = new ( new ( imgPath + "scissors_win.gif" ).().getScaledInstance( 200, 200, Image.SCALE_SMOOTH ) );
image[ROCK ][BASE] = new ( new ( imgPath + "rock.gif" ).().getScaledInstance( 200, 200, Image.SCALE_SMOOTH ) );
image[ROCK ][WIN] = new ( new ( imgPath + "rock_win.gif" ).().getScaledInstance( 200, 200, Image.SCALE_SMOOTH ) );
image[PAPER ][BASE] = new ( new ( imgPath + "paper.gif" ).().getScaledInstance( 200, 200, Image.SCALE_SMOOTH ) );
image[PAPER ][WIN] = new ( new ( imgPath + "paper_win.gif" ).().getScaledInstance( 200, 200, Image.SCALE_SMOOTH ) );
image[QUESTIONMARK][BASE] = new ( new ( imgPath + "questionmark.gif" ).().getScaledInstance( 200, 200, Image.SCALE_SMOOTH ) );
image[QUESTIONMARK][WIN] = new ( new ( imgPath + "questionmark.gif" ).().getScaledInstance( 200, 200, Image.SCALE_SMOOTH ) );
this.imgPlayerA = new ( image[QUESTIONMARK][BASE] );
this.imgPlayerB = new ( image[QUESTIONMARK][BASE] );
this.strPlayers = new ( "<html><body>[너]<br>[나]</body></html>", .CENTER );
this.( this.imgPlayerB );
this.( this.strPlayers );
this.( this.imgPlayerA );
button = new [3];
button[SCISSORS] = new ( new ( image[SCISSORS][BASE].().getScaledInstance( 30, 30, Image.SCALE_SMOOTH ) ) );
button[ROCK ] = new ( new ( image[ROCK ][BASE].().getScaledInstance( 30, 30, Image.SCALE_SMOOTH ) ) );
button[PAPER ] = new ( new ( image[PAPER ][BASE].().getScaledInstance( 30, 30, Image.SCALE_SMOOTH ) ) );
button[SCISSORS].( this );
button[ROCK ].( this );
button[PAPER ].( this );
this.( new (" 가위 바위 보를 선택하세요 ") );
this.( button[SCISSORS] );
this.( button[ROCK] );
this.( button[PAPER] );
this.setBackground( Color.cyan );
this.setPreferredSize( new Dimension(220, 530) );
this.timer = new ( 1000, new () {
@Override
public void ( event ) {
ready();
timer.();
}
});
}
public void ready() {
imgPlayerA.( image[QUESTIONMARK][BASE] );
imgPlayerB.( image[QUESTIONMARK][BASE] );
button[0].( true );
button[1].( true );
button[2].( true );
}
@Override
public void ( event ) {
int playerA = select( event );
int playerB = (int)( Math.random() * 3 );
show( playerA, playerB );
timer.();
}
public void show( int playerA, int playerB ) {
int playerA_winOrLose = BASE, playerB_winOrLose = BASE;
if ( ( ( playerA == SCISSORS ) && ( playerB == PAPER ) )
|| ( ( playerA == ROCK ) && ( playerB == SCISSORS ) )
|| ( ( playerA == PAPER ) && ( playerB == ROCK ) ) ) {
playerA_winOrLose = WIN;
}
else if ( ( ( playerA == PAPER ) && ( playerB == SCISSORS ) )
|| ( ( playerA == SCISSORS ) && ( playerB == ROCK ) )
|| ( ( playerA == ROCK ) && ( playerB == PAPER ) ) ) {
playerB_winOrLose = WIN;
}
imgPlayerA.( image[ playerA ][ playerA_winOrLose ] );
imgPlayerB.( image[ playerB ][ playerB_winOrLose ] );
button[0].( false );
button[1].( false );
button[2].( false );
}
public int select( event ) {
if( event.() == button[SCISSORS] )
return SCISSORS;
else if ( event.() == button[ROCK] )
return ROCK;
else
return PAPER;
}
}