Assignment 2
Assignment 2
Swing is called platform-independent because it is part of the Java Foundation Classes (JFC), which
are designed to provide a consistent user interface across different operating systems. Here are the
key reasons why Swing is platform-independent
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
JTextField usernameField;
JPasswordField passwordField;
JLabel messageLabel;
setLayout(new FlowLayout());
add(new JLabel("Username:"));
usernameField = new JTextField(15);
add(usernameField);
add(new JLabel("Password:"));
add(passwordField);
loginButton.addActionListener(this);
add(loginButton);
add(messageLabel);
messageLabel.setText("Login successful!");
} else {
messageLabel.setText("Invalid credentials!");
import javax.swing.*;
getContentPane().add(jtp);
public LangPanel()
add(b1);
add(b2);
add(b3);
add(b4);
{
public ColorsPanel()
add(cb1);
add(cb2);
add(cb3);
public FlavorsPanel()
jcb.addItem("Vanilla");
jcb.addItem("Chocolate");
jcb.addItem("Strawberry");
add(jcb);
Swing API architecture follows MVC architecture. The MVC design pattern consists of three modules:
model, view and controller. Model -The model represents the state (data) and business logic of the
application. View -The view module is responsible to display data i.e. it represents the presentation
Controller -The controller module acts as an interface between view and model. It intercepts all the
requests i.e. receives input and commands to Model / View to change accordingly