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

I need help trying to complete this application and dont have any Idea on where

ID: 3768898 • Letter: I

Question

I need help trying to complete this application and dont have any Idea on where to start. I need help!

This application maintains a roster for a sports team. Each player has a last name, a first name, and a number.

1. Create a Player class to represent a player. The class will include methods to set and get the first name, last name, and number. Add any other methods you need to complete the application requirements.

2. Create an array list to store the Player objects. The array list should be populated with a default roster that is coded in the JFrame’s constructor. Add a least 5 players to the array list. Use the array list to populate the combo box.

3. When the application is initially displayed, the first player in the combo box is selected and displayed in the text field controls. The text field controls are disabled so the user can’t modify the contents. The Accept and Cancel buttons are also disabled.

4. When a player is selected from the combo box, the application lists the player’s name and number in the text fields. The user can then click the Edit or Delete button to edit or delete the player.

5. If the user clicks the Edit button, the text fields are enabled, the Add, Edit, and Delete buttons are disabled, and the Accept and Cancel buttons are enabled. If the user then clicks the Accept button, any changes the user made to the player’s data are saved to the Player object in the array list. If the user clicks Cancel, any changes are discarded. After the Accept or Cancel buttons are clicked: the Accept and Cancel buttons are disabled the Add, Edit, and Delete buttons are enabled the Text Fields are disabled 2 of 2

6. If the user clicks the Delete button, the player object is immediately removed from the array list and combo box. The combo box selected index property is set to 0 (first player in the combo box).

7. If the user clicks the Add button, the text fields are cleared and enabled, the Add, Edit, and Delete buttons are disabled, and the Accept and Cancel buttons are enabled. The user can then enter data for a new player and click the Accept button to add the player. If the Accept button is clicked, a new player instance is populated with the values entered in the text fields and added to the array list. If the user clicks the Cancel button, the player is not added. After the Accept or Cancel buttons are clicked: the Accept and Cancel buttons are disabled the Add, Edit, and Delete buttons are enabled the Text Fields are disabled

8. When the user clicks the Exit button, end the application.

Explanation / Answer

Complete Program:

