You are on page 1of 15

COLOR PALETTE

SOURCE CODE:

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

/*
<applet code=colorpalette.class width=500 height=400>
</applet>
*/

public class colorpalette extends Applet implements ActionListener,ItemListener
{
int flag=1;
String s1,s2;
Button b1,b2,b3,b4;
TextField text;
Checkbox forecolor,backcolor,image1,image2;
CheckboxGroup colour,images;
Image backGround;
Panel p1,p2,p3,p4;

public void init()
{
backGround = getImage(getCodeBase(), "Mountain.jpg");

Panel p1 = new Panel();
Panel p2 = new Panel();
Panel p3 = new Panel();
Panel p4 = new Panel();

b1=new Button();
b1.setBackground(Color.green);
b2=new Button();
b2.setBackground(Color.red);
b3=new Button();
b3.setBackground(Color.yellow);
b4=new Button();
b4.setBackground(Color.orange);

colour=new CheckboxGroup();



backcolor=new Checkbox("Background",colour,true);
forecolor=new Checkbox("Foreground",colour,false);

text=new TextField("Type Here",25);

images=new CheckboxGroup();
image1=new Checkbox("Mountain",images,true);
image2=new Checkbox("Sunrise",images,false);

p1.add(b1);
p1.add(b2);
p1.add(b3);
p1.add(b4);

p2.add(backcolor);
p2.add(forecolor);

p3.add(text);

p4.add(image1);
p4.add(image2);

setLayout(new GridLayout(10,1));
add(p1);
add(p2);
add(p3);
add(p4);

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);

backcolor.addItemListener(this);
forecolor.addItemListener(this);

image1.addItemListener(this);
image2.addItemListener(this);
}
public void paint(Graphics g)
{
g.drawImage(backGround,0,100,this);
}
public void actionPerformed(ActionEvent e)


{
Color col= Color.white;

if(e.getSource()==b1)
{
col = Color.green;
}
else if(e.getSource()==b2)
{
col = Color.red;
}
else if(e.getSource()==b3)
{
col = Color.yellow;
}
else if(e.getSource()==b4)
{
col = Color.orange;
}

if(flag==1)
{
text.setBackground(col);
}
else
{
text.setForeground(col);
}

repaint();
}

public void itemStateChanged(ItemEvent ie)
{
s1=colour.getSelectedCheckbox().getLabel();
if(s1.equals("Background"))
{
flag=1;
}
else
{
flag=0;
}



s2=images.getSelectedCheckbox().getLabel();
if(s2.equals("Mountain"))
{
backGround = getImage(getCodeBase(), "Mountain.jpg");
}
else
{
backGround = getImage(getCodeBase(), "sunrise.jpg");
}

repaint();
}
}



































SOURCE CODE:

<HTML>
<HEAD>
<TITLE>About Andhra Pradesh</TITLE>
</HEAD>
<BODY>
<CENTER><H1>Andhra Pradesh</H1></CENTER>
<HR>
<UL>
<LI>Area : 2,75,068 Sq. Kms</LI>
<LI>Capital : Hyderabad</LI>
<LI>Language : Telugu</LI>
<LI>Population : 7,57,27,541</LI>
</UL>
</BODY>
</HTML>



























IMAGE MAP

SOURCE CODE:

<HTML>
<HEAD>
<TITLE>Image Map</TITLE>
</HEAD>
<BODY>
<MAP id = "picture">
<AREA href = "TamilNadu.html" shape = "circle" title="TamilNadu" coords = "170, 490, 30"
alt = "Tamil Nadu" />

<AREA href = "Karnataka.html" shape = "rect" title="Andhrapradesh"
coords = "115, 390, 150, 450" alt = "Karnataka" />

<AREA href = "AndhraPradesh.html" shape = "poly" title="Andhrapradesh"
coords = "165, 355, 200, 355, 220, 380, 170, 425, 165,
355" alt = "Andhra Pradesh" />

<AREA href = "Kerala.html" shape = "poly" title="Kerala"
coords = "115, 455, 160, 470, 140, 485, 150, 505, 150,
530, 135, 500, 115, 455" alt = "Kerala" />

</MAP>
<IMG src = "India.Jpg" alt = "India" usemap = "#picture" />
</BODY>
</HTML>


















SOURCE CODE:

<HTML>
<HEAD>
<TITLE>About Karnataka</TITLE>
</HEAD>
<BODY>
<CENTER><H1>Karnataka</H1></CENTER>
<HR>
<UL>
<LI>Area : 1,91,791 Sq. Kms</LI>
<LI>Capital : Bangalore</LI>
<LI>Language : Kannada</LI>
<LI>Population : 5,27,33,958</LI>
</UL>
</BODY>
</HTML>





























SOURCE CODE:

<HTML>
<HEAD>
<TITLE>About Kerala</TITLE>
</HEAD>
<BODY>
<CENTER><H1>Kerala</H1></CENTER>
<HR>
<UL>
<LI>Area : 38,863 Sq. Kms.</LI>
<LI>Capital : Thiruvananthapuram</LI>
<LI>Language : Malayalam</LI>
<LI>Population : 3,18,38,619</LI>
</UL>
</BODY>
</HTML>





























SOURCE CODE:

<HTML>
<HEAD>
<TITLE>About Tamil Nadu</TITLE>
</HEAD>
<BODY>
<CENTER><H1>Tamil Nadu</H1></CENTER>
<HR>
<UL>
<LI>Area : 1,30,058 Sq. Kms.</LI>
<LI>Capital : Chennai</LI>
<LI>Language : Tamil</LI>
<LI>Population : 6,21,10,839</LI>
</UL>
</BODY>
</HTML>





























SINGLE THREAD

SOURCE CODE:

class Mythread extends Thread
{
public void run()
{
System.out.println("hello world");
}
}
class FirstThread
{
public static void main(String arg[])
{
Mythread t = new Mythread();
t.start();
}
}






























MULTI THREAD

SOURCE CODE:

class MyThread extends Thread
{
String name;
int slp;
public MyThread (String na, int s)
{
name=na;
slp=s;
}
public void run()
{
try
{
for(int i=1;i<=6;i++)
{
System.out.println(name);
Thread.sleep(slp);
}
}
catch (Exception e)
{
}
}
}
class MultiThread
{
public static void main(String arg[])
{
MyThread t1= new MyThread("First",100);
MyThread t2=new MyThread ("second",200);
t1.start();
t2.start();
}
}








INTERFACE

SOURCE CODE:

interface ISports
{
public void SetTeam(String t1,String t2, int score1, int score2);
public void ShowResult();
}

class Cricket implements ISports
{
String team1,team2;
int team1Runs,team2Runs;
public void SetTeam(String t1,String t2, int r1, int r2)
{
team1 = t1;
team2 = t2;
team1Runs = r1;
team2Runs = r2;
}

public void ShowResult()
{
System.out.println(team1 + "-" + team1Runs + " Runs");
System.out.println(team2 + "-" + team2Runs + " Runs");
}
}

class Hockey implements ISports
{
String team1,team2;
int team1Goals,team2Goals;
public void SetTeam(String t1,String t2, int r1, int r2)
{
team1 = t1;
team2 = t2;
team1Goals = r1;
team2Goals = r2;
}

public void ShowResult()
{
System.out.println(team1 + "-" + team1Goals + " Goals");



System.out.println(team2 + "-" + team2Goals + " Goals");
}

}

class Sports
{
public static void main(String args[])
{
Cricket c = new Cricket();
Hockey h = new Hockey();

c.SetTeam("India", "England",240,220);
h.SetTeam("India", "Germany",3,2);

c.ShowResult();
h.ShowResult();

}
}





















SIMPLE SERVLET

SOURCECODE:

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet TestServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h3>Welcome " + request.getParameter("txtname") + "</h3>");
out.println("</body>");
out.println("</html>");
}
finally {
out.close();
}
}
























SOURCE CODE:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form name="MyForm" action="TestServlet" method="post">
<table>
<tr>
<td>Enter Name :</td>
<td><input type="text" name="txtname" size="30"></td>
</tr>
</table>
<input type="submit" name="submit" value="Ok">
</form>
</body>
</html>

You might also like