Advertisement
alexjowilson7

BoardLayersListener

Mar 5th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.82 KB | None | 0 0
  1. /*
  2.    Deadwood GUI helper file
  3.    Author: Moushumi Sharmin
  4.    This file shows how to create a simple GUI using Java Swing and Awt Library
  5.    Classes Used: JFrame, JLabel, JButton, JLayeredPane
  6. */
  7. import java.awt.*;
  8. import javax.swing.*;
  9. import javax.swing.ImageIcon;
  10. import javax.imageio.ImageIO;
  11. import java.awt.event.*;
  12. import javax.swing.JOptionPane;
  13. public class BoardLayersListener extends JFrame {
  14.  
  15.   // JLabels
  16.   JLabel boardlabel;
  17.  
  18.   // card label
  19.   JLabel cardlabel;
  20.   JLabel cardlabel2;
  21.   JLabel cardlabel3;
  22.  
  23.   // player label
  24.   JLabel playerlabel;
  25.  
  26.   JLabel mLabel;
  27.  
  28.   // shot counters
  29.   JLabel shotLabel;
  30.   JLabel shotLabel2;
  31.   JLabel shotLabel3;
  32.  
  33.   //JButtons
  34.   JButton bAct;
  35.   JButton bRehearse;
  36.   JButton bMove;
  37.  
  38.   // JLayered Pane
  39.   JLayeredPane bPane;
  40.  
  41.  
  42.   // Constructor
  43.   public BoardLayersListener() {
  44.        // Set the title of the JFrame
  45.        super("Deadwood");
  46.        
  47.        // Set the exit option for the JFrame
  48.        setDefaultCloseOperation(EXIT_ON_CLOSE);
  49.        
  50.        // Create the JLayeredPane to hold the display, cards, dice and buttons
  51.        bPane = getLayeredPane();
  52.        
  53.        // Create the deadwood board
  54.        boardlabel = new JLabel();
  55.        ImageIcon icon =  new ImageIcon("board.jpg");
  56.        boardlabel.setIcon(icon);
  57.        boardlabel.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());
  58.        
  59.        // Add the board to the lowest layer
  60.        bPane.add(boardlabel, new Integer(0));
  61.        
  62.        // Set the size of the GUI
  63.        setSize(icon.getIconWidth()+200,icon.getIconHeight());
  64.        
  65.        
  66.        
  67.        // Add card 1 to board
  68.        cardlabel = new JLabel();
  69.        ImageIcon cIcon =  new ImageIcon("01.png");
  70.        cardlabel.setIcon(cIcon);  // this places the placement of card
  71.        // this gets the placement of the card on the board
  72.        // (a,b,c,d)
  73.        // a & b being where to place the card on the board
  74.        cardlabel.setBounds(969,28,cIcon.getIconWidth()+2,cIcon.getIconHeight());
  75.        cardlabel.setOpaque(true);
  76.        // Add the card to the lower layer
  77.        bPane.add(cardlabel, new Integer(1));
  78.    
  79.        
  80.        // add card2 to board
  81.        cardlabel2 = new JLabel();
  82.        ImageIcon cIcon2 = new ImageIcon("02.png");
  83.        cardlabel2.setIcon(cIcon2);
  84.        cardlabel2.setBounds(21, 69, cIcon2.getIconWidth(), cIcon2.getIconHeight());
  85.        cardlabel2.setOpaque(true);
  86.        bPane.add(cardlabel2,new Integer(1));
  87.        
  88.        //add card3 to board
  89.        cardlabel3 = new JLabel();
  90.        ImageIcon cIcon3 = new ImageIcon("03.png");
  91.        cardlabel3.setIcon(cIcon2);
  92.        cardlabel3.setBounds(370, 282, cIcon3.getIconWidth(), cIcon3.getIconHeight());
  93.        cardlabel3.setOpaque(true);
  94.        bPane.add(cardlabel3,new Integer(1));
  95.        
  96.        
  97.        // Add a dice to represent a player.
  98.        // Role for Crusty the prospector. The x and y co-ordiantes are taken from
  99.        //Board.xml file
  100.        playerlabel = new JLabel();
  101.        ImageIcon pIcon = new ImageIcon("b1.png");
  102.        playerlabel.setIcon(pIcon);
  103.        //playerlabel.setBounds(114,227,pIcon.getIconWidth(),pIcon.getIconHeight());
  104.        playerlabel.setBounds(1000,280,46,46);
  105.        playerlabel.setVisible(true);
  106.        bPane.add(playerlabel,new Integer(3));
  107.        
  108.        // add shot counter
  109.        shotLabel = new JLabel();
  110.        ImageIcon sIcon = new ImageIcon("shot.png");
  111.        shotLabel.setIcon(sIcon);
  112.        shotLabel.setBounds(36, 11, 47, 47);
  113.        shotLabel.setVisible(true);
  114.        bPane.add(shotLabel,new Integer(3));
  115.        
  116.        // add another shot counter
  117.        shotLabel2 = new JLabel();
  118.        ImageIcon sIcon2 = new ImageIcon("shot.png");
  119.        shotLabel2.setIcon(sIcon);
  120.        shotLabel2.setBounds(89, 11, 47, 47);
  121.        shotLabel2.setVisible(true);
  122.        bPane.add(shotLabel2,new Integer(3));
  123.        
  124.        // add another shot counter
  125.        shotLabel3 = new JLabel();
  126.        ImageIcon sIcon3 = new ImageIcon("shot.png");
  127.        shotLabel3.setIcon(sIcon);
  128.        shotLabel3.setBounds(141, 11, 47, 47);
  129.        shotLabel3.setVisible(true);
  130.        bPane.add(shotLabel3,new Integer(3));
  131.        
  132.        
  133.        
  134.        
  135.        
  136.        
  137.        // Create the Menu for action buttons
  138.        mLabel = new JLabel("MENU");
  139.        mLabel.setBounds(icon.getIconWidth()+40,0,100,20);
  140.        bPane.add(mLabel,new Integer(2));
  141.        
  142.        // Create Action buttons
  143.        bAct = new JButton("ACT");
  144.        bAct.setBackground(Color.white);
  145.        bAct.setBounds(icon.getIconWidth()+10, 30,100, 20);
  146.        bAct.addMouseListener(new boardMouseListener());
  147.        
  148.        bRehearse = new JButton("REHEARSE");
  149.        bRehearse.setBackground(Color.white);
  150.        bRehearse.setBounds(icon.getIconWidth()+10,60,100, 20);
  151.        bRehearse.addMouseListener(new boardMouseListener());
  152.        
  153.        bMove = new JButton("MOVE");
  154.        bMove.setBackground(Color.white);
  155.        bMove.setBounds(icon.getIconWidth()+10,90,100, 20);
  156.        bMove.addMouseListener(new boardMouseListener());
  157.        
  158.        // Place the action buttons in the top layer
  159.        bPane.add(bAct, new Integer(2));
  160.        bPane.add(bRehearse, new Integer(2));
  161.        bPane.add(bMove, new Integer(2));
  162.   }
  163.  
  164.   // This class implements Mouse Events
  165.   class boardMouseListener implements MouseListener{
  166.      
  167.       // Code for the different button clicks
  168.       public void mouseClicked(MouseEvent e) {
  169.          if (e.getSource()== bAct){
  170.            
  171.             //playerlabel.setVisible(true);
  172.             //System.out.println("Acting is Selected\n");\
  173.  
  174.  
  175.          }
  176.          else if (e.getSource()== bRehearse){
  177.             System.out.println("Rehearse is Selected\n");
  178.          }
  179.          else if (e.getSource()== bMove){
  180.             System.out.println("Move is Selected\n");
  181.          }        
  182.       }
  183.      
  184.       public void mousePressed(MouseEvent e) {
  185.       }
  186.      
  187.       public void mouseReleased(MouseEvent e) {
  188.       }
  189.      
  190.       public void mouseEntered(MouseEvent e) {
  191.       }
  192.      
  193.       public void mouseExited(MouseEvent e) {
  194.       }
  195.      
  196.    }
  197.  
  198.  
  199.  
  200.   //public static void main(String[] args) {
  201.    
  202.      // BoardLayersListener board = new BoardLayersListener();
  203.      // board.setVisible(true);
  204.    
  205.     // Take input from the user about number of players
  206.    // JOptionPane.showInputDialog(board, "How many players?");
  207.    
  208.  
  209.  // }
  210.  
  211.  
  212.   // this method will add cards to the board
  213.   public void addCards(Room room) {
  214.    
  215.     cardlabel = new JLabel();
  216.     ImageIcon cardImage = new ImageIcon("01.png");
  217.     cardlabel.setIcon(cardImage);
  218.     cardlabel.setBounds((int)room.getCardArea().getX(),(int)room.getCardArea().getY(), cardImage.getIconWidth(),cardImage.getIconHeight());
  219.     cardlabel.setOpaque(true);
  220.     bPane.add(cardlabel, new Integer(1));
  221.      
  222.   }
  223.  
  224.  
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement