Skip to content
Open

done #18

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
29 changes: 29 additions & 0 deletions part-1/ClickCounter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import javax.swing.*;
import java.awt.*;

public class ClickCounter {
private int count =0;
private JButton ClickButton;
private JLabel countClick;
public ClickCounter() {
JFrame frame = new JFrame("Click Counter");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,200);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
// frame.setLayout(null);
ClickButton = new JButton("Click");
// ClickButton.setBounds(0,113,300,50);
countClick = new JLabel("Clicks: "+count,JLabel.CENTER);
ClickButton.addActionListener(e -> {
count++;
countClick.setText("Clicks: "+count);
});

frame.add(ClickButton,BorderLayout.SOUTH);
frame.add(countClick,BorderLayout.CENTER);
frame.setVisible(true);
}

}
Empty file removed part-1/E1.java
Empty file.
7 changes: 7 additions & 0 deletions part-1/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import javax.swing.*;

public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater (()->new ClickCounter());
}
}
Empty file removed part-2/E2.java
Empty file.
37 changes: 37 additions & 0 deletions part-2/GreetingFormApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import javax.swing.*;
import java.awt.*;

public class GreetingFormApp {
private JLabel lblGreeting;
private JButton btnGreet;
private final JTextField txtGreeting;

public GreetingFormApp() {
JFrame frame = new JFrame("Greeting");
frame.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setSize(300, 150);
txtGreeting = new JTextField( 20);
JLabel lblGreeting = new JLabel("welcome to my application", SwingConstants.CENTER);
JButton btnGreet = new JButton("Greet");
btnGreet.addActionListener(e -> {
String greeting = txtGreeting.getText();
if ( greeting.isEmpty()) {
JOptionPane.showMessageDialog(null, "please enter your name");

} else {
lblGreeting.setText("Hello, " + greeting + "!");
}

});
JPanel panel = new JPanel();
panel.add(txtGreeting);
panel.add(btnGreet);
frame.add(panel, BorderLayout.NORTH);
frame.add(lblGreeting, BorderLayout.CENTER);
frame.setVisible(true);


}
}
7 changes: 7 additions & 0 deletions part-2/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import javax.swing.*;

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

public class ThemeColorSelectorApp extends JFrame implements ActionListener {
private JFrame frame;
private JPanel Colorpanel;
private JButton RedButton;
private JButton GreenButton;
private JButton BlueButton;

public ThemeColorSelectorApp(){
frame = new JFrame("ThemeColorSelectorApp");
setLayout(new BorderLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
Colorpanel = new JPanel();
RedButton = new JButton("Red");
GreenButton = new JButton("Green");
BlueButton = new JButton("Blue");
JPanel buttonPanel = new JPanel();
RedButton.setActionCommand("Red");
GreenButton.setActionCommand("Green");
BlueButton.setActionCommand("Blue");
RedButton.addActionListener(this);
GreenButton.addActionListener(this);
buttonPanel.add(RedButton);
buttonPanel.add(BlueButton);
buttonPanel.add(GreenButton);
BlueButton.addActionListener(this);
frame.add(Colorpanel,BorderLayout.CENTER);
frame.add(buttonPanel,BorderLayout.NORTH);



frame.setVisible(true);
}


@Override
public void actionPerformed(ActionEvent e) {
switch (e.getActionCommand()){
case "Red": Colorpanel.setBackground(Color.RED);
break;
case "Green": Colorpanel.setBackground(Color.GREEN);
break;
case "Blue": Colorpanel.setBackground(Color.BLUE);
break;
}
}
}
8 changes: 8 additions & 0 deletions part-3/ex1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import javax.swing.*;

public class ex1 {

public static void main(String[] args) {
SwingUtilities.invokeLater(()-> new ThemeColorSelectorApp());
}
}
Empty file removed part-4/E4.java
Empty file.
7 changes: 7 additions & 0 deletions part-4/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import javax.swing.*;

public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(() ->new RegistrationFormApp() );
}
}
106 changes: 106 additions & 0 deletions part-4/RegistrationFormApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
public class RegistrationFormApp extends JFrame implements ActionListener {

private JTextField txtName;
private JTextField txtEmail;
private JPasswordField txtPassword;
private JRadioButton RbMale, RbFemale;
private JCheckBox cbJava, cbPython, cbCpp;
private JButton btnSubmit;
private GridBagConstraints gbc;
public RegistrationFormApp() {
setTitle("Registration Form");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(300, 300);
setLocationRelativeTo(null);
JPanel panel = new JPanel(new GridBagLayout());
gbc = new GridBagConstraints();
gbc.insets = new Insets(5, 5, 5, 5);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 0;
gbc.gridy = 0;
panel.add(new JLabel("Name:"), gbc);
gbc.gridx = 1;
gbc.gridy = 0;
txtName = new JTextField(20);
panel.add(txtName, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
panel.add(new JLabel("Email:"), gbc);
gbc.gridx = 1;
gbc.gridy = 1;
txtEmail = new JTextField(30);
panel.add(txtEmail, gbc);
gbc.gridx = 0;
gbc.gridy = 2;
panel.add(new JLabel("Password:"), gbc);
gbc.gridx = 1;
gbc.gridy = 2;
txtPassword = new JPasswordField(20);
panel.add(txtPassword, gbc);
gbc.gridx = 0;
gbc.gridy = 3;
panel.add(new JLabel("Gender:"), gbc);
gbc.gridx = 1;
gbc.gridy = 3;
RbMale = new JRadioButton("Male");
RbFemale = new JRadioButton("Female");
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(RbMale);
buttonGroup.add(RbFemale);
JPanel GenderPanel = new JPanel();
GenderPanel.add(RbMale);
GenderPanel.add(RbFemale);
panel.add(GenderPanel, gbc);
gbc.gridx = 0;
gbc.gridy = 4;
panel.add(new Label("Interests: "), gbc);
gbc.gridx = 1;
gbc.gridy = 4;
cbJava = new JCheckBox("Java");
cbPython = new JCheckBox("Python");
cbCpp = new JCheckBox("C++");
JPanel InterestPanel = new JPanel();
InterestPanel.add(cbJava);
InterestPanel.add(cbPython);
InterestPanel.add(cbCpp);
panel.add(InterestPanel, gbc);
gbc.gridx = 1;
gbc.gridy = 5;
gbc.anchor = GridBagConstraints.CENTER;
btnSubmit = new JButton("Submit");
btnSubmit.addActionListener(this);
panel.add(btnSubmit, gbc);
add(panel, BorderLayout.CENTER);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
String name = txtName.getText();
String email = txtEmail.getText();
String Gender = RbMale.isSelected() ? "Male" : "Female";
String interests = setInterests();
JOptionPane.showMessageDialog(this, "Name: " + name + "\n" +
"Email: " + email + "\n" +
"Gender: " + Gender + "\n" +
"Interests: " + interests, "Registration Form", JOptionPane.INFORMATION_MESSAGE);


}
public String setInterests() {
String result = "";
if (cbJava.isSelected()) {
result += "Java ";
}
if (cbPython.isSelected()) {
result += "Python ";
}
if (cbCpp.isSelected()) {
result += "C++ ";
}
return result;
}
}