Below is a simplified example using Java Swing for the GUI and a simple data structure for storing runner information. Note that this is a basic mockup that I made but I still need to improve on. import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class RunnerGUI extends JFrame { private List runners = new ArrayList<>(); private JTextField nameField, distanceField, timeField; private DefaultListModel listModel; public RunnerGUI() { // Set up JFrame setTitle("Runner Information"); setSize(400, 300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create components nameField = new JTextField(20); distanceField = new JTextField(10); timeField = new JTextField(10); listModel = new DefaultListModel<>(); JList listView = new JList<>(listModel); JButton addButton = new JButton("Add Runner"); JButton sortButton = new JButton("Sort List"); JButton saveButton = new JButton("Save to CSV"); // Add components to the frame setLayout(new BorderLayout()); JPanel inputPanel = new JPanel(); inputPanel.add(new JLabel("Name:")); inputPanel.add(nameField); inputPanel.add(new JLabel("Distance:")); inputPanel.add(distanceField); inputPanel.add(new JLabel("Time:")); inputPanel.add(timeField); inputPanel.add(addButton); inputPanel.add(sortButton); inputPanel.add(saveButton); add(inputPanel, BorderLayout.NORTH); add(new JScrollPane(listView), BorderLayout.CENTER); // Add ActionListener for buttons addButton.addActionListener(new ActionListener() {  @Override public void actionPerformed(ActionEvent e) { addRunner(); } }); sortButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { sortList(); } }); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveToCSV(); } }); } private void addRunner() { String name = nameField.getText(); double distance = Double.parseDouble(distanceField.getText()); double time = Double.parseDouble(timeField.getText()); double pace = time / distance; Runner runner = new Runner(name, distance, time, pace); runners.add(runner); updateListView(); clearFields(); } private void sortList() { // Implement sorting based on radio button selection // For simplicity, let's sort by name in ascending order Collections.sort(runners, Comparator.comparing(Runner::getName)); updateListView(); } private void saveToCSV() { try (BufferedWriter writer = new BufferedWriter(new FileWriter("finalProjectRunners.txt"))) { for (Runner runner : runners) { String line = String.format("%s,%.2f,%.2f,%.2f", runner.getName(), runner.getDistance(), runner.getTime(), runner.getPace()); writer.write(line); writer.newLine(); } JOptionPane.showMessageDialog(this, "Data saved to CSV file."); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "Error saving to CSV file."); } } private void updateListView() { listModel.clear(); for (Runner runner : runners) { String displayText = String.format("Name: %s, Distance: %.2f, Time: %.2f, Pace: %.2f", runner.getName(), runner.getDistance(), runner.getTime(), runner.getPace()); listModel.addElement(displayText); } } private void clearFields() { nameField.setText(""); distanceField.setText(""); timeField.setText(""); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new RunnerGUI().setVisible(true); } }); } } class Runner { private String name;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Below is a simplified example using Java Swing for the GUI and a simple data structure for storing runner information. Note that this is a basic mockup that I made but I still need to improve on.

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.BufferedWriter;

import java.io.FileWriter;

import java.io.IOException;

import java.util.ArrayList;

import java.util.Collections;

import java.util.Comparator;

import java.util.List; public class RunnerGUI extends JFrame {

private List<Runner> runners = new ArrayList<>();

private JTextField nameField, distanceField, timeField;

private DefaultListModel<String> listModel;

public RunnerGUI() {

// Set up JFrame setTitle("Runner Information");

setSize(400, 300);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Create components nameField = new JTextField(20);

distanceField = new JTextField(10);

timeField = new JTextField(10); listModel = new DefaultListModel<>();

JList<String> listView = new JList<>(listModel);

JButton addButton = new JButton("Add Runner");

JButton sortButton = new JButton("Sort List");

JButton saveButton = new JButton("Save to CSV");

// Add components to the frame setLayout(new BorderLayout());

JPanel inputPanel = new JPanel(); inputPanel.add(new JLabel("Name:"));

inputPanel.add(nameField);

inputPanel.add(new JLabel("Distance:"));

inputPanel.add(distanceField);

inputPanel.add(new JLabel("Time:"));

inputPanel.add(timeField);

inputPanel.add(addButton); inputPanel.add(sortButton);

inputPanel.add(saveButton);

add(inputPanel, BorderLayout.NORTH);

add(new JScrollPane(listView), BorderLayout.CENTER);

// Add ActionListener for buttons

addButton.addActionListener(new ActionListener() { 

@Override

public void actionPerformed(ActionEvent e) { addRunner();

}

});

sortButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) { sortList();

}

});

saveButton.addActionListener(new ActionListener()

{

@Override

public void actionPerformed(ActionEvent e)

{

saveToCSV();

}

});

}

