CV builder all source codes¶
Terminology Explained
GridBagConstraints-āĻāϰ āĻā§āϰā§āϤā§āĻŦāĻĒā§āϰā§āĻŖ āĻĒā§āϰā§āĻĒāĻžāϰā§āĻāĻŋāĻā§āϞā§āϰ āϏāĻāĻā§āώāĻŋāĻĒā§āϤ āϰā§āĻĒ āύāĻŋāĻā§ āĻĻā§āĻā§āĻž āĻšāϞā§:
- gridx & gridy: āĻāĻĒāĻžāĻĻāĻžāύāĻāĻŋ āĻā§āϰāĻŋāĻĄā§āϰ āĻāϤ āύāĻŽā§āĻŦāϰ āĻāϞāĻžāĻŽ āĻ āϰā§-āϤ⧠āĻŦāϏāĻŦā§āĨ¤
- gridwidth & gridheight: āĻāĻĒāĻžāĻĻāĻžāύāĻāĻŋ āĻĒāĻžāĻļāĻžāĻĒāĻžāĻļāĻŋ āĻŦāĻž āĻāĻĒāϰ-āύāĻŋāĻā§ āĻā§āĻāĻŋ āĻāϰ āĻā§ā§ā§ āĻĨāĻžāĻāĻŦā§āĨ¤
- weightx & weighty: āϏā§āĻā§āϰāĻŋāύ āĻŦā§ āĻāϰāϞ⧠āĻāĻĒāĻžāĻĻāĻžāύāĻāĻŋ āĻāϞāĻžāĻŽ āĻŦāĻž āϰ⧠āĻŦāϰāĻžāĻŦāϰ āĻāϤāĻāĻž āĻāĻžā§āĻāĻž āĻŦāĻžā§āĻŋā§ā§ āύā§āĻŦā§āĨ¤
- fill: āĻāĻĒāĻžāĻĻāĻžāύāĻāĻŋ āύāĻŋāĻā§āϰ āĻāϰā§āϰ āĻā§āϤāϰā§āϰ āĻĢāĻžāĻāĻāĻž āĻāĻžā§āĻāĻž āĻā§āĻāĻžāĻŦā§ āĻāϰāĻžāĻ (Horizontal/Vertical/Both) āĻāϰāĻŦā§āĨ¤
- anchor: āĻāĻĒāĻžāĻĻāĻžāύāĻāĻŋ āύāĻŋāĻā§āϰ āĻāϰā§āϰ āĻā§āϤāϰ āĻā§āύ āĻĻāĻŋāĻā§ āĻā§āĻĒā§ āĻĨāĻžāĻāĻŦā§ (āϝā§āĻŽāύ: CENTER, NORTH, WEST)āĨ¤
- insets: āĻāĻĒāĻžāĻĻāĻžāύāĻāĻŋāϰ āĻāĻžāϰāĻĒāĻžāĻļā§āϰ āĻŦāĻžāĻāϰā§āϰ āĻĢāĻžāĻāĻāĻž āĻāĻžā§āĻāĻž (Padding/Margin)āĨ¤
- ipadx & ipady: āĻāĻĒāĻžāĻĻāĻžāύāĻāĻŋāϰ āĻā§āϤāϰā§āϰ āύāĻŋāĻāϏā§āĻŦ Internal Padding āĻŦāĻž āĻāĻāĻžāϰ āĻŦāĻžā§āĻžāύā§āĨ¤
Professional Summary Pane
āĻāĻĒāύāĻžāϰ āĻĒā§āϰāĻļā§āύāĻāĻž āĻāĻŋāύā§āϤ⧠āĻā§āĻŦāĻ āϞāĻāĻŋāĻā§āϝāĻžāϞ! đĄ āĻāĻĒāύāĻžāϰ āĻŽāύ⧠āĻšāϤā§āĻ āĻĒāĻžāϰ⧠āϝ⧠āĻāύāĻĒā§āĻ āĻĢāĻŋāϞā§āĻĄ āϤ⧠txtSummary, āϤāĻžāĻšāϞ⧠āĻŽāĻžāĻāĻāĻžāύ⧠āĻāĻŦāĻžāϰ āϏā§āĻā§āϰāϞ āĻĒā§āϝāĻžāύāĻā§ āĻāĻžāύāĻžāϰ āĻā§ āĻĻāϰāĻāĻžāϰ?
āĻāĻžāĻāĻž āϏā§āĻāĻ (Java Swing)-āĻ JTextArea āĻŦā§āϝāĻŦāĻšāĻžāϰā§āϰ āϏāĻŽā§ āĻāĻāĻāĻž āĻāĻŽā§āĻāĻžāϰ āĻŽā§āĻāĻžāύāĻŋāĻāĻŽ āĻāĻžāĻ āĻāϰā§āĨ¤ đ
āĻāĻŽāϰāĻž āϝāĻĻāĻŋ āϏāϰāĻžāϏāϰāĻŋ txtSummary-āĻā§ āĻĒā§āϝāĻžāύā§āϞ⧠āϝā§āĻā§āϤ āĻāϰāĻŋ, āϤāĻžāĻšāϞ⧠āĻāĻāĻāĻžāϰ āϝāĻāύ ā§Ē āϞāĻžāĻāύā§āϰ āĻŦā§āĻļāĻŋ āĻŦā§ āĻā§āύ⧠āϏāĻžāĻŽāĻžāϰāĻŋ āĻāĻžāĻāĻĒ āĻāϰāĻŦā§, āϤāĻāύ āĻ
āϤāĻŋāϰāĻŋāĻā§āϤ āϞā§āĻāĻžāĻā§āϞ⧠āĻŦāĻā§āϏā§āϰ āύāĻŋāĻā§ āĻĸāĻžāĻāĻž āĻĒā§ā§ āϝāĻžāĻŦā§āĨ¤ āĻāĻāĻāĻžāϰ āĻāĻžāĻāϞā§āĻ āĻŽāĻžāĻāϏ āĻĻāĻŋā§ā§ āϏā§āĻā§āϰāϞ āĻāϰ⧠āĻāĻĒāϰ-āύāĻŋāĻā§āϰ āϞā§āĻāĻž āĻĻā§āĻāϤ⧠āĻĒāĻžāϰāĻŦā§ āύāĻžāĨ¤
āĻāĻāĻžāύā§āĻ āĻāĻžāĻā§ āĻāϏ⧠JScrollPane (āĻāĻŽāĻžāĻĻā§āϰ summaryScroll):
- đĻ āĻāĻāĻŋ āĻāĻāĻāĻŋ āϧāĻžāϰāĻ āĻŦāĻž āĻāύā§āĻā§āĻāύāĻžāϰ āĻšāĻŋāϏā§āĻŦā§ āĻāĻžāĻ āĻāϰ⧠āϝāĻž āĻĢāĻŋāϞā§āĻĄāĻāĻŋāĻā§ āύāĻŋāĻā§āϰ āĻĒā§āĻā§ āϧāϰ⧠āϰāĻžāĻā§āĨ¤
- âī¸ āϝāĻāύāĻ āϞā§āĻāĻž āύāĻŋāϰā§āϧāĻžāϰāĻŋāϤ āϏāĻžāĻāĻā§āϰ āĻā§ā§ā§ āĻŦā§ āĻšā§ā§ āϝāĻžā§, āĻāĻāĻŋ āĻ āĻā§āĻŽā§āĻāĻŋāĻ āĻĒāĻžāĻļā§ āĻāĻāĻāĻŋ āϏā§āĻā§āϰāϞāĻŦāĻžāϰ āύāĻŋā§ā§ āĻāϏā§, āϝāĻž āĻĒā§āϰ⧠āϏāĻŋāĻāĻŋāϰ āϞā§āĻāĻāĻāĻā§ āύāώā§āĻ āĻšāϤ⧠āĻĻā§ā§ āύāĻžāĨ¤
āϤāĻžāĻ āϏā§āĻāĻ-āĻāϰ āύāĻŋā§āĻŽ āĻšāϞā§, āĻŦā§ āĻā§āĻā§āϏāĻ āĻāϰāĻŋā§āĻž āϤā§āϰāĻŋ āĻāϰ⧠āϤāĻžāĻā§ āϏā§āĻā§āϰāϞ āĻĒā§āϝāĻžāύā§āϰ āĻā§āϤāϰ āĻĸā§āĻāĻŋā§ā§ āĻĻāĻŋāϤ⧠āĻšā§, āĻāϰ āĻĒā§āϝāĻžāύā§āϞ⧠āϝā§āĻā§āϤ āĻāϰāϤ⧠āĻšā§ āϏā§āĻ āϏā§āĻā§āϰāϞ āĻĒā§āϝāĻžāύāĻāĻŋāĻā§āĨ¤
01 Intro and Setup¶
02 Write and Fix pom.xml file¶
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>ResumeBuilder</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13.3</version>
</dependency>
</dependencies>
</project>
03 Creating JFrame and Title¶
import javax.swing.JFrame;
public class ResumeBuilder {
public static void main(String[] args) {
JFrame window = new JFrame("My Resume Builder");
window.setSize(800, 600); // āĻāĻāύā§āĻĄā§āϰ āϏāĻžāĻāĻ (āĻāĻā§āĻž āĻ āϞāĻŽā§āĻŦāĻž)
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // āĻŦāύā§āϧ āĻāϰāϞ⧠āĻĒā§āϰā§āĻā§āϰāĻžāĻŽ āĻĨāĻžāĻŽāĻŦā§
window.setVisible(true); // āĻāĻāύā§āĻĄā§āĻāĻŋ āϏā§āĻā§āϰāĻŋāύ⧠āĻĻā§āĻāĻžāĻŦā§
}
}
¶
import javax.swing.JFrame;
public class ResumeBuilder {
public static void main(String[] args) {
JFrame window = new JFrame("My Resume Builder");
window.setSize(800, 600); // āĻāĻāύā§āĻĄā§āϰ āϏāĻžāĻāĻ (āĻāĻā§āĻž āĻ āϞāĻŽā§āĻŦāĻž)
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // āĻŦāύā§āϧ āĻāϰāϞ⧠āĻĒā§āϰā§āĻā§āϰāĻžāĻŽ āĻĨāĻžāĻŽāĻŦā§
window.setVisible(true); // āĻāĻāύā§āĻĄā§āĻāĻŋ āϏā§āĻā§āϰāĻŋāύ⧠āĻĻā§āĻāĻžāĻŦā§
}
}
04 Splitting Panels¶
package org.example;
import javax.swing.*;
import java.awt.*;
public class ResumeBuilderUI {
public static void main(String[] args) {
JFrame window = new JFrame("MY CV Builder");
window.setSize(800, 500);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setDividerLocation(400);
// left panel
JPanel leftPanel = new JPanel();
leftPanel.setBackground(Color.LIGHT_GRAY);
// right panel
JPanel rightPanel = new JPanel();
rightPanel.setBackground(Color.WHITE);
splitPane.setLeftComponent(leftPanel);
splitPane.setRightComponent(rightPanel);
// leftPanel | rightPanel
window.add(splitPane);
window.setVisible(true);
}
}
¶
package org.example;
import javax.swing.*;
import java.awt.*;
public class ResumeBuilderUI {
public static void main(String[] args) {
JFrame window = new JFrame("MY CV Builder");
window.setSize(800, 500);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setDividerLocation(400);
// left panel
JPanel leftPanel = new JPanel();
leftPanel.setBackground(Color.LIGHT_GRAY);
// right panel
JPanel rightPanel = new JPanel();
rightPanel.setBackground(Color.WHITE);
splitPane.setLeftComponent(leftPanel);
splitPane.setRightComponent(rightPanel);
// leftPanel | rightPanel
window.add(splitPane);
window.setVisible(true);
}
}
05 Adding Simple Form fields¶
package org.example;
import javax.swing.*;
import java.awt.*;
public class ResumeBuilderUI {
public static void main(String[] args) {
JFrame window = new JFrame("MY CV Builder");
window.setSize(800, 500);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setDividerLocation(400);
// left panel
JPanel leftPanel = new JPanel(new GridLayout(5, 2, 10, 10)); // row, cols, hgap, vgap
leftPanel.setBackground(Color.LIGHT_GRAY);
// FORM
// Name field
JLabel lblName = new JLabel("Full Name");
JTextField txtName = new JTextField();
leftPanel.add(lblName);
leftPanel.add(txtName);
// Email field
JLabel lblEmail = new JLabel("Full Email");
JTextField txtEmail = new JTextField();
leftPanel.add(lblEmail);
leftPanel.add(txtEmail);
// Phone field
JLabel lblPhone = new JLabel("Full Phone");
JTextField txtPhone = new JTextField();
leftPanel.add(lblPhone);
leftPanel.add(txtPhone);
// Skills field
JLabel lblSkills = new JLabel("Full Skills");
JTextField txtSkills = new JTextField();
leftPanel.add(lblSkills);
leftPanel.add(txtSkills);
// right panel
JPanel rightPanel = new JPanel();
rightPanel.setBackground(Color.WHITE);
splitPane.setLeftComponent(leftPanel);
splitPane.setRightComponent(rightPanel);
// leftPanel | rightPanel
window.add(splitPane);
window.setVisible(true);
}
}
¶
package org.example;
import javax.swing.*;
import java.awt.*;
public class ResumeBuilderUI {
public static void main(String[] args) {
JFrame window = new JFrame("MY CV Builder");
window.setSize(800, 500);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setDividerLocation(400);
// left panel
JPanel leftPanel = new JPanel(new GridLayout(5, 2, 10, 10)); // row, cols, hgap, vgap
leftPanel.setBackground(Color.LIGHT_GRAY);
// FORM
// Name field
JLabel lblName = new JLabel("Full Name");
JTextField txtName = new JTextField();
leftPanel.add(lblName);
leftPanel.add(txtName);
// Email field
JLabel lblEmail = new JLabel("Full Email");
JTextField txtEmail = new JTextField();
leftPanel.add(lblEmail);
leftPanel.add(txtEmail);
// Phone field
JLabel lblPhone = new JLabel("Full Phone");
JTextField txtPhone = new JTextField();
leftPanel.add(lblPhone);
leftPanel.add(txtPhone);
// Skills field
JLabel lblSkills = new JLabel("Full Skills");
JTextField txtSkills = new JTextField();
leftPanel.add(lblSkills);
leftPanel.add(txtSkills);
// right panel
JPanel rightPanel = new JPanel();
rightPanel.setBackground(Color.WHITE);
splitPane.setLeftComponent(leftPanel);
splitPane.setRightComponent(rightPanel);
// leftPanel | rightPanel
window.add(splitPane);
window.setVisible(true);
}
}
06 Adding Live Preview¶
package org.example;
import javax.swing.*;
import java.awt.*;
public class ResumeBuilderUI {
public static void main(String[] args) {
JFrame window = new JFrame("MY CV Builder");
window.setSize(800, 500);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setDividerLocation(400);
// left panel
JPanel leftPanel = new JPanel(new GridLayout(5, 2, 10, 10)); // row, cols, hgap, vgap
leftPanel.setBackground(Color.LIGHT_GRAY);
// FORM
// Name field
JLabel lblName = new JLabel("Full Name");
JTextField txtName = new JTextField();
leftPanel.add(lblName);
leftPanel.add(txtName);
// Email field
JLabel lblEmail = new JLabel("Full Email");
JTextField txtEmail = new JTextField();
leftPanel.add(lblEmail);
leftPanel.add(txtEmail);
// Phone field
JLabel lblPhone = new JLabel("Full Phone");
JTextField txtPhone = new JTextField();
leftPanel.add(lblPhone);
leftPanel.add(txtPhone);
// Skills field
JLabel lblSkills = new JLabel("Full Skills");
JTextField txtSkills = new JTextField();
leftPanel.add(lblSkills);
leftPanel.add(txtSkills);
// for preview
JTextArea txtPreview = new JTextArea();
txtPreview.setEditable(false);
// right panel
JPanel rightPanel = new JPanel();
rightPanel.setBackground(Color.WHITE);
rightPanel.setLayout(new BorderLayout());
rightPanel.add(txtPreview);
// scrolling option for right preview panel
JScrollPane previewScroll = new JScrollPane(txtPreview);
rightPanel.add(previewScroll);
splitPane.setLeftComponent(leftPanel);
splitPane.setRightComponent(rightPanel);
// leftPanel | rightPanel
addLiveTracking(txtName.getDocument(), ()-> updatePreview(txtName, txtEmail, txtPhone, txtSkills, txtPreview) );
addLiveTracking(txtEmail.getDocument(), ()-> updatePreview(txtName, txtEmail, txtPhone, txtSkills, txtPreview) );
addLiveTracking(txtPhone.getDocument(), ()-> updatePreview(txtName, txtEmail, txtPhone, txtSkills, txtPreview) );
addLiveTracking(txtSkills.getDocument(), ()-> updatePreview(txtName, txtEmail, txtPhone, txtSkills, txtPreview) );
window.add(splitPane);
window.setVisible(true);
}
private static void updatePreview (JTextField name, JTextField email, JTextField phone, JTextField skills, JTextArea preview) {
String text = " RESUME PREVIEW " + "\n" +
"Name: " + name.getText() + "\n" +
"Email: " + email.getText() + "\n" +
"Name: " + phone.getText() + "\n" +
"Email: " + skills.getText();
preview.setText(text);
}
private static void addLiveTracking (javax.swing.text.Document doc, Runnable action ){
doc.addDocumentListener(new javax.swing.event.DocumentListener() {
public void insertUpdate (javax.swing.event.DocumentEvent event){ action.run(); };
public void removeUpdate (javax.swing.event.DocumentEvent event){action.run();};
public void changedUpdate (javax.swing.event.DocumentEvent event){action.run();};
});
}
}
¶
package org.example;
import javax.swing.*;
import java.awt.*;
public class ResumeBuilderUI {
public static void main(String[] args) {
JFrame window = new JFrame("MY CV Builder");
window.setSize(800, 500);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setDividerLocation(400);
// left panel
JPanel leftPanel = new JPanel(new GridLayout(5, 2, 10, 10)); // row, cols, hgap, vgap
leftPanel.setBackground(Color.LIGHT_GRAY);
// FORM
// Name field
JLabel lblName = new JLabel("Full Name");
JTextField txtName = new JTextField();
leftPanel.add(lblName);
leftPanel.add(txtName);
// Email field
JLabel lblEmail = new JLabel("Full Email");
JTextField txtEmail = new JTextField();
leftPanel.add(lblEmail);
leftPanel.add(txtEmail);
// Phone field
JLabel lblPhone = new JLabel("Full Phone");
JTextField txtPhone = new JTextField();
leftPanel.add(lblPhone);
leftPanel.add(txtPhone);
// Skills field
JLabel lblSkills = new JLabel("Full Skills");
JTextField txtSkills = new JTextField();
leftPanel.add(lblSkills);
leftPanel.add(txtSkills);
// for preview
JTextArea txtPreview = new JTextArea();
txtPreview.setEditable(false);
// right panel
JPanel rightPanel = new JPanel();
rightPanel.setBackground(Color.WHITE);
rightPanel.setLayout(new BorderLayout());
rightPanel.add(txtPreview);
// scrolling option for right preview panel
JScrollPane previewScroll = new JScrollPane(txtPreview);
rightPanel.add(previewScroll);
splitPane.setLeftComponent(leftPanel);
splitPane.setRightComponent(rightPanel);
// leftPanel | rightPanel
addLiveTracking(txtName.getDocument(), ()-> updatePreview(txtName, txtEmail, txtPhone, txtSkills, txtPreview) );
addLiveTracking(txtEmail.getDocument(), ()-> updatePreview(txtName, txtEmail, txtPhone, txtSkills, txtPreview) );
addLiveTracking(txtPhone.getDocument(), ()-> updatePreview(txtName, txtEmail, txtPhone, txtSkills, txtPreview) );
addLiveTracking(txtSkills.getDocument(), ()-> updatePreview(txtName, txtEmail, txtPhone, txtSkills, txtPreview) );
window.add(splitPane);
window.setVisible(true);
}
private static void updatePreview (JTextField name, JTextField email, JTextField phone, JTextField skills, JTextArea preview) {
String text = " RESUME PREVIEW " + "\n" +
"Name: " + name.getText() + "\n" +
"Email: " + email.getText() + "\n" +
"Name: " + phone.getText() + "\n" +
"Email: " + skills.getText();
preview.setText(text);
}
private static void addLiveTracking (javax.swing.text.Document doc, Runnable action ){
doc.addDocumentListener(new javax.swing.event.DocumentListener() {
public void insertUpdate (javax.swing.event.DocumentEvent event){ action.run(); };
public void removeUpdate (javax.swing.event.DocumentEvent event){action.run();};
public void changedUpdate (javax.swing.event.DocumentEvent event){action.run();};
});
}
}
07 Save ResumeData as JSON¶
ResumeData āĻāϰ code:
package org.example;
public class ResumeData {
private String name;
private String email;
private String phone;
private String skills;
public ResumeData() {
}
public ResumeData(String name, String email, String phone, String skills) {
this.name = name;
this.email = email;
this.phone = phone;
this.skills = skills;
}
// Getters and Setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getSkills() {
return skills;
}
public void setSkills(String skills) {
this.skills = skills;
}
}
ResumeBuilderUI āĻāϰ code:
package org.example;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.swing.*;
import java.awt.*;
import java.io.File;
public class ResumeBuilderUI {
public static void main(String[] args) {
// same code
}
private static void updatePreview(JTextField name, JTextField email, JTextField phone, JTextField skills, JTextArea preview) {
String text = " RESUME PREVIEW " + "\n" +
"Name: " + name.getText() + "\n" +
"Email: " + email.getText() + "\n" +
"Name: " + phone.getText() + "\n" +
"Email: " + skills.getText();
preview.setText(text);
saveToJson(name.getText(), email.getText(), phone.getText(), skills.getText());
}
private static void addLiveTracking(javax.swing.text.Document doc, Runnable action) {
// same code
}
private static void saveToJson(String name, String email, String phone, String skills){
try {
ResumeData data = new ResumeData(name, email, phone, skills);
ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(new File("Resume_backup.json"), data);
}
catch (Exception e){
e.printStackTrace(); // console a print korbe
}
}
}
08 Export to PDF Functionality¶
// for pdf export
//import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileOutputStream;
import javax.swing.JOptionPane;
public class ResumeBuilderUI {
public static void main(String[] args) {
/* other codes as before */
// Export PDF button
JButton btnExport = new JButton("Export to PDF");
rightPanel.add(btnExport, BorderLayout.SOUTH);
btnExport.setFocusPainted(false);
btnExport.addActionListener(e -> {
exportToPDF(txtName.getText(), txtEmail.getText(), txtPhone.getText(), txtSkills.getText());
});
// === footer ===
window.add(splitPane);
window.setVisible(true);
}
// other methods
private static void exportToPDF(String name, String email, String phone, String skills){
com.itextpdf.text.Document document = new com.itextpdf.text.Document();
try {
PdfWriter.getInstance(document, new FileOutputStream("My_Resume.pdf"));
document.open();
document.add(new Paragraph(" ==== RESUME ===="));
document.add(new Paragraph(" ==== \n ===="));
document.add(new Paragraph("Name: " + name));
document.add(new Paragraph("Email: " + email ));
document.add(new Paragraph("Phone: " + phone));
document.add(new Paragraph("Skills: " + skills));
document.close();
JOptionPane.showMessageDialog(null, "PDF Exported Successfully!");
}
catch (Exception e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Error creating PDF: " + e.getMessage());
}
}
}
¶
// for pdf export
//import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileOutputStream;
import javax.swing.JOptionPane;
public class ResumeBuilderUI {
public static void main(String[] args) {
/* other codes as before */
// Export PDF button
JButton btnExport = new JButton("Export to PDF");
rightPanel.add(btnExport, BorderLayout.SOUTH);
btnExport.setFocusPainted(false);
btnExport.addActionListener(e -> {
exportToPDF(txtName.getText(), txtEmail.getText(), txtPhone.getText(), txtSkills.getText());
});
// === footer ===
window.add(splitPane);
window.setVisible(true);
}
// other methods
private static void exportToPDF(String name, String email, String phone, String skills){
com.itextpdf.text.Document document = new com.itextpdf.text.Document();
try {
PdfWriter.getInstance(document, new FileOutputStream("My_Resume.pdf"));
document.open();
document.add(new Paragraph(" ==== RESUME ===="));
document.add(new Paragraph(" ==== \n ===="));
document.add(new Paragraph("Name: " + name));
document.add(new Paragraph("Email: " + email ));
document.add(new Paragraph("Phone: " + phone));
document.add(new Paragraph("Skills: " + skills));
document.close();
JOptionPane.showMessageDialog(null, "PDF Exported Successfully!");
}
catch (Exception e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Error creating PDF: " + e.getMessage());
}
}
}
09 Start Moderning UI and PDF - Part 1¶
/* same code */
// FlatLaf
import com.formdev.flatlaf.FlatLightLaf;
public class ResumeBuilderUI {
public static void main(String[] args) {
// FLATLAF
try {
com.formdev.flatlaf.FlatLightLaf.setup();
} catch (Exception e) {
System.err.println("Failed to initialize LaF");
}
JFrame window = new JFrame("MY CV Builder");
// same code
// FORM
/* same code */
// right panel
JPanel rightPanel = new JPanel();
rightPanel.setBackground(Color.WHITE);
rightPanel.setLayout(new BorderLayout());
rightPanel.add(txtPreview);
// scrolling option for right preview panel
JScrollPane previewScroll = new JScrollPane(txtPreview);
rightPanel.add(previewScroll);
splitPane.setLeftComponent(leftPanel);
splitPane.setRightComponent(rightPanel);
// leftPanel | rightPanel
// same code
// Export PDF button
JButton btnExport = new JButton("Export to PDF");
rightPanel.add(btnExport, BorderLayout.SOUTH);
btnExport.setFocusPainted(false);
btnExport.addActionListener(e -> {
exportToPDF(txtName.getText(), txtEmail.getText(), txtPhone.getText(), txtSkills.getText());
});
// === footer ===
window.add(splitPane);
window.setVisible(true);
}
private static void updatePreview(JTextField name, JTextField email, JTextField phone, JTextField skills, JTextArea preview) {
// same code
}
private static void addLiveTracking(javax.swing.text.Document doc, Runnable action) {
// same code
}
private static void saveToJson(String name, String email, String phone, String skills){
try {
ResumeData data = new ResumeData(name, email, phone, skills);
ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(new File("Resume_backup.json"), data);
}
catch (Exception e){
e.printStackTrace(); // console a print korbe
}
}
private static void exportToPDF(String name, String email, String phone, String skills){
com.itextpdf.text.Document document = new com.itextpdf.text.Document();
try {
BaseColor primaryColor = new BaseColor(30, 58, 138);
Font titleFont = new Font(Font.FontFamily.HELVETICA, 24, Font.BOLD, primaryColor);
Font normalFont = new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL, BaseColor.DARK_GRAY);
PdfWriter.getInstance(document, new FileOutputStream("My_Resume.pdf"));
document.open();
document.add(new Paragraph("RESUME", titleFont));
// same code
document.close();
JOptionPane.showMessageDialog(null, "PDF Exported Successfully!");
}
catch (Exception e){
// same code
}
}
}
¶
/* same code */
// FlatLaf
import com.formdev.flatlaf.FlatLightLaf;
public class ResumeBuilderUI {
public static void main(String[] args) {
// FLATLAF
try {
com.formdev.flatlaf.FlatLightLaf.setup();
} catch (Exception e) {
System.err.println("Failed to initialize LaF");
}
JFrame window = new JFrame("MY CV Builder");
// same code
// FORM
/* same code */
// right panel
JPanel rightPanel = new JPanel();
rightPanel.setBackground(Color.WHITE);
rightPanel.setLayout(new BorderLayout());
rightPanel.add(txtPreview);
// scrolling option for right preview panel
JScrollPane previewScroll = new JScrollPane(txtPreview);
rightPanel.add(previewScroll);
splitPane.setLeftComponent(leftPanel);
splitPane.setRightComponent(rightPanel);
// leftPanel | rightPanel
// same code
// Export PDF button
JButton btnExport = new JButton("Export to PDF");
rightPanel.add(btnExport, BorderLayout.SOUTH);
btnExport.setFocusPainted(false);
btnExport.addActionListener(e -> {
exportToPDF(txtName.getText(), txtEmail.getText(), txtPhone.getText(), txtSkills.getText());
});
// === footer ===
window.add(splitPane);
window.setVisible(true);
}
private static void updatePreview(JTextField name, JTextField email, JTextField phone, JTextField skills, JTextArea preview) {
// same code
}
private static void addLiveTracking(javax.swing.text.Document doc, Runnable action) {
// same code
}
private static void saveToJson(String name, String email, String phone, String skills){
try {
ResumeData data = new ResumeData(name, email, phone, skills);
ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(new File("Resume_backup.json"), data);
}
catch (Exception e){
e.printStackTrace(); // console a print korbe
}
}
private static void exportToPDF(String name, String email, String phone, String skills){
com.itextpdf.text.Document document = new com.itextpdf.text.Document();
try {
BaseColor primaryColor = new BaseColor(30, 58, 138);
Font titleFont = new Font(Font.FontFamily.HELVETICA, 24, Font.BOLD, primaryColor);
Font normalFont = new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL, BaseColor.DARK_GRAY);
PdfWriter.getInstance(document, new FileOutputStream("My_Resume.pdf"));
document.open();
document.add(new Paragraph("RESUME", titleFont));
// same code
document.close();
JOptionPane.showMessageDialog(null, "PDF Exported Successfully!");
}
catch (Exception e){
// same code
}
}
}