Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

AiPlayerUi.java 1. 2. Create class AiPlayerUi so it uses class JPanel as the sup

ID: 3708241 • Letter: A

Question

AiPlayerUi.java 1. 2. Create class AiPlayerUi so it uses class JPanel as the superclass Add member variables of type a. AiPlayer ai b, int position; c. ArrayList Jabel> cards; 3. A custom constructor should be defined that receives a two parameters; one is data type class Player, the other is data type int Set member variable of type class AiPlayer to the parameter passed in of class Player using an explicit type cast Set member variable position to the parameter of data type int Call method initComponentso a. b. c. 4. Write method initComponents) to initialize all the components for the UI and be called from the constructor Set the size of the JPanel using two methods to ensure the UI isn't too small a. i. setMinimumSize0 ii. setPreferredSize0 Instantiate the member variable of data type ArrayList containing elements of class JLabel Using an if statement check if the position is 1 or 3 b. c. i. If true, set the layout manager to use BoxLayout so it is aligned on the Y axis ii. Else, set the layout manager to use Boxayout so it is aligned on the X axis d. Call method displayCardsO Write method displayCards to do the following 5. Loop through the member variable of data type ArrayList containing elements of class JLabel so there are 13 JLabels a. i. Instantiate an instance of class JLabel ii. Set the size of the JLabel iii. Add a border to the Label iv. Set the text of the JLabel to explicit text "Card" concatenated with the looping variable v. Add the JLabel to the ArrayList vi. Add the JLabel to the JPanel

Explanation / Answer


import com.sun.prism.paint.Color;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
public class AiPlayerUi extends javax.swing.JPanel {
// Instance Variables
   private AiPlayer ai;
   private int position;
   private ArrayList<JLabel> cards;

   // Constructor
   public AiPlayerUi(int position, Player player) {
       this.position = position;
       this.ai = (AiPlayer) player;
       initComponents();
                cards=new ArrayList<>();
              
                //To check position
                if(position==1 ||position==3)
                {
                setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));  
                }
                else
                {
                    setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.X_AXIS));
                }
                      
   }

   public AiPlayer getAiPlayer() {
       return ai;
   }

   public void setAiPlayer(AiPlayer ai) {
       this.ai = ai;
   }

   public int getPosition() {
       return position;
   }

   public void setPosition(int position) {
       this.position = position;
   }

   public ArrayList<JLabel> getCards() {
       return cards;
   }

   public void setCards(ArrayList<JLabel> cards) {
       this.cards = cards;
   }
      
      
      
        //Method display Cards
        public void displayCards()
        {
            for(int i=1;i<=cards.size();i++)
            {
                JLabel label=new JLabel();
              
                //Set Size
                label.setSize(50,60); //Add Size accordingly
                // create a line border with red color and set it to lable
                label.setBorder(BorderFactory.createLineBorder(Color.RED, 5));
                //Set Text
                label.setText("CARD"+i);
              
                //Add jLabel to Arraylist
                cards.add(label);
                //ADD LABEL TO JPANEL
                add(label);
            }
        }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                        
    private void initComponents() {

        setMinimumSize(new java.awt.Dimension(600, 400));
        setPreferredSize(new java.awt.Dimension(500, 250));
        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.LINE_AXIS));
    }// </editor-fold>                      


    // Variables declaration - do not modify                   
    // End of variables declaration                 
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote