Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Deadwood GUI helper file
- Author: Moushumi Sharmin
- This file shows how to create a simple GUI using Java Swing and Awt Library
- Classes Used: JFrame, JLabel, JButton, JLayeredPane
- */
- import java.awt.*;
- import javax.swing.*;
- import javax.swing.ImageIcon;
- import javax.imageio.ImageIO;
- import java.awt.event.*;
- import javax.swing.JOptionPane;
- public class BoardLayersListener extends JFrame {
- // JLabels
- JLabel boardlabel;
- // card label
- JLabel cardlabel;
- JLabel cardlabel2;
- JLabel cardlabel3;
- // player label
- JLabel playerlabel;
- JLabel mLabel;
- // shot counters
- JLabel shotLabel;
- JLabel shotLabel2;
- JLabel shotLabel3;
- //JButtons
- JButton bAct;
- JButton bRehearse;
- JButton bMove;
- // JLayered Pane
- JLayeredPane bPane;
- // Constructor
- public BoardLayersListener() {
- // Set the title of the JFrame
- super("Deadwood");
- // Set the exit option for the JFrame
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- // Create the JLayeredPane to hold the display, cards, dice and buttons
- bPane = getLayeredPane();
- // Create the deadwood board
- boardlabel = new JLabel();
- ImageIcon icon = new ImageIcon("board.jpg");
- boardlabel.setIcon(icon);
- boardlabel.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());
- // Add the board to the lowest layer
- bPane.add(boardlabel, new Integer(0));
- // Set the size of the GUI
- setSize(icon.getIconWidth()+200,icon.getIconHeight());
- // Add card 1 to board
- cardlabel = new JLabel();
- ImageIcon cIcon = new ImageIcon("01.png");
- cardlabel.setIcon(cIcon); // this places the placement of card
- // this gets the placement of the card on the board
- // (a,b,c,d)
- // a & b being where to place the card on the board
- cardlabel.setBounds(969,28,cIcon.getIconWidth()+2,cIcon.getIconHeight());
- cardlabel.setOpaque(true);
- // Add the card to the lower layer
- bPane.add(cardlabel, new Integer(1));
- // add card2 to board
- cardlabel2 = new JLabel();
- ImageIcon cIcon2 = new ImageIcon("02.png");
- cardlabel2.setIcon(cIcon2);
- cardlabel2.setBounds(21, 69, cIcon2.getIconWidth(), cIcon2.getIconHeight());
- cardlabel2.setOpaque(true);
- bPane.add(cardlabel2,new Integer(1));
- //add card3 to board
- cardlabel3 = new JLabel();
- ImageIcon cIcon3 = new ImageIcon("03.png");
- cardlabel3.setIcon(cIcon2);
- cardlabel3.setBounds(370, 282, cIcon3.getIconWidth(), cIcon3.getIconHeight());
- cardlabel3.setOpaque(true);
- bPane.add(cardlabel3,new Integer(1));
- // Add a dice to represent a player.
- // Role for Crusty the prospector. The x and y co-ordiantes are taken from
- //Board.xml file
- playerlabel = new JLabel();
- ImageIcon pIcon = new ImageIcon("b1.png");
- playerlabel.setIcon(pIcon);
- //playerlabel.setBounds(114,227,pIcon.getIconWidth(),pIcon.getIconHeight());
- playerlabel.setBounds(1000,280,46,46);
- playerlabel.setVisible(true);
- bPane.add(playerlabel,new Integer(3));
- // add shot counter
- shotLabel = new JLabel();
- ImageIcon sIcon = new ImageIcon("shot.png");
- shotLabel.setIcon(sIcon);
- shotLabel.setBounds(36, 11, 47, 47);
- shotLabel.setVisible(true);
- bPane.add(shotLabel,new Integer(3));
- // add another shot counter
- shotLabel2 = new JLabel();
- ImageIcon sIcon2 = new ImageIcon("shot.png");
- shotLabel2.setIcon(sIcon);
- shotLabel2.setBounds(89, 11, 47, 47);
- shotLabel2.setVisible(true);
- bPane.add(shotLabel2,new Integer(3));
- // add another shot counter
- shotLabel3 = new JLabel();
- ImageIcon sIcon3 = new ImageIcon("shot.png");
- shotLabel3.setIcon(sIcon);
- shotLabel3.setBounds(141, 11, 47, 47);
- shotLabel3.setVisible(true);
- bPane.add(shotLabel3,new Integer(3));
- // Create the Menu for action buttons
- mLabel = new JLabel("MENU");
- mLabel.setBounds(icon.getIconWidth()+40,0,100,20);
- bPane.add(mLabel,new Integer(2));
- // Create Action buttons
- bAct = new JButton("ACT");
- bAct.setBackground(Color.white);
- bAct.setBounds(icon.getIconWidth()+10, 30,100, 20);
- bAct.addMouseListener(new boardMouseListener());
- bRehearse = new JButton("REHEARSE");
- bRehearse.setBackground(Color.white);
- bRehearse.setBounds(icon.getIconWidth()+10,60,100, 20);
- bRehearse.addMouseListener(new boardMouseListener());
- bMove = new JButton("MOVE");
- bMove.setBackground(Color.white);
- bMove.setBounds(icon.getIconWidth()+10,90,100, 20);
- bMove.addMouseListener(new boardMouseListener());
- // Place the action buttons in the top layer
- bPane.add(bAct, new Integer(2));
- bPane.add(bRehearse, new Integer(2));
- bPane.add(bMove, new Integer(2));
- }
- // This class implements Mouse Events
- class boardMouseListener implements MouseListener{
- // Code for the different button clicks
- public void mouseClicked(MouseEvent e) {
- if (e.getSource()== bAct){
- //playerlabel.setVisible(true);
- //System.out.println("Acting is Selected\n");\
- }
- else if (e.getSource()== bRehearse){
- System.out.println("Rehearse is Selected\n");
- }
- else if (e.getSource()== bMove){
- System.out.println("Move is Selected\n");
- }
- }
- public void mousePressed(MouseEvent e) {
- }
- public void mouseReleased(MouseEvent e) {
- }
- public void mouseEntered(MouseEvent e) {
- }
- public void mouseExited(MouseEvent e) {
- }
- }
- //public static void main(String[] args) {
- // BoardLayersListener board = new BoardLayersListener();
- // board.setVisible(true);
- // Take input from the user about number of players
- // JOptionPane.showInputDialog(board, "How many players?");
- // }
- // this method will add cards to the board
- public void addCards(Room room) {
- cardlabel = new JLabel();
- ImageIcon cardImage = new ImageIcon("01.png");
- cardlabel.setIcon(cardImage);
- cardlabel.setBounds((int)room.getCardArea().getX(),(int)room.getCardArea().getY(), cardImage.getIconWidth(),cardImage.getIconHeight());
- cardlabel.setOpaque(true);
- bPane.add(cardlabel, new Integer(1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement