0% found this document useful (0 votes)
33 views29 pages

Case Study - Ipt Maznur F2002, Akmal F2022

The document describes a Java program for a course registration system. The program allows users to view registered courses in a table, add new courses, update course details, and delete courses. It connects to a MySQL database and uses various Swing components like buttons, text fields and tables.

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)
33 views29 pages

Case Study - Ipt Maznur F2002, Akmal F2022

The document describes a Java program for a course registration system. The program allows users to view registered courses in a table, add new courses, update course details, and delete courses. It connects to a MySQL database and uses various Swing components like buttons, text fields and tables.

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/ 29

SUNGAI LANG

45100 SUNGAI AYER TAWAR SELANGOR

DIPLOMA IN INFORMATION TECHNOLOGY


(DIGITAL TECHNOLOGY)

INTEGRATIVE
PROGRAMMING &
TECHNOLOGY
(DFC50273)

CASE STUDY

Prepared by:
MAZNUR FIRDAUS BIN MAZLAN (17DDT21F2002)

MUHAMMAD AKMAL BIN AZHAR (17DDT21F2022)


Due date:

30/11/2023
QUESTION
CODING

package DFP50273; import java.awt.EventQueue;

import javax.swing.JFrame; import

javax.swing.JPanel; import

javax.swing.border.EmptyBorder; import

javax.swing.JButton; import

javax.swing.JTable; import

javax.swing.JScrollPane; import

javax.swing.JLabel; import

javax.swing.JOptionPane; import

javax.swing.border.TitledBorder; import

javax.swing.filechooser.FileSystemView; import

javax.swing.table.DefaultTableModel; import

java.awt.Color; import

javax.swing.border.EtchedBorder; 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.JComboBox; import

javax.swing.JFileChooser; import

javax.swing.JCheckBox; import

java.awt.event.ActionListener; import

java.io.File; import java.awt.event.ActionEvent;

import javax.swing.DefaultComboBoxModel; public

class Course_Registration extends JFrame {

private static final long serialVersionUID = 1L;

private JPanel contentPane; private JTable table;

private JTextField textField; private JTextField

textField_1; private JTextField textField_2;

private JTextField textField_3; private

JTextField textField_4;

DefaultTableModel model = new DefaultTableModel();

private JTextField textField_5; private

JFileChooser fileChooser; private File

selectedFile;

/**

* Launch the application.

*/ public static void main(String[]


args) { EventQueue.invokeLater(new
Runnable() {
public void run() { try

Course_Registration frame = new Course_Registration();

frame.setVisible(true); } catch (Exception e) {

e.printStackTrace();

});

/**

* Create the frame.

*/ public Course_Registration() {

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 1129, 690); contentPane = new

JPanel(); contentPane.setBorder(new EmptyBorder(5,

5, 5, 5)); setContentPane(contentPane);

contentPane.setLayout(null); JPanel panel = new

JPanel(); panel.setBackground(Color.ORANGE);

panel.setBorder(new TitledBorder(new
EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new
Color(160, 160, 160)), "Registered Course", TitledBorder.LEADING,
TitledBorder.TOP, null, new Color(0, 0, 0)));
panel.setBounds(28, 79, 925, 172);

contentPane.add(panel); panel.setLayout(null);

JLabel lblNewLabel = new JLabel("SESI 1 2022/2024");

lblNewLabel.setBounds(398, 22, 143, 19); lblNewLabel.setFont(new

Font("Tahoma", Font.BOLD, 15)); panel.add(lblNewLabel);

JScrollPane scrollPane = new JScrollPane();

scrollPane.setBounds(28, 51, 865, 97);

panel.add(scrollPane); table = new

JTable(model); table.setEnabled(false);

scrollPane.setViewportView(table);

model.addColumn("Bilangan");

model.addColumn("Course code");

model.addColumn("Course name");

model.addColumn("Lecturer");

model.addColumn("Credit Hours"); try {

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

PreparedStatement pstm = con.prepareStatement("SELECT * FROM


tbl_courselist");

ResultSet Rs = pstm.executeQuery(); while(Rs.next()){


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

} catch (Exception e) {

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

JPanel panel_1 = new JPanel(); panel_1.setBackground(Color.ORANGE);

panel_1.setBorder(new TitledBorder(new
EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new
Color(160, 160, 160)), "ADD COURSE", TitledBorder.LEADING,

TitledBorder.TOP, null, Color.BLUE));

panel_1.setBounds(28, 319, 925, 333);

contentPane.add(panel_1); panel_1.setLayout(null);

JLabel lblNewLabel_2 = new JLabel("STUDENT NAME:");

lblNewLabel_2.setBounds(10, 28, 90, 14);

panel_1.add(lblNewLabel_2); textField_1 = new

JTextField(); textField_1.setBounds(110, 25, 208,

20); panel_1.add(textField_1);

textField_1.setColumns(10);

JLabel lblNewLabel_3 = new JLabel("MATRIX NUMBER:");

lblNewLabel_3.setBounds(10, 64, 90, 14);

panel_1.add(lblNewLabel_3);

JLabel lblNewLabel_4 = new JLabel("COURSE CODE :");


lblNewLabel_4.setBounds(10, 102, 90, 14);
panel_1.add(lblNewLabel_4);

JLabel lblNewLabel_5 = new JLabel("COURSE NAME :");

lblNewLabel_5.setBounds(10, 138, 90, 14);

panel_1.add(lblNewLabel_5); JLabel lblNewLabel_6 =

new JLabel("LECTURER :");

lblNewLabel_6.setBounds(10, 176, 69, 14);

panel_1.add(lblNewLabel_6);

JLabel lblNewLabel_7 = new JLabel("CREDIT HOURS :");

lblNewLabel_7.setBounds(10, 217, 90, 14);

panel_1.add(lblNewLabel_7); textField_2 = new

JTextField(); textField_2.setBounds(110, 61, 208,

20); panel_1.add(textField_2);

textField_2.setColumns(10); final JComboBox comboBox

= new JComboBox();

comboBox.setModel(new DefaultComboBoxModel(new String[] {"DFP32422",


"DFP42424"})); comboBox.insertItemAt("", 0);
comboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String code = (String) comboBox.getSelectedItem();
if (code == "") { textField_4.setText("");
textField_3.setText(""); textField_5.setText("");
}

try

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

PreparedStatement pstm = con.prepareStatement("SELECT * FROM


tbl_courselist WHERE course_code = ?"); pstm.setString(1,
code);

ResultSet Rs = pstm.executeQuery(); while(Rs.next()){

String lectName = Rs.getString("lecturer_name");

String cName = Rs.getString("course_name"); String

cHours = Rs.getString("credit_hours");

textField_4.setText(lectName);

textField_3.setText(cName);

textField_5.setText(cHours);

} catch (Exception e1) {

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

} }); comboBox.setBounds(110, 102,


86, 22); panel_1.add(comboBox); try {
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost/dbregistration",
"root", "");

PreparedStatement pstm = con.prepareStatement("SELECT * FROM


tbl_courselist");

ResultSet Rs = pstm.executeQuery(); while(Rs.next()){

String cCode = Rs.getString("course_code"); comboBox.addItem(cCode);

} catch (Exception e) {

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

} textField_3 = new JTextField();

textField_3.setBounds(110, 138, 208, 20);

panel_1.add(textField_3);

textField_3.setColumns(10); textField_4 =

new JTextField();

textField_4.setBounds(110, 173, 208, 20);

panel_1.add(textField_4);

textField_4.setColumns(10);

final JCheckBox chckbxNewCheckBox = new JCheckBox("Are you sure to


add this course to your course list?");
chckbxNewCheckBox.setBounds(47, 247, 341, 23);
panel_1.add(chckbxNewCheckBox); final JButton btnNewButton_1 = new
JButton("ADD"); btnNewButton_1.addActionListener(new
ActionListener() {
public void actionPerformed(ActionEvent e) {

String studentName,matricNo, courseCode,courseName,lecturerName,

creditHours; studentName = textField_1.getText(); matricNo =

textField_2.getText(); courseCode =

comboBox.getSelectedItem().toString(); courseName =

textField_3.getText(); lecturerName = textField_4.getText();

creditHours = textField_5.getText(); int temp =

Integer.parseInt(creditHours); try {

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

PreparedStatement st = con.prepareStatement("insert into


tbl_courseregister "

+
"(student_name,matrix_number,course_code,course_name,lecturer_name,c
redit_hours)"

+ "values(?,?,?,?,?,?)");
st.setString(1, studentName);
st.setString(2, matricNo);
st.setString(3, courseCode);
st.setString(4, courseName);
st.setString(5, lecturerName);
st.setInt(6, temp); int rowInserted =
st.executeUpdate(); if (rowInserted >
0) {
JOptionPane.showMessageDialog(null, "Record Added!!!!!");

}else {

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

} con.close();

} catch (SQLException

e1)

{ e1.printStackTrace();

} }); btnNewButton_1.setEnabled(false);

btnNewButton_1.setBounds(71, 287, 89, 23);

panel_1.add(btnNewButton_1);

chckbxNewCheckBox.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { if

(chckbxNewCheckBox.isSelected()) {

btnNewButton_1.setEnabled(true);

} else { btnNewButton_1.setEnabled(false);

});

JButton btnNewButton_2 = new JButton("UPDATE");


btnNewButton_2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { try {

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

String name = textField_1.getText();

String courseName = textField_3.getText();

String matricNo = textField_2.getText();

String query = "UPDATE `tbl_courseregister` SET `student_name` = ?,


`matrix_number` = ? WHERE `course_name` = ?";

PreparedStatement pst = con.prepareStatement(query);

pst.setString(1, name); pst.setString(2, matricNo);

pst.setString(3, courseName); pst.executeUpdate();

JOptionPane.showMessageDialog(contentPane, "Information updated


successfully!");

} catch (SQLException ex) { ex.printStackTrace();

} }); btnNewButton_2.setBounds(175, 287,

89, 23); panel_1.add(btnNewButton_2);

JButton btnNewButton_3 = new JButton("RESET");


btnNewButton_3.setBounds(291, 287, 89, 23);
panel_1.add(btnNewButton_3);

JButton btnNewButton_4 = new JButton("DELETE");

btnNewButton_4.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { try {

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

String courseName = textField_3.getText();

String query = "DELETE FROM `tbl_courseregister` WHERE `course_name`


= ?";

PreparedStatement pst = con.prepareStatement(query);

pst.setString(1, courseName); pst.executeUpdate();

JOptionPane.showMessageDialog(contentPane, "Information deleted


successfully!");

} catch (SQLException ex) { ex.printStackTrace();

} }); btnNewButton_4.setBounds(409, 287,


89, 23); panel_1.add(btnNewButton_4);
textField_5 = new JTextField();
textField_5.setColumns(10);
textField_5.setBounds(110, 214, 86, 20);
panel_1.add(textField_5);
JLabel lblNewLabel_1 = new JLabel("Transkip");

lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 15));

lblNewLabel_1.setBounds(28, 262, 65, 27);

contentPane.add(lblNewLabel_1); textField = new

JTextField(); textField.setBounds(102, 267, 180, 20);

contentPane.add(textField); textField.setColumns(10);

final JButton btnNewButton = new JButton("UPLOAD");

btnNewButton.setBounds(312, 266, 89, 23);

contentPane.add(btnNewButton);

JLabel lblNewLabel_8 = new JLabel("Information and Communication

Technology Department"); lblNewLabel_8.setFont(new

Font("Tahoma", Font.ITALIC, 18)); lblNewLabel_8.setBounds(283,

10, 467, 20); contentPane.add(lblNewLabel_8); JLabel

lblNewLabel_9 = new JLabel("Course Registration");

lblNewLabel_9.setFont(new Font("Tahoma", Font.ITALIC, 18));

lblNewLabel_9.setBounds(432, 35, 162, 34);

contentPane.add(lblNewLabel_9);

btnNewButton.addActionListener(new ActionListener() { public

void actionPerformed(ActionEvent e) { if (e.getSource()==

btnNewButton) {

JFileChooser j = new
JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());

// invoke the showsOpenDialog function to show the save dialog


int r = j.showOpenDialog(null); // if

the user selects a file if (r ==

JFileChooser.APPROVE_OPTION)

// set the label to the path of the selected file

textField.setText(j.getSelectedFile().getAbsolutePath()); }

// if the user cancelled the operation

} }); btnNewButton_3.addActionListener(new

ActionListener() { public void

actionPerformed(ActionEvent e) { textField.setText("");

textField_1.setText(""); textField_2.setText("");

textField_3.setText(""); textField_4.setText("");

textField_5.setText("");

chckbxNewCheckBox.setSelected(false);

comboBox.setSelectedIndex(0);

});

}
DESIGN

OUTPUT
RUBRIC

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