Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Response to comments: no claases provided for NBATeam and NBAcourtPanel. I believe it has to be written from scratch.) Write a java program to simulate

(Response to comments: no claases provided for NBATeam and NBAcourtPanel. I believe it has to be written from scratch.)

Write a java program to simulate showing an NBA Team on a Basketball court. Here is an example of the screenshot when running the program:

image text in transcribed

An example of the JFrame subclass with main method is as follows:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class NBAPlayoff extends JFrame {

private JTextField txtName;

private JTextField txtAge;

private NBATeam spurs;

private NBAcourtPanel court;

private JLabel lMax, lMin, lAvg, lNum;

public NBAPlayoff(){

spurs=new NBATeam("Spurs");

court=new NBAcourtPanel(spurs);

add(court, BorderLayout.CENTER);

JLabel lMax0=new JLabel("Max Age:");

lMax=new JLabel("");

JLabel lMin0=new JLabel("Min Age:");

lMin=new JLabel("");

JLabel lAvg0=new JLabel("Average Age:");

lAvg=new JLabel("");

JLabel lNum0=new JLabel("Number of Players:");

lNum =new JLabel("");

JPanel rp=new JPanel(new GridLayout(8, 1)); //right panel

rp.add(lNum0);rp.add(lNum);rp.add(lMax0);rp.add(lMax);

rp.add(lMin0);rp.add(lMin);rp.add(lAvg0);rp.add(lAvg);

add(rp, BorderLayout.EAST);

JLabel l1=new JLabel("Player Name:");

txtName= new JTextField();

txtName.setPreferredSize(new Dimension(120,24));

JLabel l2=new JLabel("Player Age:");

txtAge= new JTextField();

txtAge.setPreferredSize(new Dimension(120,24));

JButton jbtAdd=new JButton("Add A Player");

jbtAdd.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int age=Integer.parseInt(txtAge.getText());

spurs.addAPlayer(txtName.getText(), age);

lMax.setText(spurs.getMaxAge()+"");

lMin.setText(spurs.getMinAge()+"");

lAvg.setText(spurs.getAvgAge()+"");

lNum.setText(spurs.getNumOfPlayer()+"");

court.repaint();

}});

JButton jbtClear= new JButton("Clear");

jbtClear.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

txtName.setText("");

txtAge.setText("");

}});

JPanel pBot=new JPanel();

pBot.add(l1); pBot.add(txtName); pBot.add(l2);pBot.add(txtAge); pBot.add(jbtAdd);pBot.add(jbtClear);

add(pBot, BorderLayout.SOUTH);

}

public static void main(String[] args) {

NBAPlayoff frame = new NBAPlayoff();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setLocationRelativeTo(null);

frame.setSize(800, 400);

frame.setVisible(true);

}

}

Number of Players: Max Age Tony Parker K. Leonared T. Splitter T. Duncan M. Ginobili 32 Min Age Age 21 Average Age 28 Player Name: MGinobill Player Age Add A Player Clear

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions