NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

public class Job {
final String title;
final String company;
final String description;
final String salary; // Changed from double to String
final String workHours;

// Constructor with all fields
public Job(String title, String company, String description, String salary, String workHours) {
this.title = title;
this.company = company;
this.description = description;
this.salary = salary;
this.workHours = workHours;
}

// Getters for all fields
public String getTitle() {
return title;
}

public String getCompany() {
return company;
}

public String getDescription() {
return description;
}

public String getSalary() {
return salary;
}

public String getWorkHours() {
return workHours;
}

// toString() method for displaying job details
@Override
public String toString() {
return "Title: " + title + ", Company: " + company + ", Description: " + description +
", Salary: " + salary + ", Work Hours: " + workHours;
}
}









import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class JobPortal {

private List<Job> jobs;
// Replace these with your actual database credentials
private static final String URL = "jdbc:mysql://localhost:3306/jobportaldb"; // Use your database URL
private static final String USER = "root"; // Use your MySQL username
private static final String PASSWORD = "masuma2002"; // Use your MySQL password

public JobPortal() {
jobs = new ArrayList<>();
// Optionally, load the jobs from the database when the portal is initialized
loadJobsFromDatabase();
}

public void postJob(Job job) {
jobs.add(job); // Add to local list
saveJobToDatabase(job); // Save to database
}

public List<Job> getAllJobs() {
// This method fetches jobs from the database (not from the local list)
List<Job> jobList = new ArrayList<>();
String sql = "SELECT * FROM jobs";

try (Connection connection = DriverManager.getConnection(URL, USER, PASSWORD); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(sql)) {

while (resultSet.next()) {
String title = resultSet.getString("title");
String company = resultSet.getString("company");
String description = resultSet.getString("description");
String salary = resultSet.getString("salary");
String workHours = resultSet.getString("work_hours");

Job job = new Job(title, company, description, salary, workHours);
jobList.add(job);
}
} catch (SQLException e) {
e.printStackTrace();
}
return jobList;
}

public List<Job> searchJobs(String keyword) {
// This searches through the local list, not the database
List<Job> results = new ArrayList<>();
for (Job job : jobs) {
if (job.getTitle().toLowerCase().contains(keyword.toLowerCase())) {
results.add(job);
}
}
return results;
}

private void loadJobsFromDatabase() {
// This method loads jobs from the database into the local list
String sql = "SELECT * FROM jobs";

try (Connection connection = DriverManager.getConnection(URL, USER, PASSWORD); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(sql)) {

while (resultSet.next()) {
String title = resultSet.getString("title");
String company = resultSet.getString("company");
String description = resultSet.getString("description");
String salary = resultSet.getString("salary");
String workHours = resultSet.getString("work_hours");

Job job = new Job(title, company, description, salary, workHours);
jobs.add(job); // Populate the local job list
}
} catch (SQLException e) {
e.printStackTrace();
}
}

private void saveJobToDatabase(Job job) {
// This method saves a job to the database
String sql = "INSERT INTO jobs (title, company, description, salary, work_hours) VALUES (?, ?, ?, ?, ?)";

try (Connection connection = DriverManager.getConnection(URL, USER, PASSWORD); PreparedStatement statement = connection.prepareStatement(sql)) {

statement.setString(1, job.getTitle());
statement.setString(2, job.getCompany());
statement.setString(3, job.getDescription());
statement.setString(4, job.getSalary());
statement.setString(5, job.getWorkHours());

int rowsInserted = statement.executeUpdate();
if (rowsInserted > 0) {
System.out.println("Job posted to the database successfully.");
} else {
System.out.println("Failed to post the job.");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}









import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

/**
*
* @author shabn
*/
public class JobPortalGUI extends JFrame {

private JobPortal jobPortal;

public JobPortalGUI() {
jobPortal = new JobPortal();

// Frame Settings
setTitle("Job Portal");
setSize(500, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());

// Background Color
getContentPane().setBackground(new Color(210, 215, 225)); // Soft light color

// Panel for Buttons
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(3, 1, 10, 10)); // Adding space between buttons
buttonPanel.setBackground(new Color(255, 255, 255));

// Welcome label
JLabel welcomeLabel = new JLabel("Welcome to Job Portal", JLabel.CENTER);
welcomeLabel.setFont(new Font("Arial", Font.BOLD, 24));

// Employer Button
JButton employerButton = new JButton("I am an Employer");
employerButton.setFont(new Font("Arial", Font.PLAIN, 16));
employerButton.setBackground(new Color(34, 193, 195));
employerButton.setForeground(Color.WHITE);
employerButton.setFocusPainted(false);
employerButton.addActionListener(e -> switchToEmployerPanel());

// Job Seeker Button
JButton jobSeekerButton = new JButton("I am a Job Seeker");
jobSeekerButton.setFont(new Font("Arial", Font.PLAIN, 16));
jobSeekerButton.setBackground(new Color(34, 193, 195));
jobSeekerButton.setForeground(Color.WHITE);
jobSeekerButton.setFocusPainted(false);
jobSeekerButton.addActionListener(e -> switchToJobSeekerPanel());

// Exit Button
JButton exitButton = new JButton("Exit");
exitButton.setFont(new Font("Arial", Font.PLAIN, 16));
exitButton.setBackground(new Color(255, 69, 58)); // Red color for exit
exitButton.setForeground(Color.WHITE);
exitButton.setFocusPainted(false);
exitButton.addActionListener(e -> System.exit(0));

// Adding buttons to panel
buttonPanel.add(employerButton);
buttonPanel.add(jobSeekerButton);
buttonPanel.add(exitButton);

// Add components to the frame
add(welcomeLabel, BorderLayout.NORTH);
add(buttonPanel, BorderLayout.CENTER);

setVisible(true);
}

private void switchToEmployerPanel() {
new EmployerPanel(jobPortal);
this.dispose();
}

private void switchToJobSeekerPanel() {
new JobSeekerPanel(jobPortal);
this.dispose();
}

public static void main(String[] args) {
SwingUtilities.invokeLater(JobPortalGUI::new);
}
}







import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.swing.*;

public class EmployerPanel extends JFrame {
private JobPortal jobPortal;
private JTextField titleField, companyField, descriptionField, salaryField, workHoursField;

public EmployerPanel(JobPortal jobPortal) {
this.jobPortal = jobPortal;

setTitle("Employer - Post Job");
setSize(500, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridBagLayout());

// Background color
getContentPane().setBackground(new Color(245, 245, 245));

GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(10, 10, 10, 10);

JLabel titleLabel = new JLabel("Job Title:");
titleField = new JTextField(20);

JLabel companyLabel = new JLabel("Company:");
companyField = new JTextField(20);

JLabel descriptionLabel = new JLabel("Description:");
descriptionField = new JTextField(20);

JLabel salaryLabel = new JLabel("Salary:");
salaryField = new JTextField(20);

JLabel workHoursLabel = new JLabel("Work Hours:");
workHoursField = new JTextField(20);

JButton postJobButton = new JButton("Post Job");
postJobButton.setFont(new Font("Arial", Font.PLAIN, 16));
postJobButton.setBackground(new Color(34, 193, 195));
postJobButton.setForeground(Color.WHITE);
postJobButton.addActionListener(new PostJobAction());

JButton exitButton = new JButton("Exit");
exitButton.setFont(new Font("Arial", Font.PLAIN, 16));
exitButton.setBackground(new Color(255, 69, 58));
exitButton.setForeground(Color.WHITE);
exitButton.addActionListener(e -> switchToJobPortal());

// Layout and adding components
gbc.gridx = 0;
gbc.gridy = 0;
add(titleLabel, gbc);
gbc.gridx = 1;
add(titleField, gbc);

gbc.gridx = 0;
gbc.gridy = 1;
add(companyLabel, gbc);
gbc.gridx = 1;
add(companyField, gbc);

gbc.gridx = 0;
gbc.gridy = 2;
add(descriptionLabel, gbc);
gbc.gridx = 1;
add(descriptionField, gbc);

gbc.gridx = 0;
gbc.gridy = 3;
add(salaryLabel, gbc);
gbc.gridx = 1;
add(salaryField, gbc);

gbc.gridx = 0;
gbc.gridy = 4;
add(workHoursLabel, gbc);
gbc.gridx = 1;
add(workHoursField, gbc);

gbc.gridx = 0;
gbc.gridy = 5;
gbc.gridwidth = 2;
add(postJobButton, gbc);

gbc.gridx = 0;
gbc.gridy = 6;
gbc.gridwidth = 2;
add(exitButton, gbc);

setVisible(true);
}

private class PostJobAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
String title = titleField.getText();
String company = companyField.getText();
String description = descriptionField.getText();
String salary = salaryField.getText();
String workHours = workHoursField.getText();

// If all fields are filled, save to database
if (!title.isEmpty() && !company.isEmpty() && !description.isEmpty()) {
saveJobToDatabase(title, company, description, salary, workHours);
JOptionPane.showMessageDialog(null, "Job posted successfully!");
clearFields();
} else {
JOptionPane.showMessageDialog(null, "Please fill all required fields.");
}
}
}

private void saveJobToDatabase(String title, String company, String description, String salary, String workHours) {
String url = "jdbc:mysql://localhost:3306/jobportaldb"; // Replace with your DB name
String username = "root"; // Replace with your MySQL username
String password = "masuma2002"; // Replace with your MySQL password

try {
// Establish connection
Connection connection = DriverManager.getConnection(url, username, password);

// SQL query to insert data into jobs table
String query = "INSERT INTO jobs (title, company, description, salary, work_hours) VALUES (?, ?, ?, ?, ?)";
PreparedStatement pstmt = connection.prepareStatement(query);
pstmt.setString(1, title);
pstmt.setString(2, company);
pstmt.setString(3, description);
pstmt.setString(4, salary);
pstmt.setString(5, workHours);

// Execute update
pstmt.executeUpdate();

// Close connection
pstmt.close();
connection.close();
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "Error posting the job: " + ex.getMessage());
}
}

private void clearFields() {
titleField.setText("");
companyField.setText("");
descriptionField.setText("");
salaryField.setText("");
workHoursField.setText("");
}

private void switchToJobPortal() {
new JobPortalGUI();
this.dispose(); // Close the Employer Panel
}
}






import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.*;

public class JobSeekerPanel extends JFrame {

private JobPortal jobPortal;
private JTextArea jobDisplayArea;
private JTextField searchField;

public JobSeekerPanel(JobPortal jobPortal) {
this.jobPortal = jobPortal;

// Setting up the frame properties
setTitle("Job Seeker - Search Jobs");
setSize(500, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridBagLayout());

// Background Color
getContentPane().setBackground(new Color(245, 245, 245));

GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(10, 10, 10, 10);

// Label and Text Field for Search
JLabel searchLabel = new JLabel("Search by Title:");
searchLabel.setFont(new Font("Arial", Font.PLAIN, 14));

searchField = new JTextField(15);
searchField.setFont(new Font("Arial", Font.PLAIN, 14));

// Search Button
JButton searchButton = new JButton("Search Job");
searchButton.setFont(new Font("Arial", Font.PLAIN, 16));
searchButton.setBackground(new Color(34, 193, 195));
searchButton.setForeground(Color.WHITE);
searchButton.addActionListener(new SearchJobAction());

// View All Jobs Button
JButton viewAllButton = new JButton("View All Jobs");
viewAllButton.setFont(new Font("Arial", Font.PLAIN, 16));
viewAllButton.setBackground(new Color(34, 193, 195));
viewAllButton.setForeground(Color.WHITE);
viewAllButton.addActionListener(new ViewAllJobsAction());

// Exit Button
JButton exitButton = new JButton("Exit");
exitButton.setFont(new Font("Arial", Font.PLAIN, 16));
exitButton.setBackground(new Color(255, 69, 58));
exitButton.setForeground(Color.WHITE);
exitButton.addActionListener(e -> switchToJobPortal());

// Text Area to Display Jobs
jobDisplayArea = new JTextArea(15, 30);
jobDisplayArea.setFont(new Font("Arial", Font.PLAIN, 14));
jobDisplayArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(jobDisplayArea);

// Layout and adding components to the frame
gbc.gridx = 0;
gbc.gridy = 0;
add(searchLabel, gbc);
gbc.gridx = 1;
add(searchField, gbc);

gbc.gridx = 0;
gbc.gridy = 1;
add(searchButton, gbc);
gbc.gridx = 1;
add(viewAllButton, gbc);

gbc.gridx = 0;
gbc.gridy = 2;
gbc.gridwidth = 2;
add(scrollPane, gbc);

gbc.gridy = 3;
add(exitButton, gbc);

setVisible(true);
}

// Action to search for jobs based on the title
private class SearchJobAction implements ActionListener {

public void actionPerformed(ActionEvent e) {
String keyword = searchField.getText();
List<Job> results = jobPortal.searchJobs(keyword);
jobDisplayArea.setText(""); // Clear previous results
for (Job job : results) {
jobDisplayArea.append(job.toString() + "n");
}
if (results.isEmpty()) {
jobDisplayArea.setText("No jobs found.");
}
}
}

private class ViewAllJobsAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
List<Job> jobs = jobPortal.getAllJobs(); // Ensure this fetches jobs from the DB

// Clear previous results
jobDisplayArea.setText("");

if (jobs.isEmpty()) {
jobDisplayArea.setText("No jobs posted yet.");
} else {
for (Job job : jobs) {
jobDisplayArea.append(job.toString() + "n");
}
}
}
}


// Method to switch to the main JobPortal GUI
private void switchToJobPortal() {
new JobPortalGUI(); // Open the main JobPortal GUI
this.dispose(); // Close the JobSeekerPanel
}

// Main method to run the JobSeekerPanel if needed
public static void main(String[] args) {
// Example of creating a JobPortal instance and passing it to the JobSeekerPanel
JobPortal jobPortal = new JobPortal(); // Assume JobPortal has a default constructor
new JobSeekerPanel(jobPortal);
}
}




//package .vscode;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Driver {

public static void main(String[] args) {
// MySQL Database connection details
String url = "jdbc:mysql://localhost:3306/jobportaldb";
String username = "root";
String password = "masuma2002";

try {
// Establish connection to MySQL
Connection connection = DriverManager.getConnection(url, username, password);

// Create a statement to execute queries
Statement stmt = connection.createStatement();

// Execute a simple query
String query = "SELECT * FROM jobs"; // Example query
ResultSet rs = stmt.executeQuery(query);

// Process the result set
while (rs.next()) {
System.out.println("Job Title: " + rs.getString("title"));
System.out.println("Company: " + rs.getString("company"));
System.out.println("Description: " + rs.getString("description"));
System.out.println("Salary: " + rs.getString("salary"));
System.out.println("Work Hours: " + rs.getString("work_hours"));
System.out.println("------");
}

// Close resources
rs.close();
stmt.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}




//launchJson

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "JobPortalGUI",
"request": "launch",
"mainClass": "JobPortalGUI",
"projectName": "java_4f235fb3"
},
{
"type": "java",
"name": "JobSeekerPanel",
"request": "launch",
"mainClass": "JobSeekerPanel",
"projectName": "java_4f235fb3"
},
{
"type": "java",
"name": "Main",
"request": "launch",
"mainClass": "Main",
"projectName": "java_4f235fb3"
}
]
}
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.