// File: TeamRoster.java
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
public class TeamRoster extends JFrame implements ActionListener
{
private ArrayList<Player> players;
private JLabel jlblSelect = new JLabel("Select player: ");
private JLabel jlblLastName = new JLabel("Last name:      ");
private JLabel jlblFirstName = new JLabel("First name:      ");
private JLabel jlblNumber = new JLabel("Number:           ");

private JComboBox<Player> combobox = new JComboBox<Player>();
private JTextField jtfLastName = new JTextField(20);
private JTextField jtfFirstName = new JTextField(20);
private JTextField jtfNumber = new JTextField(20);

private JButton jbtnAdd = new JButton("Add");
private JButton jbtnEdit = new JButton("Edit");
private JButton jbtnDelete = new JButton("Delete");
private JButton jbtnAccept = new JButton("Accept");
private JButton jbtnCancel = new JButton("Cancel");
private JButton jbtnExit = new JButton("Exit");

private JPanel panel1 = new JPanel();
private JPanel panel2 = new JPanel();
private JPanel panel3 = new JPanel();
private JPanel panel4 = new JPanel();
private JPanel panel5 = new JPanel();
private JPanel panel6 = new JPanel();
  
public TeamRoster()
{
  players = new ArrayList<Player>();
  
  players.add(new Player("Berg", "Laura", 44));
  players.add(new Player("Bustos", "Crystl", 6));
  players.add(new Player("Clark", "Jamie", 24));
  players.add(new Player("Fernandez", "Lisa", 16));
  players.add(new Player("Finch", "Jennie", 27));
  
  for(Player player : players)
   combobox.addItem(player);
  
  panel1.add(jlblSelect);
  panel1.add(combobox);
  
  panel2.add(jlblLastName);
  panel2.add(jtfLastName);
  
  panel3.add(jlblFirstName);
  panel3.add(jtfFirstName);
  
  panel4.add(jlblNumber);
  panel4.add(jtfNumber);
  
  panel5.add(jbtnAdd);
  panel5.add(jbtnEdit);
  panel5.add(jbtnDelete);
  panel5.add(jbtnAccept);
  panel5.add(jbtnCancel);
  
  panel6.add(jbtnExit);  
  
  setLayout(new FlowLayout());
  add(panel1);
  add(panel2);
  add(panel3);
  add(panel4);
  add(panel5);
  add(panel6);
    
  Player currentPlayer = (Player) combobox.getSelectedItem();
  showPlayer(currentPlayer);
  
  jbtnAccept.setEnabled(false);
  jbtnCancel.setEnabled(false);
  
  combobox.addActionListener(this);
  jbtnAdd.addActionListener(this);
  jbtnEdit.addActionListener(this);
  jbtnDelete.addActionListener(this);
  jbtnAccept.addActionListener(this);
  jbtnCancel.addActionListener(this);
  jbtnExit.addActionListener(this);
}

public void actionPerformed(ActionEvent ae)
{
  Object source = ae.getSource();
  Player currentPlayer;
  boolean isNewPlayer = false;
  
  if(source == combobox)
  {
   currentPlayer = (Player) combobox.getSelectedItem();
  
   showPlayer(currentPlayer);
  }
  else if(source == jbtnAdd)
  {
   isNewPlayer = true;
   
   jtfLastName.setText("");
   jtfFirstName.setText("");
   jtfNumber.setText("0");
   
   jtfLastName.setEnabled(true);
   jtfFirstName.setEnabled(true);
   jtfNumber.setEnabled(true);
   
   jbtnAdd.setEnabled(false);
   jbtnEdit.setEnabled(false);
   jbtnDelete.setEnabled(false);
   
   jbtnAccept.setEnabled(true);
   jbtnCancel.setEnabled(true);
  }
  else if(source == jbtnEdit)
  {
   isNewPlayer = false;
   
   jtfLastName.setEnabled(true);
   jtfFirstName.setEnabled(true);
   jtfNumber.setEnabled(true);
   
   jbtnAdd.setEnabled(false);
   jbtnEdit.setEnabled(false);
   jbtnDelete.setEnabled(false);
   
   jbtnAccept.setEnabled(true);
   jbtnCancel.setEnabled(true);
   
  }
  else if(source == jbtnDelete)
  {
   
  }
  else if(source == jbtnAccept)
  {
   if(isNewPlayer)
   {
    currentPlayer = new Player(jtfLastName.getText(), jtfFirstName.getText(), Integer.parseInt(jtfNumber.getText()));
    
    players.add(currentPlayer);   
    combobox.addItem(currentPlayer);
    
    combobox.setSelectedIndex(players.size() - 1);
    currentPlayer = (Player) combobox.getSelectedItem();
    showPlayer(currentPlayer);
   }
   else
   {    
   }
   
   jbtnAccept.setEnabled(false);
   jbtnCancel.setEnabled(false);
   
   jbtnAdd.setEnabled(true);
   jbtnEdit.setEnabled(true);
   jbtnDelete.setEnabled(true);
  }
  else if(source == jbtnCancel)
  {
   jbtnAccept.setEnabled(false);
   jbtnCancel.setEnabled(false);
   
   jbtnAdd.setEnabled(true);
   jbtnEdit.setEnabled(true);
   jbtnDelete.setEnabled(true);
  }
  else // source == jbtnExit
  {
   System.exit(0);
  }
}

private void showPlayer(Player currentPlayer)
{
  jtfLastName.setText(currentPlayer.getLastName());
  jtfFirstName.setText(currentPlayer.getFirstName());
  jtfNumber.setText("" + currentPlayer.getNumber());
  
  jtfLastName.setEnabled(false);
  jtfFirstName.setEnabled(false);
  jtfNumber.setEnabled(false);
}

public static void main(String[] args)
{
  TeamRoster roster = new TeamRoster();
  roster.setTitle("Team Roster");
  roster.setSize(400, 280);
  roster.setVisible(true);
  roster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

Sample Output:

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