문제
리모컨으로 제어하는 TV 프로그램의 GUI 문제입니다 이를 해결하는 다음 프로그램에 대해 빈칸을 채우세요
코드 빈칸 채우기
import java.awt.*;
import javax.swing.*;
import remoteControl.RemoteControllerPanel;
import remoteControl.TVPanel;
public RemoteControlTVGUIMain
{
public static void main( String[] args )
{
final String imagePath = "C:\\Users\\user\\Downloads\\JAVA-main\\src\\remoteControl\\image\\";
TVPanel appliance =
new TVPanel( imagePath );
RemoteControllerPanel remoteController =
new RemoteControllerPanel( imagePath, appliance );
frame = new ( "TV" );
frame.( new () );
frame.( remoteController, .WEST );
frame.( appliance, .EAST );
frame.setPreferredSize( new Dimension( 600,170 ) );
frame.setDefaultCloseOperation( .EXIT_ON_CLOSE );
frame.pack();
frame.setVisible( true );
}
}
package remoteControl;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public RemoteControllerPanel
{
protected [] button;
public final static int POWER = 0, UP = 1, DOWN = 2, LEFT = 3, RIGHT = 4;
protected RemoteControl appliance;
public RemoteControllerPanel( String imgPath ) {
.appliance = null;
final String[] strButton = { "power.gif", "up.gif", "down.gif", "left.gif", "right.gif" };
button = new [strButton.length];
for ( int i = 0; i < strButton.length; i++ ) {
button[i] = new ( new ( new ( imgPath + strButton[i] ).().getScaledInstance( 30, 30, Image.SCALE_SMOOTH ) ) );
button[i].( );
}
.setPreferredSize( new Dimension( 240, 120 ) );
.( new () );
.( button[POWER], .CENTER );
.( button[UP ], .NORTH );
.( button[DOWN ], .SOUTH );
.( button[LEFT ], .WEST );
.( button[RIGHT], .EAST );
}
public RemoteControllerPanel( String imgPath, RemoteControl appliance ) {
( imgPath );
.appliance = appliance;
}
@Override
public void ( event ) {
if ( ( event.() == button[POWER] ) && ( appliance != null ) )
appliance.clickPower();
else if ( ( event.() == button[UP] ) && ( appliance != null ) )
appliance.clickUp();
else if ( ( event.() == button[DOWN] ) && ( appliance != null ) )
appliance.clickDown();
else if ( ( event.() == button[LEFT] ) && ( appliance != null ) )
appliance.clickLeft();
else if ( ( event.() == button[RIGHT] ) && ( appliance != null ) )
appliance.clickRight();
}
}
package remoteControl;
import java.awt.*;
import javax.swing.*;
public TVPanel RemoteControl
{
private boolean power;
private int channel, volume;
private [] imgChannel, imgVolume;
private lblChannel, lblVolume;
public TVPanel( final String imgPath ) {
final String[] channelFile = { "EBS.gif", "SBS.gif", "KBS.gif", "MBC.gif", "blank.gif" };
imgChannel = new [channelFile.length];
for ( int i = 0; i < channelFile.length; i++ ) {
imgChannel[i] = new ( new ( imgPath + channelFile[i] ).().getScaledInstance( 250, 120, Image.SCALE_SMOOTH ) );
}
final String[] volumeFile = { "volume0.gif", "volume1.gif", "volume2.gif", "volume3.gif" };
imgVolume = new [volumeFile.length];
for ( int i = 0; i < volumeFile.length; i++ ) {
imgVolume[i] = new ( new ( imgPath + volumeFile[i] ).().getScaledInstance( 80, 120, Image.SCALE_SMOOTH ) );
}
power = OFF;
channel = imgChannel.length - 1;
volume = 0;
lblChannel = new ( imgChannel[channel] );
lblVolume = new ( imgVolume[volume] );
( lblChannel );
( lblVolume );
}
@Override
public void clickPower() {
if( power == OFF ) {
power = ON;
channel = 0;
volume = 1;
lblChannel.( imgChannel[channel] );
lblVolume.( imgVolume[volume] );
}
else {
power = OFF;
channel = imgChannel.length - 1;
volume = 0;
lblChannel.( imgChannel[channel] );
lblVolume.( imgVolume[volume] );
}
}
@Override
public void clickUp() {
if( power == ON ) {
channel = ( channel + 1 ) % ( imgChannel.length - 1 );
lblChannel.( imgChannel[channel] );
}
}
@Override
public void clickDown() {
if( power == ON ) {
channel = ( channel + ( imgChannel.length - 2 ) ) % ( imgChannel.length - 1 );
lblChannel.( imgChannel[channel] );
}
}
@Override
public void clickLeft() {
if( power == ON ) {
volume = ( volume + ( imgVolume.length - 1 ) ) % imgVolume.length;
lblVolume.( imgVolume[volume] );
}
}
@Override
public void clickRight() {
if( power == ON ) {
volume = ( volume + 1 ) % imgVolume.length;
lblVolume.( imgVolume[volume] );
}
}
}
package remoteControl;
public RemoteControl
{
boolean ON = true, OFF = false;
void clickPower();
void clickUp();
void clickDown();
void clickLeft();
void clickRight();
}