0% found this document useful (0 votes)
44 views20 pages

Java Code

This document contains Java code for a sports club management system with the following features: 1. A main menu allows the user to access modules for member management or sport management. 2. The member management modules allow adding, deleting, viewing, and updating member records stored in a database. 3. The sport management modules allow adding, viewing, and updating sport records also stored in a database. 4. All modules utilize Java Swing for the GUI and JDBC to connect to a MySQL database for data storage and retrieval.

Uploaded by

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

Java Code

This document contains Java code for a sports club management system with the following features: 1. A main menu allows the user to access modules for member management or sport management. 2. The member management modules allow adding, deleting, viewing, and updating member records stored in a database. 3. The sport management modules allow adding, viewing, and updating sport records also stored in a database. 4. All modules utilize Java Swing for the GUI and JDBC to connect to a MySQL database for data storage and retrieval.

Uploaded by

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

JAVA CODE

MAIN MENU:
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* mainMenu.java
*
* Created on Sep 25, 2019, 9:47:04 PM
*/
/**
*
* @author 12d
*/
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
new sportsclub().setVisible(true);
this.setVisible(false);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
new itemMenu().setVisible(true);
this.setVisible(false);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new mainMenu().setVisible(true);
}
});
}
SPORTS CLUB:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* sportsclub.java
*
* Created on Sep 25, 2019, 9:49:29 PM
*/

/**
*
* @author 12d
*/
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.setVisible(false);
new addmember().setVisible(true);
// TODO add your handling code here:
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {


this.setVisible(false);
new deletemember().setVisible(true);
// TODO add your handling code here:
}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {


this.setVisible(false);
new viewmember().setVisible(true);
// TODO add your handling code here:
}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {


this.setVisible(false);
new updatemember().setVisible(true);
// TODO add your handling code here:
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new sportsclub().setVisible(true);
}
});
}
ADD MEMBER:
import java.sql.*;
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* addmember.java
*
* Created on Sep 25, 2019, 10:07:40 PM
*/

/**
*
* @author 12d
*/private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String memname, memid, itemid , age;
memname = jTextField1.getText();
memid = jTextField2.getText();
itemid = jTextField3.getText();
age = jTextField4.getText();
try {
Class.forName("java.sql.DriverManager");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/project", "root", "root123");
Statement stmt = (Statement) con.createStatement();
String query = "insert into sports values('" + memname + "','" + memid + "','" +
itemid + "','" + age + "');";
stmt.executeUpdate(query);
JOptionPane.showMessageDialog(this, "Member Added");
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}

private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new addmember().setVisible(true);
}
});
}
DELETE MEMBER RECORDS :

import java.sql.*;
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* deletemember.java
*
* Created on Sep 25, 2019, 10:37:31 PM
*/

/**
*
* @author 12d
*/ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String spartaid = jTextField1.getText(),custname,itemid;
try {
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/project", "root", "root123");
Statement stmt = (Statement) con.createStatement();
String query = "select * from sports where spartaid='" + spartaid + "';";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
custname = rs.getString("name");
itemid = rs.getString("sportid");
jTextField2.setText(custname);
jTextField3.setText(itemid);
JOptionPane.showMessageDialog(this, "Record Found");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
String spartaid = jTextField1.getText();
try {
Class.forName("java.sql.DriverManager");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/project", "root", "root123");
Statement stmt = (Statement) con.createStatement();
String query = "delete from sports where spartaid='" + spartaid + "'";
stmt.executeUpdate(query);
JOptionPane.showMessageDialog(this, "Record Deleted");
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new deletemember().setVisible(true);
}
});
}
VIEW MEMBR RECORDS:

import java.sql.*;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* viewmember.java
*
* Created on Sep 26, 2019, 7:13:18 AM
*/

/**
*
* @author 12d
*/private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try
{
Class.forName("java.sql.DriverManager");
Connection
con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/project",
"root","root123");
Statement stmt=(Statement)con.createStatement();
String query="select * from sports";
ResultSet rs=stmt.executeQuery(query);
DefaultTableModel model=(DefaultTableModel)jTable1.getModel();
while (rs.next())
{
String NAME=rs.getString("name");
String SPARTAID=rs.getString("spartaid");
String SPORTID=rs.getString("sportid");
String AGE=rs.getString("age");
model.addRow(new Object[]{NAME,SPARTAID,SPORTID,AGE});
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new viewmember().setVisible(true);
}
});
}
UPDATE MEMBER RECORDS:
import java.sql.*;
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* updatemember.java
*
* Created on Sep 25, 2019, 10:55:48 PM
*/
/**
*
* @author 12d
*/private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String spartaid=jTextField1.getText(),name,sportid;
try
{
Class.forName("java.sql.DriverManager");
Connection
con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/project",
"root","root123");
Statement stmt=(Statement)con.createStatement();
String query="select * from sports where spartaid='"+spartaid+"';";
stmt.executeQuery(query);
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{
name=rs.getString("name");
sportid=rs.getString("sportid");
jTextField2.setText(""+name);
jTextField3.setText(""+sportid);
}
JOptionPane.showMessageDialog(this, "Record Found");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {


String spartaid=jTextField1.getText(),name,sportid;
name=jTextField2.getText();
sportid=jTextField3.getText();
try{
Connection
con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/project",
"root","root123");
Statement stmt=(Statement)con.createStatement();
String query="update project set name='"+name+"',sportid='"+sportid+"'where
spartaid='"+spartaid+"';";
stmt.executeUpdate(query);
JOptionPane.showMessageDialog(this, "Record Modified");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new updatemember().setVisible(true);
}
});
}
SPORT MENU:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* itemMenu.java
*
* Created on Sep 25, 2019, 9:49:29 PM
*/

/**
*
* @author 12d
*/ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.setVisible(false);
new addsport().setVisible(true);
// TODO add your handling code here:
}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {


this.setVisible(false);
new viewsport().setVisible(true);
// TODO add your handling code here:
}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {


this.setVisible(false);
new updatesport().setVisible(true);
// TODO add your handling code here:
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new itemMenu().setVisible(true);
}
});
}
ADD SPORT:

import java.sql.*;
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* addsport.java
*
* Created on Sep 25, 2019, 10:07:40 PM
*/

/**
*
* @author 12d
*/
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String sportname, sportid;
int price;
sportname = jTextField1.getText();
sportid = jTextField2.getText();
price = Integer.parseInt(jTextField3.getText());

try {
Class.forName("java.sql.DriverManager");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/project", "root", "root123");
Statement stmt = (Statement) con.createStatement();
String query = "insert into item values('" + sportname + "','" + sportid + "','" +
price + "');";
stmt.executeUpdate(query);
JOptionPane.showMessageDialog(this, "Sport Added");
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}

}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new addsport().setVisible(true);
}
});
}
VIEW SPORT DETAILS :

import java.sql.*;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* viewsport.java
*
* Created on Sep 26, 2019, 7:13:18 AM
*/

/**
*
* @author 12d
*/
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try
{
Class.forName("java.sql.DriverManager");
Connection
con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/project",
"root","root123");
Statement stmt=(Statement)con.createStatement();
String query="select * from item";
ResultSet rs=stmt.executeQuery(query);
DefaultTableModel model=(DefaultTableModel)jTable1.getModel();
while (rs.next())
{
String NAME=rs.getString("sportid");
String SPORTid=rs.getString("sport");
int PRICE=rs.getInt("price");
model.addRow(new Object[]{NAME,SPORTid,PRICE});
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new viewsport().setVisible(true);
}
});
}
MODIFY SPORT DETAILS

import java.sql.*;
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* updatesport.java
*
* Created on Sep 25, 2019, 10:55:48 PM
*/

/**
*
* @author 12d
*/

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {


String sportid=jTextField1.getText();
try
{
Class.forName("java.sql.DriverManager");
Connection
con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/project",
"root","root123");
Statement stmt=(Statement)con.createStatement();
String query="select * from item where sportid='"+sportid+"';";
stmt.executeQuery(query);
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{
String sport=rs.getString("sport");
int price=rs.getInt("price");
jTextField2.setText(""+sport);
jTextField3.setText(""+price);
}
JOptionPane.showMessageDialog(this, "Record Found");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {


String sportid=jTextField1.getText(),sport=jTextField2.getText();
int price=Integer.parseInt(jTextField3.getText());
try{
Connection
con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/project",
"root","root123");
Statement stmt=(Statement)con.createStatement();
String query="update item set sport='"+sport+"' where sportid='"+sportid+"';";
stmt.executeUpdate(query);
JOptionPane.showMessageDialog(this, "Record Modified");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new updatesport().setVisible(true);
}
});
}

You might also like