0% found this document useful (0 votes)
17 views2 pages

Text

The document describes a Java program that creates a graphical user interface for automating a gym management system. It defines a table model and JTable to display member and staff data in a table. Buttons are added to allow users to add new members or staff by entering their details using dialog boxes, which are then added as new rows in the table. The main method initializes the frame and table when the program runs.

Uploaded by

thingsr865
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Text

The document describes a Java program that creates a graphical user interface for automating a gym management system. It defines a table model and JTable to display member and staff data in a table. Buttons are added to allow users to add new members or staff by entering their details using dialog boxes, which are then added as new rows in the table. The main method initializes the frame and table when the program runs.

Uploaded by

thingsr865
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import javax.swing.

*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class GymAutomationWithJTable {


private DefaultTableModel tableModel;
private JTable table;

public GymAutomationWithJTable() {
// Create the frame
JFrame frame = new JFrame("Gym Automation");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());

// Create a table model


tableModel = new DefaultTableModel();
tableModel.addColumn("MemberID");
tableModel.addColumn("Member Name");
tableModel.addColumn("Phone Number");
tableModel.addColumn("Gym Program");

// Create the JTable with the model


table = new JTable(tableModel);
frame.add(new JScrollPane(table), BorderLayout.CENTER);

// Create buttons to add members/staff


JButton addMemberButton = new JButton("Add Member");
JButton addStaffButton = new JButton("Add Staff");

// Add action listeners to the buttons


addMemberButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addMember();
}
});

addStaffButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addStaff();
}
});

JPanel buttonPanel = new JPanel();


buttonPanel.add(addMemberButton);
buttonPanel.add(addStaffButton);
frame.add(buttonPanel, BorderLayout.SOUTH);

frame.setSize(700, 300);
frame.setVisible(true);
}

public void addMember() {


String memberID = JOptionPane.showInputDialog("Enter Member ID:");
String memberName = JOptionPane.showInputDialog("Enter Member Name:");
String phoneNumber = JOptionPane.showInputDialog("Enter Phone Number:");
String gymProgram = JOptionPane.showInputDialog("Enter Gym Program:");

tableModel.addRow(new Object[]{memberID, memberName, phoneNumber,


gymProgram});
}

public void addStaff() {


String staffID = JOptionPane.showInputDialog("Enter Staff ID:");
String staffName = JOptionPane.showInputDialog("Enter Staff Name:");
String phoneNumber = JOptionPane.showInputDialog("Enter Phone Number:");
String role = JOptionPane.showInputDialog("Enter Role:");
String salary = JOptionPane.showInputDialog("Enter Salary");

tableModel.addRow(new Object[]{staffID, staffName, phoneNumber, role,


salary});
}

public static void main(String[] args) {


SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new GymAutomationWithJTable();
}
});
}
}

You might also like