private void addRunner()

{

String name = nameField.getText();

double distance = Double.parseDouble(distanceField.getText());

double time = Double.parseDouble(timeField.getText());

double pace = time / distance;

Runner runner = new Runner(name, distance, time, pace);

runners.add(runner);

updateListView();

clearFields(); }

private void sortList()

{

// Implement sorting based on radio button selection

// For simplicity, let's sort by name in ascending order Collections.sort(runners, Comparator.comparing(Runner::getName));

updateListView();

}

private void saveToCSV() { try (BufferedWriter writer = new BufferedWriter(new FileWriter("finalProjectRunners.txt")))

{

for (Runner runner : runners) { String line = String.format("%s,%.2f,%.2f,%.2f", runner.getName(), runner.getDistance(), runner.getTime(), runner.getPace());

writer.write(line);

writer.newLine(); } JOptionPane.showMessageDialog(this, "Data saved to CSV file."); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "Error saving to CSV file."); } } private void updateListView() { listModel.clear();

for (Runner runner : runners) { String displayText = String.format("Name: %s, Distance: %.2f, Time: %.2f, Pace: %.2f", runner.getName(), runner.getDistance(), runner.getTime(), runner.getPace()); listModel.addElement(displayText); } } private void clearFields() { nameField.setText(""); distanceField.setText(""); timeField.setText("");

}

public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new RunnerGUI().setVisible(true);

}

});

}

}

class Runner

{

private String name;

private double distance;

private double time;

private double pace; public Runner(String name, double distance, double time, double pace) { this.name = name; this.distance = distance;

this.time = time; this.pace = pace;

}

public String getName()

{

return name;

}

public double getDistance() {

return distance;

}

public double getTime() {

return time;

}

 

public double getPace() {

return pace;

}

}

 

 

With this code, can you please improve on it and see what can be fixed. Thank you!

Here is a basic mockup of the screen
Runner's name Joe
Runner's
distance (miles)
Time (minutes)
26.2
192.24
Add run to list
Sort By
Name
Distance
O Time
Pace
Cathy, 5.0, 33.5, 6.7
Jim, 3.1, 22.2, 7.16
Sam, 1, 9,9.0
Save list to CSV
Transcribed Image Text:Here is a basic mockup of the screen Runner's name Joe Runner's distance (miles) Time (minutes) 26.2 192.24 Add run to list Sort By Name Distance O Time Pace Cathy, 5.0, 33.5, 6.7 Jim, 3.1, 22.2, 7.16 Sam, 1, 9,9.0 Save list to CSV
This week's project culminates in combining functionality from some past week assignments. Your job
is to create a java GUI that:
1) Allows the user to enter a Runner's name, distance and time of the runner's race. Edit/Text box
controls are typical for this type of functionality.
2) Using a button control, allow the user to enter the information from step #1 to a list-view style
control that can display the runner's name, distance, time, and also the calculated pace (in
minutes)
3) Include a button control to sort by, depending on the selection of a radio button control:
a. The runner's name in A-Z alphabetical order. This changes the runner's name and
corresponding distance, time & pace
b. The distances in descending order (longest distance run at the top)
c. The time in ascending order (shortest distance run at the top)
d. The pace in ascending order (fastest pace run at the top)
4) Include a button control to save the current list view information in a csv file, comma delimited
between runner's name, distance, time & pace. The name of the file can be set to a default
called finalProjectRunners.txt
Transcribed Image Text:This week's project culminates in combining functionality from some past week assignments. Your job is to create a java GUI that: 1) Allows the user to enter a Runner's name, distance and time of the runner's race. Edit/Text box controls are typical for this type of functionality. 2) Using a button control, allow the user to enter the information from step #1 to a list-view style control that can display the runner's name, distance, time, and also the calculated pace (in minutes) 3) Include a button control to sort by, depending on the selection of a radio button control: a. The runner's name in A-Z alphabetical order. This changes the runner's name and corresponding distance, time & pace b. The distances in descending order (longest distance run at the top) c. The time in ascending order (shortest distance run at the top) d. The pace in ascending order (fastest pace run at the top) 4) Include a button control to save the current list view information in a csv file, comma delimited between runner's name, distance, time & pace. The name of the file can be set to a default called finalProjectRunners.txt
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Concept of Threads
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education