Skip to content

Commit

Permalink
Added QImagePanel
Browse files Browse the repository at this point in the history
  • Loading branch information
annapecini committed Mar 28, 2019
1 parent 9820b14 commit b894847
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 65 deletions.
19 changes: 19 additions & 0 deletions src/gazillion/QImagePanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package gazillion;

import java.awt.*;
import java.swing.*;

public class QImagePanel extends QPanel {
private BufferedImage image;

pulic QImagePanel(QPanel parent, QFrame frame, String image){
super(parent, frame);
this.image = ImageIO.read(new File(image));
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, null);
}
}
140 changes: 75 additions & 65 deletions src/gazillion/QMainMenu.java
Original file line number Diff line number Diff line change
@@ -1,65 +1,75 @@
package gazillion;

import quadrillion.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
* QMainMenu: PURELY TEST
*
* @author Unsal Ozturk
* @version 20190328
*/
public class QMainMenu extends QPanel {
private JButton newGame;
private JButton resumeGame;
private QGazillionPanel gamePanel;
public QMainMenu(QPanel parent, QFrame frame) {
super(parent, frame);
newGame = new JButton("New Game");
resumeGame = new JButton("Resume Game");
ActionListener newGameListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
QGameBuilder g = new QGameBuilder();
QGame game = g.setGrid(QGridType.GRID_TYPE_1, 2)
.setGrid(QGridType.GRID_TYPE_2, 1)
.setGrid(QGridType.GRID_TYPE_3, 0)
.setGrid(QGridType.GRID_TYPE_4,1)
.setBoard(QBoardType.BOARD_TYPE_1)
.build(600000);
QGridFactory gridFact = new QGridFactory();
QBoardFactory boardFact = new QBoardFactory();

QPlayer player = new QPlayer();
QThemeManager man = new QThemeManager();

gamePanel = new QGazillionPanel(QMainMenu.this, frame, player, man.getThemes().get(0), game);
resumeGame.setEnabled(true);
frame.setActivePanel(gamePanel);
}
};

ActionListener resumeGameListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setActivePanel(gamePanel);
}
};
newGame.addActionListener(newGameListener);
newGame.setEnabled(true);
resumeGame.addActionListener(resumeGameListener);
resumeGame.setEnabled(false);
this.setLayout(new FlowLayout());
this.add(newGame);
this.add(resumeGame);
}

public void endGame() {
gamePanel = null;
resumeGame.setEnabled(false);
}
}
package gazillion;

import quadrillion.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
* QMainMenu: PURELY TEST
*
* @author Unsal Ozturk
* @version 20190328
*/
public class QMainMenu extends QPanel {
private JButton newGame;
private JButton resumeGame;
private QImagePanel background;
private QGazillionPanel gamePanel;
public QMainMenu(QPanel parent, QFrame frame) {
super(parent, frame);
newGame = new JButton("New Game");
resumeGame = new JButton("Resume Game");

background = new QImagePanel(parent, frame, "background.jpg");
@Override
protected void paintComponent(Graphics g) {

super.paintComponent(g);
g.drawImage(bgImage, 0, 0, null);
}

ActionListener newGameListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
QGameBuilder g = new QGameBuilder();
QGame game = g.setGrid(QGridType.GRID_TYPE_1, 2)
.setGrid(QGridType.GRID_TYPE_2, 1)
.setGrid(QGridType.GRID_TYPE_3, 0)
.setGrid(QGridType.GRID_TYPE_4,1)
.setBoard(QBoardType.BOARD_TYPE_1)
.build(600000);
QGridFactory gridFact = new QGridFactory();
QBoardFactory boardFact = new QBoardFactory();

QPlayer player = new QPlayer();
QThemeManager man = new QThemeManager();

gamePanel = new QGazillionPanel(QMainMenu.this, frame, player, man.getThemes().get(0), game);
resumeGame.setEnabled(true);
frame.setActivePanel(gamePanel);
}
};

ActionListener resumeGameListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setActivePanel(gamePanel);
}
};
newGame.addActionListener(newGameListener);
newGame.setEnabled(true);
resumeGame.addActionListener(resumeGameListener);
resumeGame.setEnabled(false);
this.setLayout(new FlowLayout());
this.add(newGame);
this.add(resumeGame);
}

public void endGame() {
gamePanel = null;
resumeGame.setEnabled(false);
}
}

0 comments on commit b894847

Please sign in to comment.