0% found this document useful (0 votes)
21 views

Distributed System And Cloud Computing Journal_Abhishek

Uploaded by

Abhi Dhuri
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Distributed System And Cloud Computing Journal_Abhishek

Uploaded by

Abhi Dhuri
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 36

Centre for Distance and Online Education

Vidya Nagari, Kalina, Santacruz East – 400098.

CERTIFICATE

This is to certify that Mr. Abhishek Ashok Dhuri of Master in Computer


Application (MCA) Semester III has completed the specified term work in the
subject of Distributed System and Cloud Computing satisfactorily within this
institute as laid down by University of Mumbai during the academic year 2023 to
2024.

(Prof. Ujwala Sav)


Subject In-charge External Examiner Coordinator – M.C.A
MCA Sem 3 Distributed System and Cloud Computing

“VIDYALANKAR SCHOOL OF INFORMATION TECHNOLOGY, WADALA”


AFFILIATED TO
UNIVERSITY OF MUMBAI
CENTRE FOR DISTANCE AND ONLINE EDUCATION (CDOE)

INDEX
Sr. Page
Title Date Signature
No. No.
WRITE A PROGRAM TO DEVELOP MULTI-CLIENT
SERVER APPLICATION WHERE MULTIPLE
1. 28-Sep-24 1-4
CLIENTS CHAT WITH EACH OTHER
CONCURRENTLY.
TO IMPLEMENT A SERVER CALCULATOR USING
2. 28-Sep-24 5-8
RPC CONCEPT.
WRITE A CLIENT-SERVER PROGRAM WHICH
3. DISPLAYS THE SERVER MACHINE'S DATE AND 06-Oct-24 9-10
TIME ON THE CLIENT MACHINE.
DEMONSTRATE A SAMPLE RMI JAVA
4. 06-Oct-24 11-13
APPLICATION.
BOOK INFORMATION FROM LIBRARY DATABASE
5. USING REMOTE OBJECT COMMUNICATION 06-Oct-24 14-17
CONCEPT.
ELECTRIC BILL DATABASE USING REMOTE
6. 06-Oct-24 18-21
OBJECT COMMUNICATION CONCEPT.
IMPLEMENTATION OF CLOUD COMPUTING
7. 06-Oct-24 22-28
SERVICES.
JAVA PROGRAM TO ILLUSTRATE HOW USER
8. 06-Oct-24 29
AUTHENTICATION IS DONE.
JAVA PROGRAM TO CHECK THE
9. 06-Oct-24 30
AUTHENTICATION OF THE USER.

10. CREATE A LOGIN FORM IN JAVA. 06-Oct-24 31-33

DYNAMICALLY CHANGING THE BACKGROUND


11. 06-Oct-24 34
COLOR OF A WEBPAGE ON EACH CLICK.

Abhishek Dhuri I
MCA Sem 3 Distributed System and Cloud Computing

Practical 1: WRITE A PROGRAM TO DEVELOP MULTI-CLIENT


SERVER APPLICATION WHERE MULTIPLE CLIENTS CHAT
WITH EACH OTHER CONCURRENTLY.

Code:
 MultiThreadedSocketServer.java

import java.net.*;

