package Gym;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.BevelBorder;
import javax.swing.border.SoftBevelBorder;
public class LogIn {
private JFrame frame;
private JPasswordField passwordField;
private JTextField textField;
private JPanel panel1;
private JLabel Label1;
private JLabel lblNewLabel_3;
private JPanel panel2;
private JLabel Label2;
private JLabel lblNewLabel;
private JButton button2;
private JButton button1;
private JLabel lblNewLabel_1;
private JLabel lblNewLabel_2;
private JLabel lblNewLabel_4;
public LogIn() {
frame = new JFrame("Gym Application - Log in");
frame.setFont(new Font("Dialog", Font.PLAIN, 12));
frame.setBounds(100, 100, 604, 547);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
panel1 = new JPanel();
panel1.setForeground(Color.BLACK);
panel1.setBorder(new SoftBevelBorder(BevelBorder.RAISED, null, null, null, null));
panel1.setBackground(Color.BLACK);
panel1.setBounds(0, 0, 596, 99);
panel1.setLayout(null);
frame.getContentPane().add(panel1);
Label1 = new JLabel("GYM MANAGEMENT SYSTEM");
Label1.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
Label1.setFont(new Font("Tahoma", Font.BOLD, 35));
Label1.setBounds(39, 28, 510, 49);
Label1.setForeground(Color.WHITE);
panel1.add(Label1);
lblNewLabel_3 = new JLabel("");
lblNewLabel_3.setBounds(0, 0, 596, 518);
panel1.add(lblNewLabel_3);
panel2 = new JPanel();
panel2.setBackground(new Color(0.0f, 0.0f, 0.0f, 0.5f));
panel2.setBounds(39, 193, 501, 276);
panel2.setLayout(null);
frame.getContentPane().add(panel2);
Label2 = new JLabel("User Name");
Label2.setFont(new Font("Tahoma", Font.BOLD, 15));
Label2.setForeground(Color.white);
Label2.setBounds(78, 41, 98, 51);
panel2.add(Label2);
lblNewLabel = new JLabel("Password");
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 15));
lblNewLabel.setForeground(Color.white);
lblNewLabel.setBounds(78, 133, 90, 40);
panel2.add(lblNewLabel);
textField = new JTextField();
textField.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
textField.setBounds(234, 49, 202, 24);
panel2.add(textField);
textField.setColumns(10);
passwordField = new JPasswordField();
passwordField.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
passwordField.setBounds(234, 139, 202, 24);
panel2.add(passwordField);
button2 = new JButton("Cancel");
button2.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
button2.setFont(new Font("Tahoma", Font.PLAIN, 15));
button2.setBounds(348, 203, 83, 21);
panel2.add(button2);
button1 = new JButton("Login");
button1.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
button1.setFont(new Font("Tahoma", Font.PLAIN, 15));
button1.setBounds(234, 203, 83, 21);
panel2.add(button1);
lblNewLabel_1 = new JLabel("Devoloped by - Armaan Ali");
lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 10));
lblNewLabel_1.setBounds(234, 479, 136, 30);
lblNewLabel_1.setForeground(Color.white);
frame.getContentPane().add(lblNewLabel_1);
lblNewLabel_2 = new JLabel("Sign in - Account");
lblNewLabel_2.setBounds(172, 113, 257, 70);
lblNewLabel_2.setFont(new Font("Sylfaen", Font.BOLD, 30));
lblNewLabel_2.setForeground(Color.white);
frame.getContentPane().add(lblNewLabel_2);
ImageIcon image = new ImageIcon(
"C:\\Users\\user\\Downloads\\muscle-press-pose-athlete-workout-hd-wallpaper-preview.jpg");
ImageIcon imageresize = resize(image, 600, 422);
lblNewLabel_4 = new JLabel("");
lblNewLabel_4.setIcon(imageresize);
lblNewLabel_4.setBounds(0, 97, 600, 422);
frame.getContentPane().add(lblNewLabel_4);
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String user = textField.getText();
String pass = passwordField.getText();
if (user.isEmpty() && pass.isEmpty()) {
JOptionPane.showMessageDialog(frame, "Do not blank the fields...");
}
else if (user.equals("Armaan") && pass.equals("123456")) {
Main m = new Main();
frame.hide();
}
else if (user.equals("Armaan") && pass != "123456") {
JOptionPane.showMessageDialog(frame, "Password do not match");
}
else if (pass.equals("123456") && user != "Armaan") {
JOptionPane.showMessageDialog(frame, "User Name do not match");
}
}
});
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.dispose();
}
});
frame.setVisible(true);
}
private static ImageIcon resize(ImageIcon im, int w, int h) {
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TRANSLUCENT);
Graphics2D gd = (Graphics2D) bi.createGraphics();
gd.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
gd.drawImage(im.getImage(), 0, 0, w, h, null);
gd.dispose();
return new ImageIcon(bi);
}
}
package Gym;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.border.SoftBevelBorder;
import javax.swing.border.BevelBorder;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
public class Main {
private JFrame frame2;
private JPanel panel;
private JLabel lblNewLabel;
private JButton btnNewButton;
private JButton btnNewButton_2;
private JButton btnNewButton_1;
private JButton btnNewButton_1_1;
private JLabel lblNewLabel_1;
private JLabel lblNewLabel_2;
private JLabel lblNewLabel_3;
public Main() {
frame2 = new JFrame("Gym Application - Select Option");
frame2.setBounds(100, 100, 429, 636);
frame2.setLocationRelativeTo(null);
frame2.setResizable(false);
frame2.setVisible(true);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.getContentPane().setLayout(null);
panel = new JPanel();
panel.setBackground(Color.BLACK);
panel.setBounds(0, 0, 425, 93);
panel.setLayout(null);
frame2.getContentPane().add(panel);
lblNewLabel = new JLabel("GYM MANAGEMENT SYSTEM");
lblNewLabel.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 25));
lblNewLabel.setForeground(new Color(255, 255, 255));
lblNewLabel.setBackground(new Color(255, 255, 255));
lblNewLabel.setBounds(32, 10, 372, 58);
panel.add(lblNewLabel);
btnNewButton = new JButton("Add Trainer");
btnNewButton.setForeground(Color.white);
btnNewButton.setBackground(Color.DARK_GRAY);
btnNewButton.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 22));
btnNewButton.setBounds(124, 354, 162, 40);
frame2.getContentPane().add(btnNewButton);
btnNewButton_2 = new JButton("Show Trainer");
btnNewButton_2.setForeground(Color.white);
btnNewButton_2.setBackground(Color.darkGray);
btnNewButton_2.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
btnNewButton_2.setFont(new Font("Tahoma", Font.PLAIN, 22));
btnNewButton_2.setBounds(124, 404, 162, 40);
frame2.getContentPane().add(btnNewButton_2);
btnNewButton_1 = new JButton("Cancel");
btnNewButton_1.setForeground(Color.white);
btnNewButton_1.setBackground(Color.DARK_GRAY);
btnNewButton_1.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
btnNewButton_1.setFont(new Font("Tahoma", Font.BOLD, 15));
btnNewButton_1.setBounds(239, 476, 106, 39);
frame2.getContentPane().add(btnNewButton_1);
btnNewButton_1_1 = new JButton("Back");
btnNewButton_1_1.setForeground(Color.white);
btnNewButton_1_1.setBackground(Color.darkGray);
btnNewButton_1_1.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
btnNewButton_1_1.setFont(new Font("Tahoma", Font.BOLD, 15));
btnNewButton_1_1.setBounds(89, 476, 106, 39);
frame2.getContentPane().add(btnNewButton_1_1);
lblNewLabel_1 = new JLabel("Devoloped by - Armaan Ali");
lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 10));
lblNewLabel_1.setForeground(Color.black);
lblNewLabel_1.setBounds(152, 568, 134, 30);
frame2.getContentPane().add(lblNewLabel_1);
lblNewLabel_2 = new JLabel("Select any Option");
lblNewLabel_2.setForeground(Color.black);
lblNewLabel_2.setBounds(89, 103, 250, 57);
lblNewLabel_2.setFont(new Font("Sylfaen", Font.BOLD, 30));
frame2.getContentPane().add(lblNewLabel_2);
ImageIcon image = new ImageIcon("C:\\Users\\user\\Downloads\\download gym main.jpg");
ImageIcon imageresize = resize(image, 295, 384);
lblNewLabel_3 = new JLabel("");
lblNewLabel_3.setIcon(imageresize);
lblNewLabel_3.setBounds(68, 159, 295, 384);
frame2.getContentPane().add(lblNewLabel_3);
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Trainer t = new Trainer();
frame2.hide();
}
});
btnNewButton_1_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
LogIn login = new LogIn();
frame2.dispose();
}
});
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame2.dispose();
}
});
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
ShowTables show = new ShowTables();
show.setVisible(true);
} catch (ClassNotFoundException | SQLException e1) {
System.out.println(e1);
}
}
});
}
private static ImageIcon resize(ImageIcon im, int w, int h) {
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TRANSLUCENT);
Graphics2D gd = (Graphics2D) bi.createGraphics();
gd.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
gd.drawImage(im.getImage(), 0, 0, w, h, null);
gd.dispose();
return new ImageIcon(bi);
}
}
Trainer.java
package Gym;
import java.sql.SQLException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.SoftBevelBorder;
import com.toedter.calendar.JDateChooser;
import javax.swing.border.BevelBorder;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JTextField;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.text.SimpleDateFormat;
import java.awt.event.ActionEvent;
import javax.swing.JTable;
public class Trainer {
private JFrame frame3;
private JPanel panel;
private JLabel lblNewLabel_1;
private JLabel lblNewLabel_1_2;
private JLabel lblNewLabel_1_1;
private JLabel lblNewLabel_1_3;
private JLabel lblNewLabel_1_4;
private JTextField name;
private JTextField age;
private JTextField address;
private JTextField mob;
private PreparedStatement pst;
private JDateChooser dateChooser;
private JPanel panel_1;
private JLabel lblNewLabel;
private JButton btnNewButton;
private JButton btnCancel;
private JLabel lblNewLabel_1_5;
private JLabel lblNewLabel_2;
private JButton btnNewButton_1;
private JButton btnNewButton_2;
private JButton btnNewButton_3;
private JLabel lblNewLabel_3;
private JTable table;
public Trainer() {
Component();
}
private void Component() {
frame3 = new JFrame("Gym Application");
frame3.setForeground(Color.WHITE);
frame3.setBackground(Color.WHITE);
frame3.setTitle("Gym Application - Add Trainer");
frame3.setBounds(100, 100, 829, 704);
frame3.setLocationRelativeTo(null);
frame3.setResizable(false);
frame3.setVisible(true);
frame3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame3.getContentPane().setLayout(null);
panel = new JPanel();
panel.setBackground(new Color(0.f, 0.f, 0.f, 0.5f));
panel.setLayout(null);
panel.setBounds(227, 174, 341, 374);
frame3.getContentPane().add(panel);
lblNewLabel_1 = new JLabel("Address");
lblNewLabel_1.setForeground(Color.white);
lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblNewLabel_1.setBounds(20, 130, 71, 28);
panel.add(lblNewLabel_1);
lblNewLabel_1_1 = new JLabel("Name");
lblNewLabel_1_1.setForeground(Color.white);
lblNewLabel_1_1.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblNewLabel_1_1.setBounds(20, 22, 71, 28);
panel.add(lblNewLabel_1_1);
lblNewLabel_1_2 = new JLabel("Age");
lblNewLabel_1_2.setForeground(Color.white);
lblNewLabel_1_2.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblNewLabel_1_2.setBounds(20, 75, 71, 28);
panel.add(lblNewLabel_1_2);
lblNewLabel_1_3 = new JLabel("Mobile");
lblNewLabel_1_3.setForeground(Color.white);
lblNewLabel_1_3.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblNewLabel_1_3.setBounds(20, 197, 71, 28);
panel.add(lblNewLabel_1_3);
lblNewLabel_1_4 = new JLabel("Date of join");
lblNewLabel_1_4.setForeground(Color.white);
lblNewLabel_1_4.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblNewLabel_1_4.setBounds(20, 264, 95, 28);
panel.add(lblNewLabel_1_4);
name = new JTextField();
name.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
name.setBounds(148, 29, 167, 21);
panel.add(name);
name.setColumns(10);
age = new JTextField();
age.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
age.setColumns(10);
age.setBounds(148, 82, 167, 21);
panel.add(age);
address = new JTextField();
address.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
address.setColumns(10);
address.setBounds(148, 137, 167, 21);
panel.add(address);
mob = new JTextField();
mob.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
mob.setColumns(10);
mob.setBounds(148, 204, 167, 21);
panel.add(mob);
dateChooser = new JDateChooser();
dateChooser.setBounds(148, 264, 155, 28);
panel.add(dateChooser);
panel_1 = new JPanel();
panel_1.setFont(new Font("Tahoma", Font.BOLD, 24));
panel_1.setBackground(Color.darkGray);
panel_1.setBounds(0, 0, 825, 96);
panel_1.setLayout(null);
frame3.getContentPane().add(panel_1);
lblNewLabel = new JLabel("GYM MANAGEMENT SYSYTEM");
lblNewLabel.setForeground(new Color(255, 255, 255));
lblNewLabel.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 40));
lblNewLabel.setBounds(97, 10, 615, 64);
panel_1.add(lblNewLabel);
btnNewButton = new JButton("Add");
btnNewButton.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
btnNewButton.setBackground(Color.darkGray);
btnNewButton.setForeground(Color.white);
btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 20));
btnNewButton.setBounds(26, 572, 117, 45);
frame3.getContentPane().add(btnNewButton);
btnCancel = new JButton("Cancel");
btnCancel.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
btnCancel.setFont(new Font("Tahoma", Font.PLAIN, 20));
btnCancel.setBackground(Color.DARK_GRAY);
btnCancel.setForeground(Color.white);
btnCancel.setBounds(167, 572, 128, 45);
frame3.getContentPane().add(btnCancel);
lblNewLabel_1_5 = new JLabel("Devoloped by - Armaan Ali");
lblNewLabel_1_5.setFont(new Font("Tahoma", Font.PLAIN, 10));
lblNewLabel_1_5.setForeground(Color.white);
lblNewLabel_1_5.setBounds(354, 636, 136, 30);
frame3.getContentPane().add(lblNewLabel_1_5);
lblNewLabel_2 = new JLabel("Add Trainer");
lblNewLabel_2.setBounds(318, 112, 188, 52);
lblNewLabel_2.setFont(new Font("Sylfaen", Font.BOLD, 30));
lblNewLabel_2.setForeground(Color.white);
frame3.getContentPane().add(lblNewLabel_2);
table = new JTable();
table.setBounds(423, 188, 1, 1);
frame3.getContentPane().add(table);
btnNewButton_1 = new JButton("Show");
btnNewButton_1.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
btnNewButton_1.setFont(new Font("Tahoma", Font.PLAIN, 20));
btnNewButton_1.setBackground(Color.DARK_GRAY);
btnNewButton_1.setForeground(Color.white);
btnNewButton_1.setBounds(318, 572, 128, 45);
frame3.getContentPane().add(btnNewButton_1);
btnNewButton_2 = new JButton("Delete Trainer");
btnNewButton_2.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
btnNewButton_2.setFont(new Font("Tahoma", Font.PLAIN, 20));
btnNewButton_2.setBackground(Color.DARK_GRAY);
btnNewButton_2.setForeground(Color.white);
btnNewButton_2.setBounds(466, 572, 169, 46);
frame3.getContentPane().add(btnNewButton_2);
btnNewButton_3 = new JButton("Back");
btnNewButton_3.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
btnNewButton_3.setFont(new Font("Tahoma", Font.PLAIN, 23));
btnNewButton_3.setBackground(Color.DARK_GRAY);
btnNewButton_3.setForeground(Color.white);
btnNewButton_3.setBounds(655, 572, 128, 45);
frame3.getContentPane().add(btnNewButton_3);
ImageIcon image = new ImageIcon("C:\\Users\\user\\Downloads\\trainer.jpg");
ImageIcon imageresize = resize(image, 825, 580);
lblNewLabel_3 = new JLabel("");
lblNewLabel_3.setIcon(imageresize);
lblNewLabel_3.setBounds(0, 96, 825, 580);
frame3.getContentPane().add(lblNewLabel_3);
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/gymapp", "root", "mysql");
pst = con.prepareStatement("insert into trainer(name,age,address,mobile,doj)values(?,?,?,?,?)");
} catch (Exception f) {
System.out.println(f);
}
String tname = name.getText();
String tage = age.getText();
String addr = address.getText();
String mobile = mob.getText();
SimpleDateFormat df = new SimpleDateFormat();
String date = df.format(dateChooser.getDate());
try {
pst.setString(1, tname);
pst.setString(2, tage);
pst.setString(3, addr);
pst.setString(4, mobile);
pst.setString(5, date);
pst.executeUpdate();
JOptionPane.showMessageDialog(frame3, "Record add successfully...");
name.setText("");
age.setText("");
address.setText("");
mob.setText("");
name.requestFocus();
} catch (Exception c) {
System.out.println(c);
}
}
});
btnCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame3.dispose();
}
});
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
ShowTables show = new ShowTables();
show.setVisible(true);
} catch (Exception e1) {
System.out.println(e1);
}
}
});
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Delete dlt = new Delete();
dlt.setVisible(true);
} catch (ClassNotFoundException | SQLException e1) {
System.out.println("e1");
}
}
});
btnNewButton_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame3.setVisible(false);
Main main = new Main();
}
});
}
private static ImageIcon resize(ImageIcon im, int w, int h) {
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TRANSLUCENT);
Graphics2D gd = (Graphics2D) bi.createGraphics();
gd.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
gd.drawImage(im.getImage(), 0, 0, w, h, null);
gd.dispose();
return new ImageIcon(bi);
}
}
ShowTables.java
package Gym;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.SoftBevelBorder;
import net.proteanit.sql.DbUtils;
import javax.swing.JButton;
import javax.swing.JTable;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import java.awt.Dimension;
public class ShowTables extends JFrame {
private JPanel contentPane;
private JTable table;
private JLabel lblNewLabel;
private JLabel lblNewLabel_1;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ShowTables frame = new ShowTables();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
* @throws SQLException
* @throws ClassNotFoundException
*/
public ShowTables() throws SQLException, ClassNotFoundException {
setTitle("Show Name");
Class.forName("com.mysql.jdbc.Driver");
Connection con1=DriverManager.getConnection("jdbc:mysql://localhost:3306/gymapp", "root", "mysql");
setBounds(100, 100, 537, 293);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
JButton btn = new JButton("Show Traner name");
btn.setBounds(5, 5, 517, 31);
btn.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
btn.setFont(new Font("Tahoma", Font.PLAIN, 20));
btn.setBackground(Color.DARK_GRAY);
btn.setForeground(Color.white);
setLocationRelativeTo(null);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try
{
String query = "select * from trainer";
PreparedStatement ps=con1.prepareStatement(query);
ResultSet rs=ps.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
}
catch(Exception e1)
{
System.out.println(e1);
}
}
});
contentPane.setLayout(null);
contentPane.add(btn);
table = new JTable();
table.setBounds(5, 36, 517, 222);
contentPane.add(table);
}
}
Delete.java
package Gym;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.SoftBevelBorder;
import net.proteanit.sql.DbUtils;
import javax.swing.JButton;
import javax.swing.JTable;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
public class Delete extends JFrame {
private JPanel contentPane;
private JButton btn2;
private JTable table;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Delete frame = new Delete();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
* @throws ClassNotFoundException
* @throws SQLException
*/
public Delete() throws ClassNotFoundException, SQLException {
setTitle("Delete Trainer");
Class.forName("com.mysql.jdbc.Driver");
Connection con1=DriverManager.getConnection("jdbc:mysql://localhost:3306/gymapp","root","mysql");
setBounds(100, 100, 559, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
setLocationRelativeTo(null);
JButton btn = new JButton("Show Trainer");
btn.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
btn.setFont(new Font("Tahoma", Font.PLAIN, 18));
btn.setBackground(Color.DARK_GRAY);
btn.setForeground(Color.white);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try
{
String query = "select * from trainer";
PreparedStatement ps=con1.prepareStatement(query);
ResultSet rs=ps.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
}
catch(Exception e1)
{
System.out.println(e1);
}
}
});
contentPane.add(btn, BorderLayout.NORTH);
btn2 = new JButton("Delete Trainer");
btn2.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
btn2.setFont(new Font("Tahoma", Font.PLAIN, 18));
btn2.setBackground(Color.DARK_GRAY);
btn2.setForeground(Color.white);
btn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int row = table.getSelectedRow();
System.out.println(row);
String cell = table.getModel().getValueAt(row, 0).toString();
System.out.println(cell);
try {
PreparedStatement ps=con1.prepareStatement("delete from trainer where name=(?)");
ps.setString(1, cell);
ps.execute();
JOptionPane.showMessageDialog(null, "Deleted Successfully");
updateTable();
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
}
}
});
contentPane.add(btn2, BorderLayout.SOUTH);
table = new JTable();
contentPane.add(table, BorderLayout.CENTER);
}
public void updateTable() throws SQLException, ClassNotFoundException
{
Class.forName("com.mysql.jdbc.Driver");
Connection con1=DriverManager.getConnection("jdbc:mysql://localhost:3306/gymapp","root","mysql");
String sql = "select * from trainer";
try
{
String query = "select * from trainer";
PreparedStatement ps=con1.prepareStatement(query);
ResultSet rs=ps.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
}
}
Comments
Post a Comment