Methapolis  0.27
 All Classes Namespaces Files Functions Variables Enumerator
SplashScreen.java
Go to the documentation of this file.
1 package micropolisj.gui;
2 
3 import java.awt.Dimension;
4 import java.awt.Graphics;
5 import java.awt.event.MouseEvent;
6 import java.awt.event.MouseListener;
7 import java.awt.image.BufferedImage;
8 import java.io.File;
9 import java.io.IOException;
10 import java.util.ResourceBundle;
11 
12 import javax.imageio.ImageIO;
13 import javax.swing.ImageIcon;
14 import javax.swing.JFrame;
15 import javax.swing.JLabel;
16 import javax.swing.JPanel;
17 
18 import micropolisj.engine.Micropolis;
19 import micropolisj.network.ServerMicropolis;
20 
21 public class SplashScreen extends JFrame {
22 
23  JPanel panel;
24  JPanel panelNewGame;
25  JPanel panelHost;
26  JPanel panelLogin;
27  JPanel panelLoad;
28  BufferedImage image;
29  JLabel jlSplashImage;
30  JLabel jlStartNewGame;
31  JLabel jlHostGame;
32  JLabel jlLoginGame;
33  JLabel jlLoadGame;
34 
35  static final ResourceBundle strings = MainWindow.strings;
36 
37  public SplashScreen() {
38  super("Welcome To Methapolis");
39  try {
40  image = ImageIO.read(new File("graphics/splash.png"));
41  jlStartNewGame = new JLabel(new ImageIcon(ImageIO.read(new File("graphics/splash_1.png"))));
42  jlHostGame = new JLabel(new ImageIcon(ImageIO.read(new File("graphics/splash_2.png"))));
43  jlLoginGame = new JLabel(new ImageIcon(ImageIO.read(new File("graphics/splash_3.png"))));
44  jlLoadGame = new JLabel(new ImageIcon(ImageIO.read(new File("graphics/splash_4.png"))));
45  }
46  catch(IOException e) {
47  e.printStackTrace();
48  }
49 
50  jlSplashImage = new JLabel(new ImageIcon(image));
51  jlSplashImage.setBounds(0, 0, 1024, 576);
52  jlStartNewGame.setBounds(0, 0, 1024, 576);
53  jlHostGame.setBounds(0, 0, 1024, 576);
54  jlLoginGame.setBounds(0, 0, 1024, 576);
55  jlLoadGame.setBounds(0, 0, 1024, 576);
56 
57  panel = new JPanel(null, true);
58  panel.setSize(1024, 576);
59  getContentPane().add(panel);
60  panel.add(jlSplashImage);
61 
62  panelNewGame = new JPanel(null, true);
63  panelNewGame.setBounds(775, 40, 225, 55);
64  HandlerNewGame handlernew = new HandlerNewGame();
65  panelNewGame.addMouseListener(handlernew);
66  panel.add(panelNewGame);
67 
68  panelHost = new JPanel(null, true);
69  panelHost.setBounds(895, 175, 125, 40);
70  HandlerHost handlerhost = new HandlerHost();
71  panelHost.addMouseListener(handlerhost);
72  panel.add(panelHost);
73 
74  panelLogin = new JPanel(null, true);
75  panelLogin.setBounds(875, 320, 110, 45);
76  HandlerLogin handlerlog = new HandlerLogin();
77  panelLogin.addMouseListener(handlerlog);
78  panel.add(panelLogin);
79 
80  panelLoad = new JPanel(null, true);
81  panelLoad.setBounds(755, 500, 230, 55);
82  HandlerLoad handlerload = new HandlerLoad();
83  panelLoad.addMouseListener(handlerload);
84  panel.add(panelLoad);
85 
86  final Dimension d = this.getToolkit().getScreenSize();
87  // center the frame
88  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
89  this.setSize(1024, 576);
90  this.setResizable(false);
91  this.setLocationRelativeTo(null);
92  this.setUndecorated(true);
93  this.setVisible(true);
94 
95  }
96 
97  private void startJoinGameScreen() {
98  new JoinGameScreen();
99  closeThis();
100  }
101 
102  private void startNewGame() {
103  MainWindow win = new MainWindow();
104  win.doNewCity(true);
105  this.setVisible(false);
106  win.setVisible(false);
107  win.setVisible(true);
108  closeThis();
109  }
110 
111  private void startNewServer() {
112  this.setVisible(false);
113  MainWindow win = new MainWindow(new ServerMicropolis());
114  win.setVisible(false);
115  win.doNewCity(true);
116  win.setVisible(true);
117  closeThis();
118  }
119 
120  private void loadGame() {
121  this.setVisible(false);
122  MainWindow win = new MainWindow();
123  win.setVisible(false);
124  win.onLoadGameClicked();
125  win.setVisible(true);
126  closeThis();
127  }
128 
129  private void closeThis() {
130  this.setVisible(false);
131  this.dispose();
132  }
133 
134  private class HandlerNewGame implements MouseListener {
135  public void mouseClicked(MouseEvent event) {
136  startNewGame();
137  }
138 
139  public void mousePressed(MouseEvent event) {
140 
141  }
142 
143  public void mouseReleased(MouseEvent event) {
144 
145  }
146 
147  public void mouseEntered(MouseEvent event) {
148  panel.remove(jlSplashImage);
150  panel.add(jlStartNewGame);
152  panel.repaint();
153  }
154 
155  public void mouseExited(MouseEvent event) {
156  panel.remove(jlStartNewGame);
158  panel.add(jlSplashImage);
160  panel.repaint();
161  }
162  }
163 
164  private class HandlerHost implements MouseListener {
165  public void mouseClicked(MouseEvent event) {
166  startNewServer();
167  }
168 
169  public void mousePressed(MouseEvent event) {
170 
171  }
172 
173  public void mouseReleased(MouseEvent event) {
174 
175  }
176 
177  public void mouseEntered(MouseEvent event) {
178  panel.remove(jlSplashImage);
180  panel.add(jlHostGame);
182  panel.repaint();
183  }
184 
185  public void mouseExited(MouseEvent event) {
186  panel.remove(jlHostGame);
188  panel.add(jlSplashImage);
190  panel.repaint();
191  }
192  }
193 
194  private class HandlerLogin implements MouseListener {
195  public void mouseClicked(MouseEvent event) {
197  }
198 
199  public void mousePressed(MouseEvent event) {
200 
201  }
202 
203  public void mouseReleased(MouseEvent event) {
204 
205  }
206 
207  public void mouseEntered(MouseEvent event) {
208  panel.remove(jlSplashImage);
210  panel.add(jlLoginGame);
212  panel.repaint();
213  }
214 
215  public void mouseExited(MouseEvent event) {
216  panel.remove(jlLoginGame);
218  panel.add(jlSplashImage);
220  panel.repaint();
221  }
222  }
223 
224  private class HandlerLoad implements MouseListener {
225  public void mouseClicked(MouseEvent event) {
226  loadGame();
227  }
228 
229  public void mousePressed(MouseEvent event) {
230 
231  }
232 
233  public void mouseReleased(MouseEvent event) {
234 
235  }
236 
237  public void mouseEntered(MouseEvent event) {
238  panel.remove(jlSplashImage);
240  panel.add(jlLoadGame);
242  panel.repaint();
243  }
244 
245  public void mouseExited(MouseEvent event) {
246  panel.remove(jlLoadGame);
248  panel.add(jlSplashImage);
250  panel.repaint();
251  }
252  }
253 
254  protected void paintComponent(Graphics g) {
255  super.paintComponents(g);
256  g.drawImage(image, 0, 0, null);
257  }
258 
259  void startPlaying(Micropolis newEngine, File file) {
260 
261  MainWindow win = new MainWindow();
262  win.setVisible(true);
263  win.setEngine(newEngine);
264  win.currentFile = file;
265  win.makeClean();
266  dispose();
267  }
268 
269  private void removeBackgroundPanels() {
270  panel.remove(panelNewGame);
271  panel.remove(panelHost);
272  panel.remove(panelLogin);
273  panel.remove(panelLoad);
274 
275  }
276 
277  private void addBackgroundPanels() {
278  panel.add(panelNewGame);
279  panel.add(panelHost);
280  panel.add(panelLogin);
281  panel.add(panelLoad);
282  }
283 
284 }