diff --git a/part-1/.idea/.gitignore b/part-1/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/part-1/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/part-1/.idea/misc.xml b/part-1/.idea/misc.xml new file mode 100644 index 0000000..f03c948 --- /dev/null +++ b/part-1/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/part-1/.idea/modules.xml b/part-1/.idea/modules.xml new file mode 100644 index 0000000..ddf6c41 --- /dev/null +++ b/part-1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/part-1/.idea/part-1.iml b/part-1/.idea/part-1.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/part-1/.idea/part-1.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/part-1/.idea/vcs.xml b/part-1/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/part-1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/part-1/Main.java b/part-1/Main.java new file mode 100644 index 0000000..bd9151e --- /dev/null +++ b/part-1/Main.java @@ -0,0 +1,23 @@ +import javax.swing.*; +import java.awt.*; + +public class Main { + public static void main(String[] args) { + JFrame frame = new JFrame("Click Counter"); + JLabel label = new JLabel("Clicks: 0"); + label.setHorizontalAlignment(SwingConstants.CENTER); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(300, 100); + frame.setLayout(new BorderLayout()); + frame.setResizable(false); + JButton button = new JButton("Click Me"); + frame.add(button, BorderLayout.SOUTH); + frame.add(label, BorderLayout.CENTER); + frame.setVisible(true); + final int[] count = {0}; + button.addActionListener( e-> { + count[0]++; + label.setText("clicks: " + count[0]); + }); + } +} diff --git a/part-1/out/production/part-1/.idea/.gitignore b/part-1/out/production/part-1/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/part-1/out/production/part-1/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/part-1/out/production/part-1/.idea/misc.xml b/part-1/out/production/part-1/.idea/misc.xml new file mode 100644 index 0000000..f03c948 --- /dev/null +++ b/part-1/out/production/part-1/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/part-1/out/production/part-1/.idea/modules.xml b/part-1/out/production/part-1/.idea/modules.xml new file mode 100644 index 0000000..ddf6c41 --- /dev/null +++ b/part-1/out/production/part-1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/part-1/out/production/part-1/.idea/part-1.iml b/part-1/out/production/part-1/.idea/part-1.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/part-1/out/production/part-1/.idea/part-1.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/part-1/out/production/part-1/.idea/vcs.xml b/part-1/out/production/part-1/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/part-1/out/production/part-1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/part-1/out/production/part-1/Main.class b/part-1/out/production/part-1/Main.class new file mode 100644 index 0000000..1cc5d10 Binary files /dev/null and b/part-1/out/production/part-1/Main.class differ diff --git a/part-1/out/production/part-1/images/img-1-1.png b/part-1/out/production/part-1/images/img-1-1.png new file mode 100644 index 0000000..12b529a Binary files /dev/null and b/part-1/out/production/part-1/images/img-1-1.png differ diff --git a/part-1/out/production/part-1/images/img-1-2.png b/part-1/out/production/part-1/images/img-1-2.png new file mode 100644 index 0000000..a78ac9e Binary files /dev/null and b/part-1/out/production/part-1/images/img-1-2.png differ diff --git a/part-1/out/production/part-1/readme-part-1.md b/part-1/out/production/part-1/readme-part-1.md new file mode 100644 index 0000000..f7292df --- /dev/null +++ b/part-1/out/production/part-1/readme-part-1.md @@ -0,0 +1,67 @@ +## Exercise 1: Click Counter Application + +### Description & Goal + +Create a simple GUI application that tracks how many times a user clicks a button and displays the count in real time. This exercise reinforces the basics of Swing components and event handling. + +### Code Breakdown + +**Part 1: Field Declarations** +Define the UI components and a counter variable. + +```java +public class ClickCounterApp extends JFrame implements ActionListener { + private JLabel counterLabel; // Displays the click count + private JButton clickButton; // Button to register clicks + private int count = 0; // Stores the current count +} +``` + +*Explanation:* We declare a `JLabel` for showing the count, a `JButton` for clicks, and an integer `count` initialized to 0. + +**Part 2: Constructor Setup** +Initialize and arrange components in the window. + +```java +public ClickCounterApp() { + setTitle("Click Counter"); + counterLabel = new JLabel("Clicks: 0", SwingConstants.CENTER); + clickButton = new JButton("Click Me"); + clickButton.addActionListener(this); + + setLayout(new BorderLayout()); + add(counterLabel, BorderLayout.CENTER); + add(clickButton, BorderLayout.SOUTH); +} +``` + +*Explanation:* In the constructor we set the title, create the label and button, attach an `ActionListener` to the button, choose a `BorderLayout`, and place the label at center and button at bottom. + +**Part 3: Event Handling** +Update count and label text when the button is clicked. + +```java +@Override +public void actionPerformed(ActionEvent e) { + count++; // Increment the click counter + counterLabel.setText("Clicks: " + count); +} +``` + +*Explanation:* The `actionPerformed` method is called on each click. We increase `count` by one and refresh the label text to reflect the new value. + +**Part 4: Application Entry Point** +Launch the GUI on the Event Dispatch Thread. + +```java +public static void main(String[] args) { + SwingUtilities.invokeLater(() -> new ClickCounterApp().setVisible(true)); +} +``` + +*Explanation:* Using `SwingUtilities.invokeLater` ensures thread safety by creating and showing the GUI on the Swing event thread. +--- +### output of the code: + +... +... diff --git a/part-2/.idea/misc.xml b/part-2/.idea/misc.xml new file mode 100644 index 0000000..f03c948 --- /dev/null +++ b/part-2/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/part-2/.idea/modules.xml b/part-2/.idea/modules.xml new file mode 100644 index 0000000..84a3089 --- /dev/null +++ b/part-2/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/part-2/.idea/part-2.iml b/part-2/.idea/part-2.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/part-2/.idea/part-2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/part-2/.idea/vcs.xml b/part-2/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/part-2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/part-2/.idea/workspace.xml b/part-2/.idea/workspace.xml new file mode 100644 index 0000000..20d5b96 --- /dev/null +++ b/part-2/.idea/workspace.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1746907819053 + + + + + + + + + + \ No newline at end of file diff --git a/part-2/Main.java b/part-2/Main.java new file mode 100644 index 0000000..ab85ed1 --- /dev/null +++ b/part-2/Main.java @@ -0,0 +1,38 @@ +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class Main { + public static void main(String[] args) { + + JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(400, 200); + frame.setLayout(null); + + + JLabel label = new JLabel("Enter your name and press greet"); + label.setBounds(100, 100, 200, 50); + frame.add(label); + + JLabel label2 = new JLabel("Name :"); + label2.setBounds(50, 50, 100, 50); + frame.add(label2); + + JTextField textField = new JTextField(); + textField.setBounds(100, 50, 100, 50); + textField.setOpaque(true); + frame.add(textField); + + JButton button = new JButton("Greet"); + button.setBounds(200, 50, 80, 40); + frame.add(button); + frame.setVisible(true); + button.addActionListener(e -> { + String name = textField.getText(); + label.setText("Hello "+name); + }); + + + } +} diff --git a/part-3/.idea/misc.xml b/part-3/.idea/misc.xml new file mode 100644 index 0000000..f03c948 --- /dev/null +++ b/part-3/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/part-3/.idea/modules.xml b/part-3/.idea/modules.xml new file mode 100644 index 0000000..865bd60 --- /dev/null +++ b/part-3/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/part-3/.idea/vcs.xml b/part-3/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/part-3/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/part-3/.idea/workspace.xml b/part-3/.idea/workspace.xml new file mode 100644 index 0000000..1df5a1a --- /dev/null +++ b/part-3/.idea/workspace.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1746907936619 + + + + + + + + + + \ No newline at end of file diff --git a/part-3/Main.java b/part-3/Main.java new file mode 100644 index 0000000..ca5faba --- /dev/null +++ b/part-3/Main.java @@ -0,0 +1,35 @@ +import javax.swing.*; +import java.awt.*; + +public class Main { + public static void main(String[] args) { + JFrame frame = new JFrame("Theme color selector"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(800, 400); + frame.setLayout(new BorderLayout()); + JPanel panel1 = new JPanel(); + panel1.setPreferredSize(new Dimension(800, 100)); + panel1.setBackground(Color.GRAY); + frame.add(panel1, BorderLayout.NORTH); + JPanel panel2 = new JPanel(); + frame.add(panel2, BorderLayout.CENTER); + JButton button1 = new JButton("Red"); + JButton button2 = new JButton("Green"); + JButton button3 = new JButton("Blue"); + panel1.add(button1); + panel1.add(button2); + panel1.add(button3); + frame.setVisible(true); + + button1.addActionListener(e-> { + panel2.setBackground(Color.RED); + }); + button2.addActionListener(e-> { + panel2.setBackground(Color.GREEN); + }); + button3.addActionListener(e-> { + panel2.setBackground(Color.BLUE); + }); + + } +} diff --git a/part-4/.idea/.gitignore b/part-4/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/part-4/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/part-4/.idea/misc.xml b/part-4/.idea/misc.xml new file mode 100644 index 0000000..f03c948 --- /dev/null +++ b/part-4/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/part-4/.idea/modules.xml b/part-4/.idea/modules.xml new file mode 100644 index 0000000..994917e --- /dev/null +++ b/part-4/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/part-4/.idea/vcs.xml b/part-4/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/part-4/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/part-4/Main.java b/part-4/Main.java new file mode 100644 index 0000000..2a908d1 --- /dev/null +++ b/part-4/Main.java @@ -0,0 +1,113 @@ +import javax.swing.*; +import java.awt.*; + +public class Main { + public static void main(String[] args) { + + JFrame frame = new JFrame("User Registration"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(500, 500); + frame.setLayout(new GridBagLayout()); + JPanel panel = new JPanel(); + panel.setLayout(new GridBagLayout()); + panel.setPreferredSize(new Dimension(300, 300)); + panel.setBackground(Color.GRAY); + + GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = new Insets(5, 5, 5, 5); + gbc.gridx = 0; + gbc.gridy = 0; + JLabel label1 = new JLabel("Name:"); + panel.add(label1, gbc); + gbc.gridx = 1; + final JTextField textField1 = new JTextField(20); + panel.add(textField1, gbc); + + gbc.gridx =0; + gbc.gridy = 1; + JLabel label2 = new JLabel("Email:"); + panel.add(label2, gbc); + gbc.gridx = 1; + final JTextField textField2 = new JTextField(20); + panel.add(textField2, gbc); + + gbc.gridx = 0; + gbc.gridy = 2; + JLabel label3 = new JLabel("Password:"); + panel.add(label3, gbc); + + gbc.gridx = 1; + JPasswordField textField3 = new JPasswordField(20); + panel.add(textField3, gbc); + + gbc.gridx = 0; + gbc.gridy = 3; + JLabel label4 = new JLabel("Gender:"); + panel.add(label4, gbc); + JRadioButton radioButton1 = new JRadioButton("Male"); + JRadioButton radioButton2 = new JRadioButton("Female"); + JPanel radioPanel = new JPanel(); + radioPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 0)); // Adds horizontal spacing + radioPanel.add(radioButton1); + radioPanel.add(radioButton2); + gbc.gridx = 1; + gbc.gridy = 3; + panel.add(radioPanel, gbc); + + gbc.gridx = 0; + gbc.gridy = 4; + JLabel label5 = new JLabel("Interests:"); + panel.add(label5, gbc); + + JCheckBox checkBox1 = new JCheckBox("Java"); + JCheckBox checkBox2 = new JCheckBox("Python"); + JCheckBox checkBox3 = new JCheckBox("C++"); + + JPanel checkPanel = new JPanel(); + checkPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 0)); + + checkPanel.add(checkBox1); + checkPanel.add(checkBox2); + checkPanel.add(checkBox3); + gbc.gridx = 1; + gbc.gridy = 4; + panel.add(checkPanel, gbc); + + JButton button1 = new JButton("Submit"); + gbc.gridx = 1; + gbc.gridy = 5; + panel.add(button1, gbc); + frame.add(panel); + frame.setVisible(true); + + + button1.addActionListener(e->{ + + String gender = ""; + if(radioButton1.isSelected()){ + gender = "Male"; + } + else if (radioButton2.isSelected()){ + gender = "Female"; + } + String interests = ""; + if(checkBox1.isSelected()){ + interests = "Java"; + } + else if (checkBox2.isSelected()){ + interests = "Python"; + } + else if (checkBox3.isSelected()){ + interests = "C++"; + } + + + String fullInformation = "Name : " + textField1.getText() + "\nEmail : " + textField2.getText() + + "\n Gender: " + gender + "\n Interests : " + interests; + + + JOptionPane.showMessageDialog(frame, fullInformation, "Registration Details", JOptionPane.INFORMATION_MESSAGE); + + }); + } +}