Skip to content
Snippets Groups Projects
Commit 22d9a5aa authored by Jie Luo's avatar Jie Luo
Browse files

eclipse game files

parent 6f9bf896
No related branches found
No related tags found
No related merge requests found
package view;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Tutorial extends JFrame{
private JButton back;
public Tutorial(ImageIcon img){
super("FaultInOurPong - Tutorial");
this.setSize(700,500);
this.setResizable(false);
this.setLocationRelativeTo(null);
this.add(new JLabel(img));
back = new JButton("Back");
//this.add(back);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public JButton getBack(){
return back;
}
public void addListener(ActionListener listener){
back.addActionListener(listener);
}
}
package view;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.*;
public class View extends JFrame{
public class Welcome extends JFrame {
private JButton start = new JButton("Start New Game");
private JButton load = new JButton("Load Game");
......@@ -17,17 +12,23 @@ public class View extends JFrame{
private JButton tutorial = new JButton("Tutorial");
private JButton exit = new JButton("Exit");
private JButton single = new JButton("Single Player Mode");
private JButton sObstacle = new JButton("Advanced Single Player Mode");
private JButton multi = new JButton("Multiplayer Mode");
private JPanel buttonPanel;
JPanel buttonPanel = new JPanel();
public View(){
public Welcome(){
/*
* - Set the header of the window
* - Set the size of the window
*/
super("FaultInOurPong");
this.setSize(700,500);
this.setResizable(false);
this.setLocationRelativeTo(null);
/*
* Add buttons on the window
*/
buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.Y_AXIS));
buttonPanel.add(Box.createVerticalGlue());
......@@ -37,94 +38,46 @@ public class View extends JFrame{
addButton(tutorial);
addButton(exit);
buttonPanel.add(Box.createVerticalGlue());
start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
start();
}
});
load.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
load();
}
});
highScores.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
highScores();
}
});
tutorial.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tutorial();
}
});
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
add(buttonPanel);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
public void addButton(JButton x) {
x.setMaximumSize(sObstacle.getPreferredSize());
x.setAlignmentY(CENTER_ALIGNMENT);
x.setAlignmentX(CENTER_ALIGNMENT);
buttonPanel.add(x);
buttonPanel.add(Box.createVerticalStrut(20));
public JButton getStart(){
return start;
}
public void start() {
buttonPanel.removeAll();
this.getContentPane().removeAll();
this.repaint();
buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.Y_AXIS));
buttonPanel.add(Box.createVerticalGlue());
addButton(single);
addButton(sObstacle);
buttonPanel.add(Box.createVerticalGlue());
add(buttonPanel);
this.setVisible(true);
single.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
single();
}
});
public JButton load(){
return load;
}
public void single() {
Pong_viewAndController view_controller = new Pong_viewAndController();
this.setVisible(false);
public JButton highScores(){
return highScores;
}
public void load() {
public JButton tutorial(){
return tutorial;
}
public void highScores() {
public JButton exit(){
return exit;
}
public void tutorial() {
public void addButton(JButton x) {
x.setMaximumSize(start.getPreferredSize());
x.setAlignmentY(CENTER_ALIGNMENT);
x.setAlignmentX(CENTER_ALIGNMENT);
buttonPanel.add(x);
buttonPanel.add(Box.createVerticalStrut(20));
}
public static void main(String[] args) {
View menuPage = new View();
public void addListener(ActionListener buttonListener){
start.addActionListener(buttonListener);
load.addActionListener(buttonListener);
highScores.addActionListener(buttonListener);
tutorial.addActionListener(buttonListener);
exit.addActionListener(buttonListener);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment