Week 9 Assignment App
Week 9 Assignment App
PROGRAMMING
PRACTICE
ASSIGNMENT-9
RA2211026010486
G.Abiram cse-Aiml
Programs:
GRAPHICAL USER INTERFACE BASED PROGRAMMING
PARADIGM
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLO
SE);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,
"Button Clicked!");
}
});
frame.add(button);
frame.setSize(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLO
SE);
frame.setVisible(true);
}
}
Ans:
import javax.swing.*;
openItem.addActionListener(e ->
JOptionPane.showMessageDialog(null, "Open
clicked"));
saveItem.addActionListener(e ->
JOptionPane.showMessageDialog(null, "Save
clicked"));
fileMenu.add(openItem);
fileMenu.add(saveItem);
menuBar.add(fileMenu);
frame.setJMenuBar(menuBar);
frame.setSize(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLO
SE);
frame.setVisible(true);
}
}
Ans:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class StudentRegistrationForm {
public static void main(String[] args) {
JFrame frame = new JFrame("Student Registration
Form");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLO
SE);
frame.setSize(400, 300);
panel.add(nameLabel);
panel.add(nameField);
panel.add(rollNumberLabel);
panel.add(rollNumberField);
panel.add(submitButton);
frame.add(panel);
frame.setVisible(true);
}
}
Ans:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
submitButton.addActionListener(new
ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = nameField.getText();
String age = ageField.getText();
String position = positionField.getText();
JOptionPane.showMessageDialog(frame,
"Name: " + name + "\nAge: " + age + "\nPosition: " +
position);
}
});
panel.add(nameLabel);
panel.add(nameField);
panel.add(ageLabel);
panel.add(ageField);
panel.add(positionLabel);
panel.add(positionField);
panel.add(submitButton);
frame.add(panel);
frame.setVisible(true);
}
}
Ans:
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
if ((row + col) % 2 == 0) {
g.setColor(Color.white);
} else {
g.setColor(Color.black);
}
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
Ans:
public class MVCEmployeeDetails {
public static void main(String[] args) {
// Create the Model, View, and Controller
EmployeeModel model = new EmployeeModel();
EmployeeView view = new EmployeeView();
EmployeeController controller = new
EmployeeController(model, view);
class EmployeeModel {
private String name;
private int employeeId;
private String department;
public String getName() {
return name;
}
class EmployeeView {
public void printEmployeeDetails(String name, int
employeeId, String department) {
System.out.println("Employee Details:");
System.out.println("Name: " + name);
System.out.println("Employee ID: " + employeeId);
System.out.println("Department: " + department);
}
}
class EmployeeController {
private EmployeeModel model;
private EmployeeView view;