Aryan
Aryan
Course – MCA
Semester – 2nd
Roll number – 24124
Subject – Advance Object Technology
Submitted to – Dr. Gopal Singh
a. Button
b. Checkbox
4. Write a program to implement Swing components.
a. Button
b. Table
c. Tree
d. Checkbox Pane
5. Write a program to implement Swing components.
(a) Tabbed Pane
(b) Scroll Pane
6. Write a program to implement all the phases of life cycle of Servlet.
7. Write a program to show implement DHTML and CSS with java script.
8. How is role of server side different from client side in a typical website? Clear using
an example.
9. Write a program in Java using JSP which accept two integer numbers from user and
display the result.
10. Write a program using POST and GET Method in swing.
11. Write a JavaScript program to check number entered is an Armstrong number or not.
12. Write a JavaScript program to create a Login Form and validate it.
13. Write a program to implement Event and AWT components.
a. CANVAS
b. SCROLLBAR
14. Write a program using JSP to implement the Scripting Elements.
15. Write a program using JSP to implement any five Implicit Objects.
Index
Code:
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
setSize(400, 300);
setBackground(Color.lightGray);
g.setColor(Color.blue);
g.setColor(Color.red);
// Draw a line
g.setColor(Color.green);
}
HTML embedded code:
<html>
<body>
</applet>
</body>
</html>
Output:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Form
Validation</title>
</head>
<style>
.my_form {
display: flex;
flex-direction: column;
gap: 1em;
position: absolute;
top: 30%;
left: 40%;
padding: 1.5rem;
width: max-content;
border-radius: 3%;
body {
.ft {
font-weight: 500;
letter-spacing: 0.075rem;
font-style: oblique;
margin-right: 1em;
input {
background-color: transparent;
border: none;
outline: none;
border-radius: 3px;
input:focus {
background-color: black;
color: white;
#ent,
#eet,
#enut,
#ept,
#ecpt {
color: red;
letter-spacing: 2px;
font-size: .9rem;
font-weight: 600;
</style>
<body>
<div class="my_form_container">
<form id="my_form" class="my_form">
<div class="fg">
<span class="ft">Name</span>
</div>
<div class="fg">
<span id="ent"></span>
</div>
<div class="fg">
<span class="ft">Email</span>
</div>
<div class="fg">
<span id="eet"></span>
</div>
<div class="fg">
</div>
<div class="fg">
<span id="enut"></span>
</div>
<div class="fg">
<span class="ft">Password</span>
</div>
<div class="fg">
<span id="ept"></span>
</div>
<div class="fg">
</div>
<div class="fg">
<span id="ecpt"></span>
</div>
<div class="fg">
<span class="ft"></span>
</div>
</form>
</div>
<script>
} else {
ent.innerText = ''
} else {
} else {
eet.innerText = "";
if (val == null) {
} else {
enut.innerText = "";
} else {
ept.innerText = '';
} else {
ecpt.innerText = ''
event.preventDefault();
if (phone == null) {
if (password.length < 8) {
}
});
</script>
</body>
</html>
Output:
import java.awt.event.*;
Checkbox checkbox;
public AWTEventDemo() {
setLayout(new FlowLayout());
// Button Component
btn.addActionListener(this);
add(btn);
add(lblButton);
// Checkbox Component
checkbox.addItemListener(this);
add(checkbox);
add(lblCheckbox);
// Frame properties
setSize(300, 200);
setVisible(true);
addWindowListener(new WindowAdapter() {
dispose();
});
@Override
lblButton.setText("Button Clicked!");
@Override
if (checkbox.getState()) {
lblCheckbox.setText("Checkbox Checked");
} else {
lblCheckbox.setText("Checkbox Unchecked");
new AWTEventDemo();
Output:
Question4: Write a program to implement Swing components.
a. Button
b. Table
c. Tree
d. Checkbox Pane
Code:
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public SwingComponentsDemo() {
setSize(500, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
// Button Component
button.addActionListener(new ActionListener() {
buttonLabel.setText("Button Clicked!");
});
add(button);
add(buttonLabel);
// Table Component
String[][] data = {
};
add(tablePane);
// Tree Component
root.add(child2);
add(treePane);
// Checkbox Pane
add(checkbox);
setVisible(true);
new SwingComponentsDemo();
}
Output:
import java.awt.*;
public SwingTabbedScrollDemo() {
setSize(500, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
// Tabbed Pane
// Scroll Pane
add(tabbedPane, BorderLayout.NORTH);
add(scrollPane, BorderLayout.CENTER);
setVisible(true);
new SwingTabbedScrollDemo();
}
Output:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/LifecycleServlet")
super.init(config);
System.out.println("Servlet is initialized");
response.setContentType("text/html");
}
Output:
Question7: Write a program to show implement DHTML and CSS with
java script.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
margin-top: 50px;
#dynamicText {
font-size: 20px;
color: blue;
margin-top: 20px;
padding: 10px;
#movingBox {
width: 100px;
height: 100px;
background-color: red;
position: absolute;
left: 50px;
top: 200px;
button {
margin: 10px;
font-size: 16px;
cursor: pointer;
</style>
</head>
<body>
<h2>DHTML & CSS with JavaScript</h2>
<div id="movingBox"></div>
<script>
function changeText() {
textElement.style.color = "green";
textElement.style.fontSize = "24px";
function toggleVisibility() {
textElement.style.display = "block";
} else {
textElement.style.display = "none";
}
function moveBox() {
</script>
</body>
</html>
Output:
Code:
Server side:
const express = require('express');
res.send("Login Successful!");
} else {
res.send("Invalid Credentials!");
});
app.listen(3000, () => {
console.log("Server running on port 3000");
});
Output:
Client side:
<form onsubmit="return validateForm()" action="/login" method="POST">
<button type="submit">Login</button>
</form>
<script>
function validateForm() {
return true;
</script>
Output:
Question 9: Write a program in Java using JSP which accept two
integer numbers from user and display the result.
Code:
Index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>Number Calculator</h1>
</form>
</body>
</html>
calculateResult.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>Calculation Result</h1>
<%
try {
number1 = Integer.parseInt(num1Str);
number2 = Integer.parseInt(num2Str);
} catch (NumberFormatException e) {
%>
<% } %>
</body>
</html>
Output:
Question 10: Write a program using POST and GET Method in swing
Code:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import javax.swing.*;
//Program 10
public SwingHttpClient() {
setSize(500, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
responseArea.setEditable(false);
add(nameLabel);
add(nameField);
add(getButton);
add(postButton);
add(scrollPane);
getButton.addActionListener(new ActionListener() {
sendGetRequest();
});
postButton.addActionListener(new ActionListener() {
sendPostRequest();
});
setVisible(true);
}
private void sendGetRequest() {
try {
conn.setRequestMethod("GET");
String inputLine;
response.append(inputLine).append("\n");
in.close();
responseArea.setText("GET Response:\n" +
response.toString());
try {
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/x-
www-form-urlencoded");
OutputStream os = conn.getOutputStream();
writer.write("name=" + name);
writer.flush();
writer.close();
os.close();
String inputLine;
response.append(inputLine).append("\n");
in.close();
responseArea.setText("POST Response:\n" +
response.toString());
} catch (Exception ex) {
new SwingHttpClient();
Output:
Question 11: Write a JavaScript program to check number entered is
an Armstrong number or not.
Code:
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
function isArmstrongNumber(num) {
let sum = 0;
if (!isNaN(number)) {
if (isArmstrongNumber(number)) {
} else {
} else {
readline.close();
});
Output:
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
.login-container {
background-color: #fff;
padding: 20px;
border-radius: 8px;
width: 300px;
text-align: center;
h2 {
margin-bottom: 20px;
color: #333;
.form-group {
margin-bottom: 15px;
text-align: left;
label {
display: block;
margin-bottom: 5px;
color: #555;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 8px;
border-radius: 4px;
box-sizing: border-box;
button {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
button:hover {
background-color: #45a049;
#message {
margin-top: 15px;
font-size: 14px;
}
.success {
color: green;
.error {
color: red;
</style>
</head>
<body>
<div class="login-container">
<h2>Login Form</h2>
<div class="form-group">
</div>
<div class="form-group">
<label for="password">Password:</label>
</div>
<button type="submit">Login</button>
</form>
<div id="message"></div>
</div>
<script>
function validateForm(event) {
const phoneOrEmail =
document.getElementById("phoneOrEmail").value.trim();
const password =
document.getElementById("password").value.trim();
messageDiv.textContent = "";
messageDiv.className = "error";
return false;
messageDiv.className = "success";
return true;
messageDiv.className = "success";
return true;
} else {
messageDiv.className = "error";
return false;
</script>
</body>
</html>
Output:
I have take predicted data since I havn’t linked it with any of website
or database
Question 13: Write a program to implement Event and AWT
components.
a. CANVAS
b. SCROLLBAR
Code:
import java.awt.*;
import java.awt.event.*;
//program13
public AWTCanvasScrollbarExample() {
super.paint(g);
g.setColor(Color.RED);
};
canvas.setSize(300, 200);
scrollbar = new Scrollbar(Scrollbar.VERTICAL, 50, 10, 0, 150);
frame.setLayout(null);
frame.add(canvas);
frame.add(scrollbar);
scrollbar.addAdjustmentListener(new AdjustmentListener() {
circleYPosition = e.getValue();
canvas.repaint();
});
frame.setSize(400, 300);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
System.exit(0);
});
new AWTCanvasScrollbarExample();
Output:
Question 14: Write a program using JSP to implement the Scripting
Elements.
Code:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<%!
int counter = 0;
%>
<%
counter++;
%>
<h3>Numbers 1 to 5:</h3>
<ul>
<%
%>
<%
%>
</ul>
</body>
</html>
Output:
Question 15: Write a program using JSP to implement any five Implicit
Objects.
Code:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<body>
<%
response.setHeader("Custom-Header", "JSP-Demo");
%>
<%
if (visitCount == null) {
visitCount = 0;
visitCount++;
session.setAttribute("visitCount", visitCount);
%>
<%
synchronized (application) {
if (totalVisits == null) {
totalVisits = 0;
totalVisits++;
application.setAttribute("totalVisits", totalVisits);
%>
<%
%>
</body>
</html>
Output: