/*
*--------------------------------------------------------------------------
* Battlefield - A Realtime Network Multiplayer Game
* =======================================================
* Developed by Group D02 - 2009/2010 Semester 4 - CS2103
* Harry Nguyen Duy Hoang <nnduyhoang@yahoo.co.uk>
* Kent Chng Siang Rong <fivefootway@gmail.com>
* Lim Yong Peng <limpeng1986@gmail.com>
* Loh Xiankun <u0807185@nus.edu.sg>
* Instructed by
* Dr. Damith C.Rajapakse <damith@gmail.com>
* =======================================================
* $Id: TutorialScreen.java 646 2010-07-30 05:59:09Z Harry $
* $LastChangedDate: 2010-07-29 22:59:09 -0700 (Thu, 29 Jul 2010) $
* $LastChangedBy: Harry $
*--------------------------------------------------------------------------
*/
package battlefield.ui.screen;
import battlefield.resource.Graphics;
import battlefield.ui.component.NormalWhiteButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
*
* @author Yong Peng
*/
public class TutorialScreen extends Screen implements ActionListener {
private NormalWhiteButton homeBut;
private NormalWhiteButton backBut;
private NormalWhiteButton nextBut;
private int index = 0;
private static final String[] tutorials = new String[]{"/battlefield/images/tutpage1.png", "/battlefield/images/tutpage2.png", "/battlefield/images/tutpage3.png"};
public TutorialScreen() {
initComponent();
}
private void initComponent() {
setLayout(null);
homeBut = new NormalWhiteButton("Home", this);
backBut = new NormalWhiteButton("Previous", this);
nextBut = new NormalWhiteButton("Next", this);
add(homeBut);
homeBut.setLocation(540, 650);
add(backBut);
backBut.setLocation(650, 650);
backBut.setEnabled(false);
add(nextBut);
nextBut.setLocation(760, 650);
this.setBackgroundImage(Graphics.get(tutorials[index]).getImage());
}
/* Begin Region: State Pattern */
@Override
public Screen home() {
return new GameMenuScreen();
}
/* End Region: State Pattern */
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(homeBut)) {
getGUI().home();
} else if (e.getSource().equals(backBut)) {
index = Math.max(index - 1, 0);
this.setBackgroundImage(Graphics.get(tutorials[index]).getImage());
backBut.setEnabled(index > 0);
nextBut.setEnabled(index < tutorials.length - 1);
repaint();
} else if (e.getSource().equals(nextBut)) {
index = Math.min(index + 1, tutorials.length - 1);
this.setBackgroundImage(Graphics.get(tutorials[index]).getImage());
backBut.setEnabled(index > 0);
nextBut.setEnabled(index < tutorials.length - 1);
repaint();
}
}
}
|