Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions part-1/ClickCounterApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ClickCounterApp extends JFrame {
private int clickCount = 0;
private JLabel label;

public ClickCounterApp() {

setTitle("Click Counter");
setSize(300, 150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null); // مرکز صفحه

label = new JLabel("Clicks: 0", SwingConstants.CENTER);
label.setFont(new Font("Arial", Font.BOLD, 18));
JButton button = new JButton("Click Me");
button.setFont(new Font("Arial", Font.BOLD, 16));

button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
clickCount++;
label.setText("Clicks: " + clickCount);
}
});

setLayout(new BorderLayout());
add(label, BorderLayout.CENTER);
add(button, BorderLayout.SOUTH);
}

public static void main(String[] args) {

SwingUtilities.invokeLater(() -> {
ClickCounterApp frame = new ClickCounterApp();
frame.setVisible(true);
});
}
}
Empty file removed part-1/E1.java
Empty file.
Empty file removed part-2/E2.java
Empty file.
56 changes: 56 additions & 0 deletions part-2/GreetingFormApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class GreetingFormApp extends JFrame {

private JLabel massage;
private JTextField nameField;

public GreetingFormApp() {
setTitle("Greeting Form");
setSize(300,150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);

JLabel nameLabel = new JLabel("Name: ");
nameLabel.setFont(new Font("Arial",Font.BOLD,14));

nameField = new JTextField(15);
JButton greetingButton = new JButton("Greet");
greetingButton.setFont(new Font("Arial",Font.BOLD,14));

massage = new JLabel("Enter your name and press greet", SwingConstants.CENTER);
massage.setFont(new Font("Arial",Font.BOLD,14));

greetingButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String name = nameField.getText().trim();

if (!name.isEmpty())
massage.setText("Hello " + name + "!");
else
massage.setText("Please Enter your name");
}
});

JPanel panel = new JPanel();
panel.add(nameLabel);
panel.add(nameField);
panel.add(greetingButton);

setLayout(new BorderLayout());
add(panel,BorderLayout.NORTH);
add(massage,BorderLayout.CENTER);

}

public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
GreetingFormApp frame = new GreetingFormApp();
frame.setVisible(true);
});
}
}
Empty file removed part-3/E3.java
Empty file.
58 changes: 58 additions & 0 deletions part-3/ThemeColorSelectorApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ThemeColorSelectorApp extends JFrame {

public ThemeColorSelectorApp() {
setTitle("THeme Color Selector");
setSize(600,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);

JButton redButton = new JButton("Red");
JButton blueButton = new JButton("Blue");
JButton greenButton = new JButton("Green");

JPanel colorButtonPanel = new JPanel();
colorButtonPanel.add(redButton);
colorButtonPanel.add(blueButton);
colorButtonPanel.add(greenButton);

JPanel colorPanel = new JPanel();
colorPanel.setBackground(Color.WHITE);

setLayout(new BorderLayout());
add(colorButtonPanel, BorderLayout.NORTH);
add(colorPanel, BorderLayout.CENTER);

redButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
colorPanel.setBackground(Color.RED);
}
});

blueButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
colorPanel.setBackground(Color.BLUE);
}
});

greenButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
colorPanel.setBackground(Color.GREEN);
}
});
}

public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
ThemeColorSelectorApp frame = new ThemeColorSelectorApp();
frame.setVisible(true);
});
}
}
Empty file removed part-4/E4.java
Empty file.
107 changes: 107 additions & 0 deletions part-4/RegistrationFormApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class RegistrationFormApp extends JFrame {

private JTextField nameField, emailField;
private JPasswordField passwordField;
private JRadioButton maleButton, femaleButton;
private JCheckBox javaBox, pythonBox, cppBox;

public RegistrationFormApp() {
setTitle("User Registration");
setSize(400, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);

JLabel nameLabel = new JLabel("Name:");
JLabel emailLabel = new JLabel("Email:");
JLabel passwordLabel = new JLabel("Password:");
JLabel genderLabel = new JLabel("Gender:");
JLabel interestsLabel = new JLabel("Interests:");

nameField = new JTextField(15);
emailField = new JTextField(15);
passwordField = new JPasswordField(15);

maleButton = new JRadioButton("Male");
femaleButton = new JRadioButton("Female");
ButtonGroup genderGroup = new ButtonGroup();
genderGroup.add(maleButton);
genderGroup.add(femaleButton);

javaBox = new JCheckBox("Java");
pythonBox = new JCheckBox("Python");
cppBox = new JCheckBox("C++");

JButton submitButton = new JButton("Submit");

setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(5,5,5,5);
gbc.anchor = GridBagConstraints.WEST;

gbc.gridx = 0; gbc.gridy = 0;
add(nameLabel, gbc);
gbc.gridx = 1;
add(nameField, gbc);

gbc.gridx = 0; gbc.gridy = 1;
add(emailLabel, gbc);
gbc.gridx = 1;
add(emailField, gbc);

gbc.gridx = 0; gbc.gridy = 2;
add(passwordLabel, gbc);
gbc.gridx = 1;
add(passwordField, gbc);

gbc.gridx = 0; gbc.gridy = 3;
add(genderLabel, gbc);
gbc.gridx = 1;
add(maleButton, gbc);
gbc.gridx = 2;
add(femaleButton, gbc);

gbc.gridx = 0; gbc.gridy = 4;
add(interestsLabel, gbc);
gbc.gridx = 1;
add(javaBox, gbc);
gbc.gridx = 2;
add(pythonBox, gbc);
gbc.gridx = 3;
add(cppBox, gbc);

gbc.gridx = 1; gbc.gridy = 5; gbc.gridwidth = 2;
gbc.anchor = GridBagConstraints.CENTER;
add(submitButton, gbc);

submitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = nameField.getText();
String email = emailField.getText();
String gender = maleButton.isSelected() ? "Male" : (femaleButton.isSelected() ? "Female" : "Unspecified");

StringBuilder interests = new StringBuilder();
if (javaBox.isSelected()) interests.append("Java ");
if (pythonBox.isSelected()) interests.append("Python ");
if (cppBox.isSelected()) interests.append("C++ ");

String message = String.format(
"Name: %s\nEmail: %s\nGender: %s\nInterests: %s",
name, email, gender, interests.toString().trim()
);

JOptionPane.showMessageDialog(RegistrationFormApp.this, message, "Registration Details", JOptionPane.INFORMATION_MESSAGE);
}
});
}

public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
new RegistrationFormApp().setVisible(true);
});
}
}