0% found this document useful (0 votes)
15 views13 pages

Pe 2 Ipt (F2022)

The document is a student's submission for a practical exercise on creating a Java program for a sports registration system. It includes the program codes to build a GUI for the system using Swing components, with functions to connect to a MySQL database, add new registrations, and display the registration table. The program allows users to enter registrant details, add them to the database, and view the registration records.

Uploaded by

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

Pe 2 Ipt (F2022)

The document is a student's submission for a practical exercise on creating a Java program for a sports registration system. It includes the program codes to build a GUI for the system using Swing components, with functions to connect to a MySQL database, add new registrations, and display the registration table. The program allows users to enter registrant details, add them to the database, and view the registration records.

Uploaded by

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

SUNGAI LANG

45100 SUNGAI AYER TAWAR


SELANGOR

DIPLOMA IN INFORMATION TECHNOLOGY


( DIGITAL TECHNOLOGY )

INTEGRATIVE PROGRAMMING & TECHNOLOGY


( DFP 40203 )

PRACTICAL EXERCISE 2

Prepared by :
MUHAMAD AKMAL BIN AZHAR ( 17DDT21F2022)

DDT4A

Lecturer
TS.NORQURSIAH BINTI SAAD

Submission Date
29 NOVEMBER 2023
PROGRAM CODES

/*NAME:MUHAMAD AKMAL BIN AZHAR

* MATRIC NO:17DDT21F2022

*/

package Akmal;

import java.awt.EventQueue;

import javax.swing.JFrame;

import java.awt.FlowLayout;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import java.awt.Font;

import java.sql.Connection;

import java.sql.Date;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import javax.swing.JTextField;

import javax.swing.table.DefaultTableModel;

import com.toedter.calendar.JDateChooser;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.JButton;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import javax.swing.JTextArea;
import javax.swing.JPanel;

import java.awt.Color;

import net.proteanit.sql.DbUtils;

public class Sukan {

private JFrame frmSukan;

private JTextField txtNama;

private JTextField txtIc;

private JTextField txtAlamat;

private JTextField txtNotel;

private JTextField txtMatric;

DefaultTableModel model = new DefaultTableModel();

private JTable table_4;

/**

* Launch the application.

*/

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

Sukan window = new Sukan();

window.frmSukan.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

});

/**
* Create the application.

*/

public Sukan() {

initialize();

/**

* Initialize the contents of the frame.

*/

private void initialize() {

frmSukan = new JFrame();

frmSukan.getContentPane().setBackground(Color.ORANGE);

frmSukan.setTitle("Sukan");

frmSukan.setBounds(100, 100, 818, 769);

frmSukan.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frmSukan.getContentPane().setLayout(null);

JLabel lblHeader = new JLabel("PENDAFTARAN HARI SUKAN NEGARA");

lblHeader.setFont(new Font("Tahoma", Font.BOLD, 22));

lblHeader.setBounds(160, 28, 435, 59);

frmSukan.getContentPane().add(lblHeader);

JLabel lblNama = new JLabel("Nama Pelajar:");

lblNama.setFont(new Font("Tahoma", Font.PLAIN, 18));

lblNama.setBounds(57, 260, 120, 32);

frmSukan.getContentPane().add(lblNama);

JLabel lblIc = new JLabel("IC Pelajar:");

lblIc.setFont(new Font("Tahoma", Font.PLAIN, 18));

lblIc.setBounds(82, 326, 85, 32);

frmSukan.getContentPane().add(lblIc);

JLabel lblAlamat = new JLabel("Alamat:");


lblAlamat.setFont(new Font("Tahoma", Font.PLAIN, 18));

lblAlamat.setBounds(99, 462, 68, 32);

frmSukan.getContentPane().add(lblAlamat);

JLabel lblTelefon = new JLabel("No Telefon:");

lblTelefon.setFont(new Font("Tahoma", Font.PLAIN, 18));

lblTelefon.setBounds(68, 538, 99, 32);

frmSukan.getContentPane().add(lblTelefon);

JLabel lblTarikh = new JLabel("Tarikh Tempahan:");

lblTarikh.setFont(new Font("Tahoma", Font.PLAIN, 18));

lblTarikh.setBounds(30, 612, 147, 32);

frmSukan.getContentPane().add(lblTarikh);

txtNama = new JTextField();

txtNama.setBounds(193, 260, 272, 32);

frmSukan.getContentPane().add(txtNama);

txtNama.setColumns(10);

txtIc = new JTextField();

txtIc.setColumns(10);

txtIc.setBounds(193, 326, 272, 32);

frmSukan.getContentPane().add(txtIc);

txtAlamat = new JTextField();

txtAlamat.setColumns(10);

txtAlamat.setBounds(193, 462, 272, 32);

frmSukan.getContentPane().add(txtAlamat);

txtNotel = new JTextField();

txtNotel.setColumns(10);

txtNotel.setBounds(193, 542, 272, 32);

frmSukan.getContentPane().add(txtNotel);

JDateChooser txtdDate = new JDateChooser();


txtdDate.setBounds(193, 612, 272, 32);

frmSukan.getContentPane().add(txtdDate);

JPanel panel = new JPanel();

panel.setBounds(82, 97, 648, 130);

frmSukan.getContentPane().add(panel);

panel.setLayout(null);

JScrollPane scrollPane_1 = new JScrollPane();

scrollPane_1.setBounds(21, 10, 606, 110);

panel.add(scrollPane_1);

JTextArea textArea = new JTextArea();

textArea.setBounds(509, 260, 285, 322);

frmSukan.getContentPane().add(textArea);

table_4 = new JTable(model);

scrollPane_1.setViewportView(table_4);

model.addColumn("IC");

model.addColumn("No Pendaftaran");

model.addColumn("Nama Pelajar");

model.addColumn("Alamat");

model.addColumn("Telefon");

model.addColumn("Tarikh Tempahan");

try {

Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/dbsukan","root
","");

PreparedStatement pstm = con.prepareStatement("SELECT * FROM tempahan");

ResultSet Rs=pstm.executeQuery();

while(Rs.next()) {

model.addRow(new Object []
{Rs.getInt(1),Rs.getString(2),Rs.getString(3),Rs.getString(4),Rs.getInt(5),
Rs.getDate(6)});
}

catch(Exception f) {

System.out.println(f.getMessage());

JButton btnAdd = new JButton("Add");

btnAdd.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String ic,matric, name,address,phoneNo;

Date date = new Date(txtdDate.getDate().getTime());

ic = txtIc.getText();

name=txtNama.getText();

matric=txtMatric.getText();

address = txtAlamat.getText();

phoneNo = txtNotel.getText();

textArea.setText("\n/Ic.No "+ic+"\\/nNo.Pendaftaran "+matric+"\n\nNama


Pelajar "+name+"\n\nAlamat "+address+"\n\nNo Telefon "+phoneNo+"\n\nDate
"+date);

try {

Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/dbsukan", "root",
"");

PreparedStatement st =con.prepareStatement("insert into tempahan " +


"(IC,NoPendaftaran,NamaPelajar,Alamat,Telefon,TarikhTempahan)"

+ "values(?,?,?,?,?,?)");

st.setString(1, ic);

st.setString(2, matric);

st.setString(3, name);

st.setString(4, address);

st.setString(5, phoneNo);
st.setDate(6, date);

int rowInserted = st.executeUpdate();

if (rowInserted > 0) {

JOptionPane.showMessageDialog(null, "Record Added!!!!!");

txtIc.setText("");

txtNama.setText("");

txtMatric.setText("");

txtAlamat.setText("");

txtNotel.setText("");

txtdDate.setDate(null);

textArea.setText("IC No: "+ic+"\n\nMatric No: "+matric+"\n\nName:


"+name+"\n\nAddress: "+address

+"\n\nPhone No: "+phoneNo+"\n\nBooking Date: "+date);

refreshTable();

}else {

JOptionPane.showMessageDialog(null, "Data Not Save!!!!!");

con.close();

catch (SQLException e1)

e1.printStackTrace();

});

btnAdd.setFont(new Font("Tahoma", Font.PLAIN, 18));

btnAdd.setBounds(268, 672, 120, 50);

frmSukan.getContentPane().add(btnAdd);
table_4.setModel(model);

txtMatric = new JTextField();

txtMatric.setColumns(10);

txtMatric.setBounds(193, 397, 272, 32);

frmSukan.getContentPane().add(txtMatric);

JLabel lblMatric = new JLabel("No Matric:");

lblMatric.setFont(new Font("Tahoma", Font.PLAIN, 18));

lblMatric.setBounds(82, 397, 85, 32);

frmSukan.getContentPane().add(lblMatric);

public void refreshTable() {

try {

Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/dbsukan", "root",
"");

PreparedStatement st = con.prepareStatement("SELECT * FROM tempahan");

ResultSet Rs = st.executeQuery();

table_4.setModel(DbUtils.resultSetToTableModel(Rs));

} catch (Exception e) {

System.out.println(e.getMessage());

}
OUTPUT
PE 2 RUBRICS

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy