0% found this document useful (0 votes)
8 views10 pages

Oopactivities14 15

The document contains programming activities for Object Oriented Programming at Southern Luzon State University, specifically activities 14 and 15. Activity 14 involves creating a student registration form using Java Swing, while Activity 15 focuses on designing a scientific calculator layout. Both activities include source code that demonstrates the implementation of GUI components and layout management.

Uploaded by

Mico
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)
8 views10 pages

Oopactivities14 15

The document contains programming activities for Object Oriented Programming at Southern Luzon State University, specifically activities 14 and 15. Activity 14 involves creating a student registration form using Java Swing, while Activity 15 focuses on designing a scientific calculator layout. Both activities include source code that demonstrates the implementation of GUI components and layout management.

Uploaded by

Mico
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/ 10

Southern Luzon State University

COLLEGE OF ENGINEERING
Lucban, Quezon

CpE05 – Object Oriented Programming


Activity 14

Prepared by:
ALAY, MICO
BSCPE IIA - GE

Presented to:
ENGR. MADONNA CASTRO

May 08, 2025


Southern Luzon State University
College Of Engineering
Computer Engineering Department

PROGRAMMING ACTIVITY 14

CpE05 - Object Oriented Programming


SY 2024-2025

Name: ALAY, MICO Section: BSCpE – 2GE

SOURCE CODE:

// ======== Frames.java ========


package activity1;

import javax.swing.*;
import java.awt.*;

public class Frames extends JFrame { // Subclassing the Frames from JFrame
directly instead of
// constructing an instance from the
JFrame class. Allows
// overriding and better
customization.
public Frames() {
setTitle("Student Registration Form");
setSize(800, 800);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);

// Main content panel


JPanel mainPanel = new JPanel();
// Layout is vertically stacked, though box layout is not included in
the module
// lol
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));

// Ensures a margin of 10 pixels on all sides — top, left, bottom,


right
// to keep the content from touching the edge of the window.
mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10,
10));

// Adding different sections of the form to the panel inside the frame
mainPanel.add(new HeaderPanel());
mainPanel.add(Box.createRigidArea(new Dimension(0, 10))); // 10 px
vertical gap
mainPanel.add(new UserInfoPanel());
mainPanel.add(Box.createRigidArea(new Dimension(0, 10)));
mainPanel.add(new MoreInfoPanel());
mainPanel.add(Box.createRigidArea(new Dimension(0, 10)));
mainPanel.add(new ButtonPanel());

// Wraps the main panel of the frame inside a scrollable pane


add(new JScrollPane(mainPanel));

// Displays the frame


setVisible(true);
}
public static void main(String[] args) {
new Frames();
}
}

// ======== HeaderPanel.java ========


package activity1;

import javax.swing.*;
import java.awt.*;

public class HeaderPanel extends JPanel {


private JLabel createLabel(String text, int size, int style) {
JLabel label = new JLabel(text);
label.setFont(new Font("Arial", style, size));
label.setAlignmentX(Component.CENTER_ALIGNMENT);
return label;
}

public HeaderPanel() {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0)); // 10px at
bottom and top

JLabel universityLabel = createLabel("SOUTHERN LUZON STATE


UNIVERSITY", 18, Font.BOLD);
JLabel addressLabel = createLabel("Brgy. Kulapi, Lucban, Quezon", 14,
Font.PLAIN);
JLabel collegeLabel = createLabel("College of Engineering", 16,
Font.BOLD);
JLabel regFormLabel = createLabel("REGISTRATION FORM", 16,
Font.BOLD);

add(universityLabel);
add(addressLabel);
add(collegeLabel);
add(Box.createRigidArea(new Dimension(0, 10))); // 10px vertical gap
add(regFormLabel);
}

// ======== UserInfoPanel.java ========


package activity1;

import javax.swing.*;
import java.awt.*;

public class UserInfoPanel extends JPanel {


private JTextField usernameField, nameField, dobField, ageField,
citizenshipField, religionField, contactField,
fatherNameField, motherNameField;
private JComboBox<String> yearBox, casBox;
private JRadioButton maleRadio, femaleRadio, otherRadio, pntsRadio;
private ButtonGroup genderGroup;
private TextField passwordField, confirmPasswordField;

public UserInfoPanel() {
setLayout(new GridLayout(0, 2, 5, 5)); // 0 rows, 2 columns, 5px of
spacing in both axes.

// Text fields
usernameField = new JTextField();
passwordField = new TextField(15);
passwordField.setEchoChar('#');
confirmPasswordField = new TextField(15);
confirmPasswordField.setEchoChar('#');
nameField = new JTextField();
dobField = new JTextField();
ageField = new JTextField();
citizenshipField = new JTextField();
religionField = new JTextField();
contactField = new JTextField();
fatherNameField = new JTextField();
motherNameField = new JTextField();

// Drop-downs
yearBox = new JComboBox<>(new String[] { "--Select your Year--", "I",
"II", "III", "IV" });
casBox = new JComboBox<>(new String[] { "--Select your Course &
Section--", "BSCE-GA", "BSCE-GB", "BSCPE-GE",
"BSCPE-GF", "BSECE-GG", "BSECE-GH", "BSEE-GI", "BSEE-GJ",
"BSIE-GK", "BSIE-GL", "BSME-GM", "BSME-GN" });

// Gender radio buttons


maleRadio = new JRadioButton("Male");
femaleRadio = new JRadioButton("Female");
otherRadio = new JRadioButton("Other");
pntsRadio = new JRadioButton("Prefer not to Say");

genderGroup = new ButtonGroup();


genderGroup.add(maleRadio);
genderGroup.add(femaleRadio);
genderGroup.add(otherRadio);
genderGroup.add(pntsRadio);

JPanel genderPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));


genderPanel.add(maleRadio);
genderPanel.add(femaleRadio);
genderPanel.add(otherRadio);
genderPanel.add(pntsRadio);

// Adding components
add(new JLabel("Username:"));
add(usernameField);
add(new JLabel("Password:"));
add(passwordField);
add(new JLabel("Confirm Password:"));
add(confirmPasswordField);
add(new JLabel("Name:"));
add(nameField);
add(new JLabel("Date of Birth:"));
add(dobField);
add(new JLabel("Age:"));
add(ageField);
add(new JLabel("Citizenship:"));
add(citizenshipField);
add(new JLabel("Religion:"));
add(religionField);
add(new JLabel("Contact No.:"));
add(contactField);
add(new JLabel("Father's Name:"));
add(fatherNameField);
add(new JLabel("Mother's Name:"));
add(motherNameField);
add(new JLabel("Year Level:"));
add(yearBox);
add(new JLabel("Course & Section:"));
add(casBox);
add(new JLabel("Gender:"));
add(genderPanel);
}
}
// ======== MoreInfoPanel.java ========
package activity1;

import javax.swing.*;
import java.awt.*;

public class MoreInfoPanel extends JPanel {


private JTextArea mottoArea, skillsArea, seminarsArea;

public MoreInfoPanel() {
// 3 rows, 2 columns for labels and text areas
// 5 px of spacing in horizontal and vertical axes.
setLayout(new GridLayout(3, 2, 5, 5));

// Create text areas with scroll


mottoArea = createTextArea();
skillsArea = createTextArea();
seminarsArea = createTextArea();

// Add labels and corresponding text areas


add(new JLabel("Motto in Life:"));
add(mottoArea); // Regular text area
add(new JLabel("Skills:"));
add(skillsArea); // Regular text area
add(new JLabel("Seminars Attended:"));
add(new JScrollPane(seminarsArea)); // Wrap in JScrollPane
}

private JTextArea createTextArea() {


// 3 rows of characters, width is dynamic because
// it relies on the layout of the parent container.
JTextArea textArea = new JTextArea(3, 0);
textArea.setLineWrap(true); // Wraps to the next line if the chars
limit is reached
textArea.setWrapStyleWord(true); // Prevents words from being split
return textArea;
}
}

// ======== ButtonPanel.java ========


package activity1;

import javax.swing.*;
import java.awt.*;

public class ButtonPanel extends JPanel {


private JButton submitButton, resetButton, validateButton;

public ButtonPanel() {
setLayout(new FlowLayout(FlowLayout.CENTER));

submitButton = new JButton("Submit");


resetButton = new JButton("Reset");
validateButton = new JButton("Validate");

add(submitButton);
add(resetButton);
add(validateButton);
}
}
OUTPUT:
Southern Luzon State University
COLLEGE OF ENGINEERING
Lucban, Quezon

CpE05 – Object Oriented Programming


Activity 15

Prepared by:
ALAY, MICO
BSCPE IIA - GE

Presented to:
ENGR. MADONNA CASTRO

May 08, 2025


Southern Luzon State University
College Of Engineering
Computer Engineering Department

PROGRAMMING ACTIVITY 15

CpE05 - Object Oriented Programming


SY 2024-2025

Name: ALAY, MICO Section: BSCpE – 2GE

SOURCE CODE:
package activity2;

import javax.swing.*;
import java.awt.*;

public class CalculatorLayout extends JFrame {


public CalculatorLayout() {
setTitle("Scientific Calculator Layout");
setSize(400, 600);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);

JPanel mainPanel = new JPanel(new BorderLayout(10, 10));

// Display
JTextField displayField = new JTextField();
displayField.setFont(new Font("Consolas", Font.BOLD, 24));
displayField.setHorizontalAlignment(JTextField.RIGHT);
displayField.setPreferredSize(new Dimension(400, 60));
displayField.setEditable(false);

mainPanel.add(displayField, BorderLayout.NORTH);
mainPanel.add(new ButtonPanel(displayField), BorderLayout.CENTER);

add(mainPanel);
setVisible(true);
}

public static void main(String[] args) {


new CalculatorLayout();
}
}

package activity2;

import javax.swing.*;
import java.awt.*;

public class ButtonPanel extends JPanel {


private JButton[] buttons;
private String[] buttonLabels = {
"sin", "cos", "tan", "ln", "log",
"x²", "√", "x³", "∛", "π",
"(", ")", "∫", "d/dx", "C",
"7", "8", "9", "/", "Σ",
"4", "5", "6", "*", "Area",
"1", "2", "3", "-", "Perim",
"0", ".", "±", "+", "Vol",
"Ans", "DEL", "EXP", "=", "MODE"
};

public ButtonPanel(JTextField displayField) {


setLayout(new GridLayout(8, 5, 5, 5)); // 8 rows, 5 columns
buttons = new JButton[buttonLabels.length];

for (int i = 0; i < buttonLabels.length; i++) {


buttons[i] = new JButton(buttonLabels[i]);
buttons[i].setFont(new Font("Arial", Font.PLAIN, 12));
add(buttons[i]);
}
}
}

OUTPUT:

You might also like