Está en la página 1de 8

TECNÓLOGO EN DESARROLLO DE SOFTWARE

Nombre:
Warling Manuel Guzmán Burgos

Matrícula:
2022-0187

Grupo:
Grupo #4

Asignatura:
Programación 1

Profesor:
Freidy Núñez

2023

This study source was downloaded by 100000849293786 from CourseHero.com on 07-13-2023 15:19:37 GMT -05:00

https://www.coursehero.com/file/197002874/Tarea-de-recuperacionpdf/
Se debe crear una aplicación que permita gestionar jugadores de un equipo de
fútbol. La aplicación debe permitir agregar, modificar y eliminar jugadores, así como
también mostrar una lista de todos los jugadores registrad os.
La aplicación debe contar con una interfaz gráfica de usuario implementada con Java
Swing y Windows Builder.
Los jugadores deben ser objetos que se almacenan en una lista y se deben poder
clasificar según su posición en el campo de juego (delantero, medio campista,
defensa, portero). Cada jugador debe contar con un número de identificación,
nombre, edad y posició n.

Como puede ver maestro mi aplicación cumple con todos los


requisitos que pide en el mandato de la tarea, el ID viene siendo
como los jugadores pueden ser identificados, en este caso yo lo
puse que se identifiquen con el número de camiseta.

CODIGO

This study source was downloaded by 100000849293786 from CourseHero.com on 07-13-2023 15:19:37 GMT -05:00

https://www.coursehero.com/file/197002874/Tarea-de-recuperacionpdf/
Aquí le estaré dejando el codigo tanto
como escribo como .java por si quiere
manipularlo.

JugadoresApp.java

package wali;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;

public class JugadoresApp extends JFrame implements ActionListener {


// Definir componentes de la interfaz gráfica
private JTextField idField, nombreField, edadField;
private JComboBox<String> posicionCombo;
private JButton addButton, editButton, deleteButton;
private JList<String> list;
private DefaultListModel<String> model;
private ArrayList<Jugador> jugadores;

public JugadoresApp() {
// Configuración de la ventana
setTitle("Equipo de Wali");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Crear componentes de la interfaz gráfica


idField = new JTextField();

This study source was downloaded by 100000849293786 from CourseHero.com on 07-13-2023 15:19:37 GMT -05:00

https://www.coursehero.com/file/197002874/Tarea-de-recuperacionpdf/
nombreField = new JTextField();
edadField = new JTextField();
posicionCombo = new JComboBox<>(new String[] {"Delantero", "Medio
campista", "Defensa", "Portero"});
addButton = new JButton("Añadir");
editButton = new JButton("Editar");
deleteButton = new JButton("pa fuera");
model = new DefaultListModel<>();
list = new JList<>(model);
jugadores = new ArrayList<>();

// Agregar componentes a la ventana


Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
JPanel formPanel = new JPanel(new GridLayout(4, 2));
formPanel.add(new JLabel("ID:"));
formPanel.add(idField);
formPanel.add(new JLabel("Nombre:"));
formPanel.add(nombreField);
formPanel.add(new JLabel("Edad:"));
formPanel.add(edadField);
formPanel.add(new JLabel("Posición:"));
formPanel.add(posicionCombo);
contentPane.add(formPanel, BorderLayout.NORTH);
contentPane.add(new JScrollPane(list), BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new GridLayout(1, 3));
buttonPanel.add(addButton);
buttonPanel.add(editButton);
buttonPanel.add(deleteButton);
contentPane.add(buttonPanel, BorderLayout.SOUTH);

This study source was downloaded by 100000849293786 from CourseHero.com on 07-13-2023 15:19:37 GMT -05:00

https://www.coursehero.com/file/197002874/Tarea-de-recuperacionpdf/
// Configurar eventos de los botones
addButton.addActionListener(this);
editButton.addActionListener(this);
deleteButton.addActionListener(this);
}

// Método para añadir un jugador a la lista


private void addJugador(Jugador jugador) {
jugadores.add(jugador);
actualizarLista();
}

// Método para editar un jugador de la lista


private void editJugador(int index, Jugador jugador) {
jugadores.set(index, jugador);
actualizarLista();
}

// Método para borrar un jugador de la lista


private void deleteJugador(int index) {
jugadores.remove(index);
actualizarLista();
}

// Método para actualizar la lista de jugadores en la interfaz gráfica


private void actualizarLista() {
model.clear();
for (Jugador jugador : jugadores) {

This study source was downloaded by 100000849293786 from CourseHero.com on 07-13-2023 15:19:37 GMT -05:00

https://www.coursehero.com/file/197002874/Tarea-de-recuperacionpdf/
model.addElement(jugador.getId() + ": " + jugador.getNombre() +
" - " + jugador.getPosicion());
}
}

// Método para manejar los eventos de los botones


public void actionPerformed(ActionEvent e) {
if (e.getSource() == addButton) {
int id = Integer.parseInt(idField.getText());
String nombre = nombreField.getText();
int edad = Integer.parseInt(edadField.getText());
String posicion = (String) posicionCombo.getSelectedItem();
Jugador jugador = new Jugador(id, nombre, edad, posicion);
addJugador(jugador);
} else if (e.getSource() == editButton) {
int index = list.getSelectedIndex();
if (index != -1) {
int id = Integer.parseInt(idField.getText());
String nombre = nombreField.getText();
int edad = Integer.parseInt(edadField.getText());
String posicion = (String) posicionCombo.getSelectedItem();
Jugador jugador = new Jugador(id, nombre, edad, posicion);
editJugador(index, jugador);
}
} else if (e.getSource() == deleteButton) {
int index = list.getSelectedIndex();
if (index != -1) {
deleteJugador(index);
}
}

This study source was downloaded by 100000849293786 from CourseHero.com on 07-13-2023 15:19:37 GMT -05:00

https://www.coursehero.com/file/197002874/Tarea-de-recuperacionpdf/
}
// Clase para representar un jugador
private class Jugador {
private int id;
private String nombre;
private int edad;
private String posicion;

public Jugador(int id, String nombre, int edad, String posicion) {


this.id = id;
this.nombre = nombre;
this.edad = edad;
this.posicion = posicion;
}

public int getId() {


return id;
}

public String getNombre() {


return nombre;
}

public int getEdad() {


return edad;
}

public String getPosicion() {


return posicion;
}

This study source was downloaded by 100000849293786 from CourseHero.com on 07-13-2023 15:19:37 GMT -05:00

https://www.coursehero.com/file/197002874/Tarea-de-recuperacionpdf/
}

public static void main(String[] args) {


JugadoresApp app = new JugadoresApp();
app.setVisible(true);
}
}

This study source was downloaded by 100000849293786 from CourseHero.com on 07-13-2023 15:19:37 GMT -05:00

https://www.coursehero.com/file/197002874/Tarea-de-recuperacionpdf/
Powered by TCPDF (www.tcpdf.org)

También podría gustarte