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

Practical No.2

The document provides code for a Java program that demonstrates an editable table to display employee details. It imports necessary packages, creates a class called Program2 with a main method that creates a MyFrame object and sets its properties. The MyFrame class extends JFrame, gets the content pane, sets the layout, and adds a JTable populated with employee data to a JScrollPane, which is then added to the content pane.

Uploaded by

nisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

Practical No.2

The document provides code for a Java program that demonstrates an editable table to display employee details. It imports necessary packages, creates a class called Program2 with a main method that creates a MyFrame object and sets its properties. The MyFrame class extends JFrame, gets the content pane, sets the layout, and adds a JTable populated with employee data to a JScrollPane, which is then added to the content pane.

Uploaded by

nisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Practical No.

Write a java program to demonstrate editable table describing employee details


Software Company.

Coding :
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class Program2

{
public static void main(String args[])

{
MyFrame mf=new MyFrame();
mf.setVisible(true);
mf.setSize(300,300);
mf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

class MyFrame extends JFrame

Container cp;

MyFrame()

cp=getContentPane();
cp.setLayout(new FlowLayout());

String data[][]={{"101","Vighnesh","Bhoir","20","CS","PM","600000"},
{"102","Kuldeep","Mane","20","IT","PM","500000"},
{"103","Nitin","Aarde","19","IT","Designer","250000"},
{"104","Ritesh","Tambe","25","CS","Tester","200000"},
{"","","","","","",""},{"","","","","","",""}};
String s[]={"id","name","lname","age","dept","designation","salary"};
JTable tb=new JTable(data,s);
JScrollPane js=new JScrollPane(tb);
cp.add(js);
}

Output:

Practical No.3

Write a java program using SplitPane to demonstrate aa screen divided in


two parts one part contain the names of Planet and another display the
image of Planet.

Coding:

import javax.swing.*;

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

class Program1
{
public static void main(String args[])
{

MyFrame mf=new MyFrame();


mf.setVisible(true);
mf.setSize(300,300);
mf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

class MyFrame extends JFrame implements ListSelectionListener


{

Container cp;
JList j1;
JLabel j2;
JSplitPane jsp;

MyFrame()
{
cp=getContentPane();

String
s1[]={"Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune
","Pluto"};
j1=new JList(s1);
j2=new JLabel("");
jsp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,j1,j2);
cp.add(jsp);
j1.addListSelectionListener(this);
}
public void valueChanged(ListSelectionEvent e)
{

if(j1.getSelectedIndex()==0)
{
j2.setIcon(new ImageIcon("Mercury.jpg"));
}

if(j1.getSelectedIndex()==1)
{
j2.setIcon(new ImageIcon("Venus.jpg"));
}

if(j1.getSelectedIndex()==2)
{
j2.setIcon(new ImageIcon("Earth.jpg"));
}

if(j1.getSelectedIndex()==3)
{
j2.setIcon(new ImageIcon("Mars.jpg"));
}

if(j1.getSelectedIndex()==4)
{
j2.setIcon(new ImageIcon("Jupiter.jpg"));
}

if(j1.getSelectedIndex()==5)
{
j2.setIcon(new ImageIcon("Saturn.jpg"));
}

if(j1.getSelectedIndex()==6)
{
j2.setIcon(new ImageIcon("Uranus.jpg"));

if(j1.getSelectedIndex()==7)
{
j2.setIcon(new ImageIcon("Neptune.jpg"));
}

if(j1.getSelectedIndex()==8)
{
j2.setIcon(new ImageIcon("Pluto.jpg"));
}
}
}
Output:

Practical No.5

Develop Servlet Application of Basic Calculator (+,-,*, /, %) using


ServletInputStream and ServletOutputStream.

Coding:
1.index.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CALCULATOR</title>
</head>
<body>
<h3>T CALCULATOR!</h3>
<form action="TCalc" method="Get">
<table>
<tr>
<td><input name="opr1" type="text"></td>
<td> <select name="opr">
<option value="+"> + </option>
<option value="-"> - </option>
<option value="*"> * </option>
<option value="/"> / </option>
</select></td>
<td><input name="opr2" type="text"></td>
<td><input name="result" type="Submit"></td>
</tr>
</table>

</form>
</body>
</html>

2.Tcalc.java:
package Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import static java.lang.System.out;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import static sun.java2d.cmm.ColorTransform.Out;

public class TCalc extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter())
{
Integer opr1=Integer.parseInt(request.getParameter("opr1"));
Integer opr2=Integer.parseInt(request.getParameter("opr2"));
Integer res=null;

String operation=request.getParameter("opr");
if("+".equals(operation))
{
res=opr1+opr2;
}
else if("-".equals(operation))
{
res=opr1-opr2;
}
else if("*".equals(operation))
{
res=opr1*opr2;
}
else
{
res=opr1/opr2;
}
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet TCalc</title>");
out.println("</head>");
out.println("<body>");
out.println("<h2>Result is:"+res+"</h2>");
out.println("</body>");
out.println("</html>");
}

finally
{
out.close();
}
}

Output:

Practical No.4
Develop Simple Servlet Question Answer Application to demonstrate use
of HttpServletRequest and HttpServletResponse interfaces.

Coding:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
</head>
<body>
<form method = "post" action = "Logins.jsp">
<fieldset>
<legend style="font-size:xx-large;color:white"><b>Login</b></legend>
<font size = 5>Enter your name<br>
<input type = "text" name = "name"></font><br>
<font size = 5>Enter your password<br>
<input type="password" name = "pwd" ></font><br><br>
<input type = "submit" name = "submit" value = "submit" >
</fieldset>
</form>
</body>
</html>

Output:

Practical No. 09
Coding:
1.ReservationBean.java:
package com;

import java.util.ArrayList;

public class ReservationBean


{
public String welcome(String customer)
{
return "Hello"+""+customer.toUpperCase()+""+"Welcome to our Hotel";
}
public String roomType(String roomtype){
return "You have Selected"+""+ roomtype.toUpperCase()+""+"Room";
}
public String payment(String roomtype){
System.out.print(roomtype);
System.out.print(roomtype);
if(roomtype.equalsIgnoreCase("SUITE"))
{
return "You have to pay 8000 Rs";
}
else if(roomtype.equalsIgnoreCase("DELUXE"))
{
return "You have to pay 4000 Rs";
}
else
return "You have to pay 2000 Rs";
}

public ArrayList<String> reserve(String customer,String add,String ph,String checkin,String


checkout,String roomtype,String paymode)
{
ArrayList<String>a=new ArrayList();
a.add(customer);
a.add(add);
a.add(ph);
a.add(checkin);
a.add(checkout);
a.add(roomtype);
a.add(paymode);
return a;
}
}
ReservationServlet.java:
package com;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ReservationServlet extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String cname=request.getParameter("cname");
String add=request.getParameter("cadd");
String ph=request.getParameter("cph");
String roomtype=request.getParameter("roomtype");
String chkin=request.getParameter("chekindate");
String chkout=request.getParameter("checkoutdate");
String paymode=request.getParameter("paymode");
PrintWriter out = response.getWriter();
ReservationBean rb=new ReservationBean();
int i=0;
ArrayList<String> list1 = rb.reserve(cname, add, ph, chkin, chkout, roomtype,
paymode);
try
{
rb.reserve(cname, add, ph, chkin, chkout, roomtype, paymode);

out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Reservation EJB </title>");
out.println("</head>");
out.println("<body>");
out.println(rb.roomType(roomtype));
out.println("<br/>");

out.println(rb.payment(roomtype));
out.println("<br/>");
out.println("<br/>");
out.println("Wer Details:");
int n=list1.size();
out.println("<Table border=1>");
out.println("<tr><th>Name</th><th>Address</th><th>Phone</th><th>Check In
Date</th>");
out.println("<th> Check Out Date</th><th> Room</th><th>Payment
Mode</th></tr>");
out.println("<tr>");
for(i=0;i<n;i++)
{
out.println("<TD>");
out.println(list1.get(i));
out.println("</TD>");
}
out.println("</tr>");
out.println("</Table>");
out.println("<br/> Click <a href='index.jsp'>here</a>to go back");
out.println("</body>");
out.println("</html>");
}
}
Index.jsp:
<%-Document : index
Created on : Sep 25, 2016, 11:36:01 PM

Author

: dell

--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Room Reservation</title>
</head>
<body>
<hr>
<p>
Enter Details For Room Reservation.
</p>
<form method="post" action="ReservationServlet">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td> Customers Name:</td>
<td><input type="text" name="cname" value="" size="50" tabindex="1"/></td>
<tr><td> Address : </td>
<td><input type="text" name="cadd" value="" size="50" tabindex="1"/></td>
<tr><td> Phone Number : </td>
<td><input type="text" name="cph" value="" size="50" tabindex="1"/></td>
</tr><tr><td> Room Type : </td>
<td><select name="roomtype">
<option id="g"> General</option>
<option id="s"> Deluxe</option>

<option id="s"> Suite</option>


</select></td>
</tr><tr><td> Check IN Date :</td>
<td><input type="text" name="checkindate" value="" size="12"
tabindex="1"/></td>
</tr><tr><td> Check Out Date :</td>
<td><input type="text" name="checkoutdate" value="" size="12"
tabindex="1"/></td>
</tr><tr><td> Payment Mode : </td>
<td><select name="paymode">
<option id="cash"> CASH</option>
<option id="credit"> CREDIT CARD</option>
</select></td>
</tr> <tr><td colspan="2">
<input name="cmdSubmit" type="submit" value="Submit" alt="Convert"
tabindex="4"/>
</td></tr>
</table>
</form>
</hr>

</body>
</html>

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy