Class Main GUI
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MainGUI extends JFrame {
Team team;
private class ButtonListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e){
}
public static void main(String[] args) {
new MainGUI("Team manager").setVisible(true);
}
private final JButtonbtCreateTeam;
public MainGUI(){
btCreateTeam= new JButton("Creat Team");
btAddOnePlayer= new JButton("Add player");
btAddRe= new JButton("Add remaining players");
btExit= new JButton ("Exit");
lablTeamName= new JLabel ("Team name: ");
lablPlayersCount= new JLabel ("Players count: ");
lablMaxTeamSize= new JLabel ("Max team size: ");
tpPanel= new JPanel();
tpPanel.setLayout(new GridLayout(1,2));
tpPanel.add(lablTeamName);
tpPanel.add(lablPlayersCount);
tpPanel.add(lablMaxTeamSize);
btnPanel= new JPanel();
btnPanel.setLayout(new GridLayout(3,3));
btnPanel.add(btCreateTeam);
btnPanel.add(btAddOnePlayer);
btnPanel.add(btAddRe);
btnPanel.add(btExit);
btCreateTeam.addActionListener(new ButtonWatcher());
btAddOnePlayer.addActionListener(new ButtonWatcher());
btAddRe.addActionListener(new ButtonWatcher());
btExit.addActionListener(new ButtonWatcher());
} Container cont = getContentPane();
cont.add(tpPanel, BorderLayout.NORTH);
cont.add(textArea, BorderLayout.CENTER);
cont.add(btnPanel, BorderLayout.SOUTH);
}
public static void main(String[]args){
MainGUI test = new MainGUI();
}
}//the end of class
Class Team
import java.util.ArrayList;
import java.util.Scanner;
public class Team {
private String name;
private int count;
private int size;
private ArrayList<Player>players;
public Team(){
Scanner scan=new Scanner(System.in);
System.out.println("What is your team name?");
name=scan.nextLine();
System.out.println("How many players are in the team?");
size=scan.nextInt();
players=new ArrayList<Player>(size);
System.out.println("Do you want to build your team now (Y/N)?");
scan.nextLine();
String choice = scan.nextLine();
switch(choice){
case "Y":
case "y":
addPlayers();
break;
case "N":
case "n":
System.out.println("No Player were added.");
break;
default:
System.out.println("Do you want to build your team now (Y/N)? ");
choice = scan.nextLine();
}
}
public String getName(){
return name;
}
public intgetSize(){
return size;
}
public intgetCount(){
return count;
}
public void setName(String name){
this.name=name;
}
public void setSize(int size){
this.size=size;
}
public void setCount(int count){
this.count=count;
}
public booleanaddPlayer(Player p1){
if(count>=size){
System.out.println("Team is full, failed to add player.");
return false;
}else{
players.add(p1);
count++;
System.out.println("Player added!");
return true;
}
}
public static Player createPlayer() {
JOptionPane.showMessageDialog(null,"Enter player info");
String playerName=JOptionPane.showInputDialog(null,"Nam:");
double playerAge=Double.parseDouble(JOptionPane.showInputDialog(null,"Age:"));
int playerNumber=Integer.parseInt(JOptionPane.showInputDialog(null,"Number:"));
Player pl = new Player( playerName,playerAge,playerNumber);
return pl;
}
I know the answer to your problem, which is a very simple mistake and can be cleared with ease. But as you have no clue & common sense I will not help you.