Package com.google.code.timetrail.gui

Source Code of com.google.code.timetrail.gui.TakingMoveFrame

/*
* TakingMoveFrame.java
* Team qq 2011
*/
package com.google.code.timetrail.gui;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.google.code.timetrail.backend.*;
import com.google.code.timetrail.presenter.EventFrameBackend;
import com.google.code.timetrail.presenter.TakingMoveFrameBackend;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import java.awt.Component;
import javax.swing.JSeparator;

public class TakingMoveFrame extends JPanel {

  /**
   *
   */
  private static final long serialVersionUID = 1L;

  private TakingMoveFrameBackend takingMoveFrameBackend;
 
  /**
   * Create the panel.
   */
  private Control myGameControl;
  private JPanel myCD;
  private JLabel foodStatusLabel;
  private JLabel distanceStatusLabel;
  private JLabel rationsStatusLabel;
  private JLabel paceStatusLabel;
  private JLabel currentLocationStatusLabel;

  private JLabel turnStatusLabel;
  private MapPanel panel;
  private JButton changePaceRationsButton;
  private JButton takeTurnButton;
  private JButton btnInventory;

 
  public TakingMoveFrame(Control gameControl, JPanel cd, String previous) {
    //setBounds(new Rectangle(0, 0, 600, 200));
    this.myGameControl = gameControl;
    this.myCD = cd;
    takingMoveFrameBackend = new TakingMoveFrameBackend(myGameControl);
   
    turnStatusLabel = new JLabel(takingMoveFrameBackend.getTurnLabelText());
   
    foodStatusLabel = new JLabel(takingMoveFrameBackend.getFoodLabelText());
   
    distanceStatusLabel = new JLabel(takingMoveFrameBackend.getDistanceLabelText());
   
    rationsStatusLabel = new JLabel(takingMoveFrameBackend.getRationsLabelText());
   
    paceStatusLabel = new JLabel(takingMoveFrameBackend.getPaceLabelText());
   
    currentLocationStatusLabel = new JLabel(takingMoveFrameBackend.getCurrentLocText());
   
    changePaceRationsButton = new JButton(takingMoveFrameBackend.getPaceRationsButtonText());
    changePaceRationsButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        myCD.add(new RationsPaceFrame(myGameControl, myCD, "TakeMove"), "name_1317840867491837002");
                CardLayout cd = (CardLayout) myCD.getLayout();
                cd.last(myCD);
      }
    });
   
 
    
    //panel = new mapPanel("background2.gif","spaceship.jpg",gameControl);
    //panel.setBounds(0, 0, this.getSize().width, this.getSize().height);
      //panel.setBorder(BorderFactory.createLineBorder (Color.black, 2));
    //add(panel);
   
    takeTurnButton = new JButton(takingMoveFrameBackend.getContinueButtonText());
    takeTurnButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
          myGameControl.setNextEvent(myGameControl.getRandomEvent());
        if(myGameControl.getCurrentPlace().equals(Place.OREGON)){
          takeTurnButton.setEnabled(false);
        }
        if(takingMoveFrameBackend.isRiverCrossing()){
         
         
          myCD.add(new RiverFrame(myGameControl, myCD), "");
          CardLayout cd = (CardLayout) myCD.getLayout();
          cd.last(myCD);
         
        } else if(takingMoveFrameBackend.isStore()){
            myCD.add(new StoreFrame(myGameControl, myCD), "");
                    CardLayout cd = (CardLayout) myCD.getLayout();
                    cd.last(myCD);
        }
        if(takingMoveFrameBackend.hasEvent() && !takingMoveFrameBackend.isStore() && !takingMoveFrameBackend.isRiverCrossing()){
            myGameControl.getNextEvent().action();
          EventFrameBackend eventFrameBackend = new EventFrameBackend(myGameControl.getNextEvent());
          myCD.add(new EventFrame(myGameControl, eventFrameBackend, myCD), "newEvent");
          myGameControl.setNextEvent(new Event());
          CardLayout cd = (CardLayout) myCD.getLayout();
          cd.last(myCD);
        }
        takingMoveFrameBackend.pressContinue();
        foodStatusLabel.setText(takingMoveFrameBackend.getFoodLabelText());
        distanceStatusLabel.setText(takingMoveFrameBackend.getDistanceLabelText());
        turnStatusLabel.setText(takingMoveFrameBackend.getTurnLabelText());
        currentLocationStatusLabel.setText(takingMoveFrameBackend.getCurrentLocText());
        panel.repaint();
       
       
      }
    });
   
    panel= new MapPanel("assets/images/space_background.jpg","assets/images/spaceship.png",gameControl);
    panel.setBorder(BorderFactory.createLineBorder (Color.black, 1));
   
   
    JSeparator separator = new JSeparator();
   
    btnInventory = new JButton("Inventory");
    btnInventory.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            myCD.add(new InventoryFrame(myGameControl, myCD), "");
                CardLayout cd = (CardLayout) myCD.getLayout();
                cd.last(myCD);
        }
    });
   

    GroupLayout groupLayout = new GroupLayout(this);
    groupLayout.setHorizontalGroup(
        groupLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(groupLayout.createSequentialGroup()
                .addGap(68)
                .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                    .addGroup(groupLayout.createSequentialGroup()
                        .addComponent(takeTurnButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(117))
                    .addGroup(groupLayout.createSequentialGroup()
                        .addComponent(btnInventory)
                        .addPreferredGap(ComponentPlacement.RELATED)))
                .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                    .addComponent(changePaceRationsButton, GroupLayout.PREFERRED_SIZE, 161, GroupLayout.PREFERRED_SIZE)
                    .addComponent(turnStatusLabel, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
                    .addComponent(foodStatusLabel, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
                    .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
                        .addComponent(currentLocationStatusLabel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(paceStatusLabel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(rationsStatusLabel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(distanceStatusLabel, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)))
                .addGap(93))
            .addGroup(Alignment.LEADING, groupLayout.createSequentialGroup()
          .addContainerGap()
          .addComponent(panel, GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE)
          .addContainerGap())
            .addGroup(groupLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(separator, GroupLayout.DEFAULT_SIZE, 494, Short.MAX_VALUE)
                .addContainerGap())
    );
    groupLayout.setVerticalGroup(
        groupLayout.createParallelGroup(Alignment.TRAILING)
            .addGroup(groupLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panel, GroupLayout.PREFERRED_SIZE, 178, GroupLayout.PREFERRED_SIZE)
          .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(separator, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                    .addGroup(groupLayout.createSequentialGroup()
                        .addGap(8)
                        .addComponent(turnStatusLabel, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
                        .addGap(11)
                        .addComponent(foodStatusLabel, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
                        .addGap(11)
                        .addComponent(distanceStatusLabel, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
                        .addGap(11)
                        .addComponent(rationsStatusLabel, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(ComponentPlacement.RELATED, 101, Short.MAX_VALUE)
                        .addComponent(paceStatusLabel, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
                        .addGap(11)
                        .addComponent(currentLocationStatusLabel, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(ComponentPlacement.UNRELATED)
                        .addComponent(changePaceRationsButton, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
                        .addGap(16))
                    .addGroup(groupLayout.createSequentialGroup()
                        .addPreferredGap(ComponentPlacement.RELATED, 131, Short.MAX_VALUE)
                        .addComponent(takeTurnButton, GroupLayout.PREFERRED_SIZE, 46, GroupLayout.PREFERRED_SIZE)
                        .addGap(52)
                        .addComponent(btnInventory)
                        .addGap(27))))
    );
    groupLayout.linkSize(SwingConstants.HORIZONTAL, new Component[] {turnStatusLabel, foodStatusLabel, distanceStatusLabel, rationsStatusLabel, paceStatusLabel, currentLocationStatusLabel, changePaceRationsButton});
        setLayout(groupLayout);
  }
}
TOP

Related Classes of com.google.code.timetrail.gui.TakingMoveFrame

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.