public class MultiThreadedSocketServer {

public static void main(String[] args) {

try{
ServerSocket server = new ServerSocket(8888);
int counter = 0;
System.out.println("Server started...");
while (true){
counter++;
//SERVER ACCEPT THE CLIENT CONNECTION REQUEST
Socket serverClient = server.accept();
System.out.println(">> Client No.: " + counter + " started!!");
//SEND THE REQUEST TO SEPARATE THREAD
ServerClientThread sct = new ServerClientThread(serverClient, counter);
sct.start();
}
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
}

 ServerClientThread.java

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.Socket;

public class ServerClientThread extends

Thread{ Socket serverClient;


int clientNo;
int square;

Abhishek Dhuri 1
MCA Sem 3 Distributed System and Cloud Computing

ServerClientThread(Socket inSocket, int counter){


serverClient = inSocket;
clientNo = counter;
}

public void run() {

try{
DataInputStream inputStream = new
DataInputStream(serverClient.getInputStream());
DataOutputStream outputStream = new
DataOutputStream(serverClient.getOutputStream());
String clientMsg = "", serverMessage = "";
while(!clientMsg.equals("bye")){
clientMsg = inputStream.readUTF();
System.out.println("From Client: " + clientNo + " : Number is: " + clientMsg);
square = Integer.parseInt(clientMsg) * Integer.parseInt(clientMsg);
serverMessage = "From Server to Client: " + clientNo + " : Square of " +
clientMsg + " is " + square;
outputStream.writeUTF(serverMessage);
outputStream.flush();
}
inputStream.close();
outputStream.close();
serverClient.close();
}
catch (Exception e){
System.out.println(e.getMessage());
}
finally {
System.out.println(">> Client: " + clientNo + " exit!!");
}
}
}

Abhishek Dhuri 2
MCA Sem 3 Distributed System and Cloud Computing

 TCPClient.java

import java.io.*;
import java.net.Socket;

public class TCPClient {

public static void main(String[] args) {

try {
Socket socket = new Socket("127.0.0.1", 8888);
DataInputStream inputStream = new DataInputStream(socket.getInputStream());
DataOutputStream outputStream = new
DataOutputStream(socket.getOutputStream());
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String clientMsg = "";
String serverMsg = "";
while (!clientMsg.equals("bye"))
{ System.out.print("Enter Number: ");
clientMsg = br.readLine();
outputStream.writeUTF(clientMsg);
outputStream.flush();
serverMsg = inputStream.readUTF();
System.out.println(serverMsg);
}
outputStream.close();
outputStream.close();
socket.close();
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
}

Abhishek Dhuri 3
MCA Sem 3 Distributed System and Cloud Computing

Output:

Abhishek Dhuri 4
MCA Sem 3 Distributed System and Cloud Computing

Practical 2: TO IMPLEMENT A SERVER CALCULATOR USING RPC


CONCEPT.

Code:
 RPCServer.java

import java.net.*;
import java.util.StringTokenizer;

public class RPCServer {

DatagramSocket ds;
DatagramPacket dp;
String str, methodName, result;
int val1, val2;

RPCServer() {
try {
ds = new DatagramSocket(1200);
byte b[] = new byte[4096];
while (true) {
dp = new DatagramPacket(b, b.length);
ds.receive(dp);
str = new String(dp.getData(), 0, dp.getLength());
if (str.equalsIgnoreCase("q")) {
System.exit(1);
} else {
StringTokenizer st = new StringTokenizer(str, " ");
int i = 0;
while (st.hasMoreTokens())
{ String token =
st.nextToken(); methodName
= token;
val1 = Integer.parseInt(st.nextToken());
val2 = Integer.parseInt(st.nextToken());
}
}

System.out.println(str);
InetAddress ia = InetAddress.getLocalHost();
if (methodName.equalsIgnoreCase("add")) {
result = "" + add(val1, val2);
} else if (methodName.equalsIgnoreCase("sub")) {
result = "" + sub(val1, val2);
} else if (methodName.equalsIgnoreCase("mul")) {
result = "" + mul(val1, val2);

Abhishek Dhuri 5
MCA Sem 3 Distributed System and Cloud Computing

} else if (methodName.equalsIgnoreCase("div")) {
result = "" + div(val1, val2);
}
byte b1[] = result.getBytes();
DatagramSocket ds1 = new DatagramSocket();
DatagramPacket dp1 = new
DatagramPacket(b1, b1.length, InetAddress.getLocalHost(), 1300);
System.out.println("result : " + result + "\n");
ds1.send(dp1);
}
} catch (Exception e) {
e.printStackTrace();
}
}

public int add(int val1, int val2) {


return val1 + val2;
}

public int sub(int val3, int val4) {


return val3 - val4;
}

public int mul(int val3, int val4) {


return val3 * val4;
}

public int div(int val3, int val4) {


return val3 / val4;
}

public static void main(String[] args) {


new RPCServer();
}
}

 RPCClient.java

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import java.net.*;

public class RPCClient

{ RPCClient() {

Abhishek Dhuri 6
MCA Sem 3 Distributed System and Cloud Computing

try {
InetAddress ia = InetAddress.getLocalHost();
DatagramSocket ds = new DatagramSocket();
DatagramSocket ds1 = new DatagramSocket(1300);
System.out.println("\nRPC Client\n");
System.out.println("Enter method name and parameter like add 3 4");
while (true) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
byte b[] = str.getBytes();
DatagramPacket dp = new
DatagramPacket(b, b.length, ia, 1200);
ds.send(dp);
dp = new DatagramPacket(b, b.length);
ds1.receive(dp);
String s = new String(dp.getData(), 0, dp.getLength()); System.out.println("\
nResult = " + s + "\n");
}
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {


new RPCClient();
}
}

Abhishek Dhuri 7
MCA Sem 3 Distributed System and Cloud Computing

Output:

Abhishek Dhuri 8
MCA Sem 3 Distributed System and Cloud Computing

Practical 3: WRITE A CLIENT-SERVER PROGRAM WHICH DISPLAYS


THE SERVER MACHINE'S DATE AND TIME ON THE CLIENT
MACHINE.

Code:
 DateClient.java

import java.io.*;
import java.net.*;

public class DateClient {


public static void main(String args[]) throws Exception
{
Socket soc=new Socket(InetAddress.getLocalHost(),5217);
BufferedReader in=new BufferedReader(new InputStreamReader(soc.getInputStream()
));
System.out.println(in.readLine());
}
}

 DateServer.java

import java.net.*;
import java.io.*;
import java.util.*;

public class DateServer {


public static void main(String args[]) throws Exception
{
ServerSocket s=new ServerSocket(5217);
while(true)
{
System.out.println("Waiting For Connection ...");
Socket soc=s.accept();
DataOutputStream out=new
DataOutputStream(soc.getOutputStream());
out.writeBytes("Server Date: " + (new Date()).toString() + "\n");
out.close();
soc.close();
}
}

Abhishek Dhuri 9
MCA Sem 3 Distributed System and Cloud Computing

Output:

Abhishek Dhuri 10
MCA Sem 3 Distributed System and Cloud Computing

Practical 4: DEMONSTRATE A SAMPLE RMI JAVA APPLICATION.

Code:
 Hello.java

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Hello extends Remote {


void printMsg() throws RemoteException;
}

 Server.java

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class Server extends ImplExample {

public Server() throws RemoteException {


super();
}

public static void main(String[] args) {


try {
ImplExample obj = new ImplExample();
Registry registry = LocateRegistry.createRegistry(1099);
registry.bind("Hello", obj);
System.err.println("Server ready");
} catch (RemoteException e) {
System.err.println("Server exception: " +
e.toString()); e.printStackTrace();
} catch (Exception e) {
System.err.println("Unexpected exception: " + e.toString());
e.printStackTrace();
}
}
}

Abhishek Dhuri 11
MCA Sem 3 Distributed System and Cloud Computing

 Client.java

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class Client {

private Client() {
}

public static void main(String[] args) {


try {

Registry registry = LocateRegistry.getRegistry("localhost", 1099);


Hello stub = (Hello) registry.lookup("Hello");
stub.printMsg();
System.out.println("Remote method invoked");
} catch (Exception e) {
System.err.println("Client exception: " + e.toString());
e.printStackTrace();
}
}
}

 ImplExample.java

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class ImplExample extends UnicastRemoteObject implements Hello {

public ImplExample() throws RemoteException {


super()
}

@Override
public void printMsg() throws RemoteException
{ System.out.println("This is an example RMI program");
}
}

Abhishek Dhuri 12
MCA Sem 3 Distributed System and Cloud Computing

Output:

Abhishek Dhuri 13
MCA Sem 3 Distributed System and Cloud Computing

Practical 5: BOOK INFORMATION FROM LIBRARY DATABASE USING


REMOTE OBJECT COMMUNICATION CONCEPT.

Code:
 Library.java

import java.io.Serializable;

public class Library implements Serializable {

private int BookID;


private String BookName;
private String
BookAuthor;

public int getBookID() {


return BookID;
}

public void setBookID(int bookID) {


BookID = bookID;
}

public String getBookName() {


return BookName;
}

public void setBookName(String bookName) {


BookName = bookName;
}

public String getBookAuthor() {


return BookAuthor;
}

public void setBookAuthor(String bookAuthor) {


BookAuthor = bookAuthor;
}
}

 Hello.java

import java.rmi.Remote;
import java.util. * ;

public interface Hello extends Remote {

Abhishek Dhuri 14
MCA Sem 3 Distributed System and Cloud Computing

public List < Library > getBookInfo() throws Exception;


}

 ImplExample.java
import java.sql.*;
import java.util.*;

public class ImplExample implements Hello {

@Override
public List<Library> getBookInfo() throws Exception {

List<Library> list = new ArrayList<>();


String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
String DB_URL = "jdbc:mysql://localhost:3306/test";
String USER = "DATABASE_USERNAME";
String PASS = " DATABASE_PASSWORD ";
Connection conn = null;
Statement stmt = null;
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("Connecting to a selected database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Connected database successfully...");
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = "SELECT * FROM books";
ResultSet rs = stmt.executeQuery(sql);

while (rs.next()) {
int id = rs.getInt("Book_id");
String name = rs.getString("Book_name");
String author = rs.getString("Book_author");
Library info = new Library();
info.setBookID(id);
info.setBookName(name);
info.setBookAuthor(author);
list.add(info);
}
rs.close();
return list;
}

Abhishek Dhuri 15
MCA Sem 3 Distributed System and Cloud Computing

 Server.java
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

public class Server extends ImplExample


{ public Server() {
}

public static void main(String args[])


{ try {
ImplExample obj = new ImplExample();
Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
Registry registry = LocateRegistry.createRegistry(6666);
registry.rebind("bookInfo", stub);
System.err.println("Server ready");
}
catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}

 Client.java
import
java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.List;

public class Client


{ private Client()
{
}

public static void main(String[] args) throws Exception


{ try {
Registry registry = LocateRegistry.getRegistry("localhost", 6666);
Hello stub = (Hello) registry.lookup("bookInfo");
List<Library> list = (List) stub.getBookInfo();
for (Library l : list) {
System.out.println("Book ID: " + l.getBookID());
System.out.println("Book Name: " + l.getBookName());
System.out.println("Book Author: " + l.getBookAuthor());
System.out.println(" ");
}

Abhishek Dhuri 16
MCA Sem 3 Distributed System and Cloud Computing

} catch (Exception e) {
System.err.println("Client exception: " + e.toString());
e.printStackTrace();
}
}
}

Output:

Abhishek Dhuri 17
MCA Sem 3 Distributed System and Cloud Computing

Practical 6: ELECTRIC BILL DATABASE USING REMOTE OBJECT


COMMUNICATION CONCEPT.

Code:
 Electric.java
public class Electric implements java.io.Serializable {

private float BillAmount;


private String CustomerName;
private String BillDueDate;

public float getBillAmount() {


return BillAmount;
}

public void setBillAmount(float billAmount) {


BillAmount = billAmount;
}

public String getCustomerName() {


return CustomerName;
}

public void setCustomerName(String customerName) {


CustomerName = customerName;
}

public String getBillDueDate() {


return BillDueDate;
}

public void setBillDueDate(String billDueDate) {


BillDueDate = billDueDate;
}
}

 Hello.java
import java.rmi.Remote;
import java.util.List;

public interface Hello extends Remote {


public List<Electric> getBillInfo() throws Exception;
}

Abhishek Dhuri 18
MCA Sem 3 Distributed System and Cloud Computing

 ImplExample.java
import java.sql.*;
import java.util.*;

public class ImplExample implements Hello {

public List<Electric> getBillInfo() throws Exception


{ List<Electric> list = new ArrayList<Electric>();

String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";


String DB_URL = "jdbc:mysql://localhost:3306/test";

String USER = " DATABASE_USERNAME";


String PASS = " DATABASE_PASSWORD ";

Connection conn = null;


Statement stmt = null;

Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("Connecting to a selected database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Connected database successfully...");

System.out.println("Creating statement...");

stmt = conn.createStatement();
String sql = "SELECT * FROM electricbill";
ResultSet rs = stmt.executeQuery(sql);

while (rs.next()) {
float amount = rs.getFloat("BillAmount");
String name = rs.getString("ConsumerName");
String Date = rs.getString("BillDuedate");
Electric info = new Electric();
info.setBillAmount(amount);
info.setCustomerName(name);
info.setBillDueDate(Date);
list.add(info);
}
rs.close();
return list;
}
}

Abhishek Dhuri 19
MCA Sem 3 Distributed System and Cloud Computing

 Server.java
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

public class Server extends ImplExample {


public Server() {
}

public static void main(String args[]) {


try {
ImplExample obj = new ImplExample();
Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
Registry registry = LocateRegistry.createRegistry(6666);
registry.rebind("billinfo", stub);
System.err.println("Server ready");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}

 Client.java
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.List;

public class Client {


private Client() {
}

public static void main(String[] args) throws Exception {


try {
Registry registry = LocateRegistry.getRegistry("localhost", 6666);
Hello stub = (Hello) registry.lookup("billinfo");
List<Electric> list = (List) stub.getBillInfo();
for (Electric l : list) {

System.out.println("Customer name: " + l.getCustomerName());


System.out.println("Bill Due Date: " + l.getBillDueDate());
System.out.println("Bill Amount: " + l.getBillAmount());
System.out.println(" ");

Abhishek Dhuri 20
MCA Sem 3 Distributed System and Cloud Computing

} catch (Exception e) {
System.err.println("Client exception: " + e.toString());
e.printStackTrace();
}
}
}

Output:

Abhishek Dhuri 21
MCA Sem 3 Distributed System and Cloud Computing

Practical 7: IMPLEMENTATION OF CLOUD COMPUTING SERVICES.

Implementation of cloud computing services:


Infrastructure as a service (IaaS):

 Create a storage account:

A storage account is an Azure Resource Manager resource. Resource Manager is the deployment
and management service for Azure. For more information, see Azure Resource Manager
overview.

https://k21academy.com/microsoft-azure/create-free-microsoft-azure-trial-account/

https://azure.microsoft.com/en-in/free/students/

Abhishek Dhuri 22
MCA Sem 3 Distributed System and Cloud Computing

Click on Start Free.

1. From the left portal menu, select Storage accounts to display a list of your storage
accounts. If the portal menu isn't visible, click the menu button to toggle it on.

Abhishek Dhuri 23
MCA Sem 3 Distributed System and Cloud Computing

2. On the Storage accounts page, select Create.

Tutorial: Deploy Node.js app to Azure Web App using DevOps Starter for GitHub Actions

 Use DevOps Starter to deploy a Node.js app

DevOps Starter creates a workflow in GitHub. You can use an existing GitHub organization.
DevOps Starter also creates Azure resources such as Web App in the Azure subscription of your
choice.

1. Sign in to the Azure portal.


2. In the search box, type DevOps Starter, and then select. Click on Add to create a new one.

Abhishek Dhuri 24
MCA Sem 3 Distributed System and Cloud Computing

3. Select Node.js, and then select Next.


4. Under Choose an application Framework, select Express.js, and then select Next. The
application framework, which you chose in a previous step, dictates the type of Azure
service deployment target that's available here.

Abhishek Dhuri 25
MCA Sem 3 Distributed System and Cloud Computing

Abhishek Dhuri 26
MCA Sem 3 Distributed System and Cloud Computing

Software as a service (SaaS):

Software as a service (SaaS) allows users to connect to and use cloud based apps over the
Internet. Common examples are email, calendaring and office tools (such as Microsoft Office
365).

Manage the Azure app:

To manage your web app, go to the Azure portal, and search for and select App Services.

On the App Services page, select the name of your web app.

Abhishek Dhuri 27
MCA Sem 3 Distributed System and Cloud Computing

The Overview page for your web app, contains options for basic management like browse, stop,
start, restart, and delete. The left menu provides further pages for configuring your app.

Abhishek Dhuri 28
MCA Sem 3 Distributed System and Cloud Computing

Practical 8: JAVA PROGRAM TO ILLUSTRATE HOW


USER AUTHENTICATION IS DONE.

Code:

 UserAuthentication.java
import java.util.Scanner;

public class UserAuthentication {


public static void main(String[] args)
{ String userName, password;
Scanner sc = new Scanner(System.in);
System.out.print("Enter Username: ");
userName = sc.nextLine();
System.out.print("Enter Password: ");
password = sc.nextLine();
if (userName.equals("USER") && password.equals("PASSWORD"))
System.out.println("Authentication Successful!!");
else
System.out.println("Authentication Failed!!");
}
}

Output:

Abhishek Dhuri 29
MCA Sem 3 Distributed System and Cloud Computing

Practical 9: JAVA PROGRAM TO CHECK THE AUTHENTICATION OF


THE USER.

Code:
 AuthenticationOfUser.java
public class AuthenticationOfUser {
public static void main(String[] args)
{ String userName = "Uday Bhai";
String password = "Aalu Kanda";
if(userName.equals("Uday Bhai") && password.equals("Aalu Kanda"))
System.out.println("Authentication Successful!!");
else
System.out.println("Username/Password not matching");
}
}

Output:

 AuthenticationOfUser.java
public class AuthenticationOfUser {
public static void main(String[] args)
{ String userName = "Uday Bhai";
String password = "Alu Kanda";
if(userName.equals("Uday Bhai") && password.equals("Aalu Kanda"))
System.out.println("Authentication Successful!!");
else
System.out.println("Username/Password not matching");
}
}

Output:

Abhishek Dhuri 30
MCA Sem 3 Distributed System and Cloud Computing

Practical 10: CREATE A LOGIN FORM IN JAVA.

Code:
 LoginForm.java

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LoginForm extends JFrame implements ActionListener

{ JButton b1;
JPanel newPanel;
JLabel userLabel, passLabel;
final JTextField textField1, textField2;

LoginForm()
{
userLabel = new JLabel();
userLabel.setText("Username");
textField1 = new JTextField(15);
passLabel = new JLabel();
passLabel.setText("Password");
textField2 = new JPasswordField(15);
b1 = new JButton("SUBMIT");
newPanel = new JPanel(new GridLayout(3, 1));
newPanel.add(userLabel);
newPanel.add(textField1);
newPanel.add(passLabel);
newPanel.add(textField2);
newPanel.add(b1);
add(newPanel, BorderLayout.CENTER);
b1.addActionListener(this);
setTitle("LOGIN FORM");
}
public void actionPerformed(ActionEvent ae)
{
String userValue = textField1.getText();
String passValue = textField2.getText();
if (userValue.equals("[email protected]") && passValue.equals("test"))
{
NewPage page = new NewPage();
page.setVisible(true);
JLabel wel_label = new JLabel("Welcome: "+userValue);

Abhishek Dhuri 31
MCA Sem 3 Distributed System and Cloud Computing

page.getContentPane().add(wel_label);
}
else{
System.out.println("Please enter valid username and password");
}
}
}
class LoginFormDemo
{
public static void main(String arg[])
{
try
{
LoginForm form = new LoginForm();
form.setSize(300,100);
form.setVisible(true);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
}

 NewPage.java
import
javax.swing.*;

public class NewPage extends JFrame


{ NewPage() {
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Welcome");
setSize(400, 200);
}
}

Abhishek Dhuri 32
MCA Sem 3 Distributed System and Cloud Computing

Output:

Abhishek Dhuri 33
MCA Sem 3 Distributed System and Cloud Computing

Practical 11: DYNAMICALLY CHANGING THE BACKGROUND COLOR


OF A WEBPAGE ON EACH CLICK.

Code:
 ColorChange.html

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></
script>
</head>
<body style="text-align: center;" id="body">
<h1>Enter Your Color Choice</h1>
<button type="button" onclick="changecolor()">
Color
</button>
<script>
function changecolor() {
// Generating random color each time
var color = "#" + ((Math.random() * 16777215) | 0).toString(16);

$("body").css("background-color", color);
}
</script>
</body>
</html>

Output:

Abhishek Dhuri 34

You might also like