0% found this document useful (0 votes)
293 views38 pages

EX NO:13 Implementation of Point Class For Image Manipulation Date

This document describes coding for implementing a point class for image manipulation. It defines 4 Point objects (p1, p2, p3, p4) and draws lines between them in a rectangle in the paint method. The code imports necessary libraries, creates a PointDemo class that extends Applet, initializes the Points, sets the background color, and draws lines between the Points to make a rectangle shape.

Uploaded by

Vinoth M
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)
293 views38 pages

EX NO:13 Implementation of Point Class For Image Manipulation Date

This document describes coding for implementing a point class for image manipulation. It defines 4 Point objects (p1, p2, p3, p4) and draws lines between them in a rectangle in the paint method. The code imports necessary libraries, creates a PointDemo class that extends Applet, initializes the Points, sets the background color, and draws lines between the Points to make a rectangle shape.

Uploaded by

Vinoth M
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/ 38

EX NO:13

DATE:

Aim:

Procedure:

Implementation of Point Class for Image Manipulation

Coding:
importjava.awt.*;
importjava.applet.*;
/*<applet code="pointdemo.class" width=1000 height=690></applet>*/
public class pointdemo extends Applet
{
Point p1=new Point(20,200);
Point p2=new Point(120,200);
Point p3=new Point(120,20);
Point p4=new Point(20,20);
public void init()
{
setBackground(Color.yellow); }
public void paint(Graphics g)
{
g.setColor(Color.red);
g.drawLine(p1.x,p1.y,p2.x,p2.y);
g.drawLine(p2.x,p2.y,p3.x,p3.y);
g.drawLine(p3.x,p3.y,p4.x,p4.y);
g.drawLine(p4.x,p4.y,p1.x,p1.y);
}
}

Output:

EX NO: 14
DATE:
Aim:

Procedure:

Working with Frames and Various Control

Coding:
import java.awt.*;
import java.awt.event.*;
class framesdemo extends Frame implements ActionListener
{
Frame f;
TextField t;
Button b1,b2;
List l;
framesdemo(String t1)
{
super(t1);
Label lb=new Label("Enter your text:",Label.RIGHT);
setLayout(new FlowLayout());
t=new TextField(100);
b1=new Button("Click to add in list");
b2=new Button("Click to remove from list");
l=new List(10,false);
t.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
l.addActionListener(this);
add(lb);
add(t);
add(b1);
add(b2);
add(l);
mywin a=new mywin(this);
addWindowListener(a);
}
public static void main(String arg[])
{
framesdemo fr=new framesdemo("Demo of frames and other controls");
fr.setSize(1000,600);
fr.setVisible(true);

}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
l.add(t.getText());
if(ae.getSource()==b2)
l.remove(l.getSelectedItem());
}
class mywin extends WindowAdapter
{
framesdemo fr1;
public mywin(framesdemo fr1)
{
this.fr1=fr1;
}
public void windowClosing(WindowEvent we)
{
fr1.setVisible(false);
System.exit(0);

}
}
}

Output:

EX:NO:15
DATE:
Aim:

Procedure:

WORKING WITH DIALOG BOX AND MENUS

Coding:
importjava.awt.*;
importjava.applet.*;
importjava.awt.event.*;
/*<APPLET CODE="menudemo"
WIDTH="1100"HEIGHT="690"></APPLET>*/
public class menudemo extends Applet implements ActionListener
{
Menu m1,m2;
MenuItem mi1,mi2,mi3,mi4,mi5,mi6,mi7,mi8,mi9,mi10;
MenuBarmb;
Dialog d;
Frame f;
Label l;
Button b1,b2;
Panel p;
public void init()
{
f=new Frame("menudemo");
p=new Panel();
l=new Label("Are you sure you want to exit...?");
b1=new Button("Ok");
b2=new Button("Cancel");
d=new Dialog(f,"CONFIRM",true);
mb=new MenuBar();
mi1=new MenuItem("Exit");
mi2=new MenuItem("Red");
mi3=new MenuItem("Green");
mi4=new MenuItem("Cyan");
mi5=new MenuItem("Blue");
mi6=new MenuItem("Pink");

mi1.addActionListener(this);
mi2.addActionListener(this);
mi3.addActionListener(this);
mi4.addActionListener(this);
mi5.addActionListener(this);
mi6.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
m1=new Menu("File");
m2=new Menu("Back color");
m1.add(mi1);
m2.add(mi2);
m2.add(mi3);
m2.add(mi4);
m2.add(mi5);
m2.add(mi6);
mb.add(m1);
mb.add(m2);
f.setMenuBar(mb);
f.setSize(500,500);
f.setVisible(true);
}
public void actionPerformed(ActionEventae)
{
if(ae.getActionCommand().equals("Red"))
f.setBackground(Color.red);
if(ae.getActionCommand().equals("Green"))
f.setBackground(Color.green);
if(ae.getActionCommand().equals("Cyan"))
f.setBackground(Color.cyan);
if(ae.getActionCommand().equals("Blue"))
f.setBackground(Color.blue);
if(ae.getActionCommand().equals("Pink"))
f.setBackground(Color.pink);
if(ae.getActionCommand().equals("Exit"))

{
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae1)
{
f.dispose();
}
});
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae2)
{
d.dispose();
}
});
d.setLayout(new BorderLayout());
d.add(l,BorderLayout.NORTH);
p.add(b1);
p.add(b2);
d.add(p,BorderLayout.CENTER);
d.setSize(200,200);
d.setVisible(true);
}
}
}

Output:

EX NO:16
DATE:

Aim:

Procedure:

Coding:

WORKING WITH COLOURS AND FONTS

importjava.awt.*;
importjava.awt.event.*;
importjava.applet.*;
/*<applet code="colfont" width=1100 height=690 >
</applet>*/
public class colfont extends Applet implements ItemListener
{
Choice c1,c2,c3,c4;
Label l1,l2,l3,l4;
Panel p1,p2;
staticint f;
public void init()
{
c1=new Choice();
c2=new Choice();
c3=new Choice();
c4=new Choice();
c1.addItemListener(this);
c2.addItemListener(this);
c3.addItemListener(this);
c4.addItemListener(this);
l1=new Label("Font");
l2=new Label("Font Style");
l3=new Label("Font Color");
l4=new Label("Font Size");
p1=new Panel();
p2=new Panel();
}
public void start()
{
GraphicsEnvironment g=
GraphicsEnvironment.getLocalGraphicsEnvironment();
Font f2[ ]=g.getAllFonts();
for(int i=0;i<f2.length;i++)
c1.addItem(f2[i].getFontName());

c2.addItem("BOLD");
c2.addItem("ITALIC");
c3.addItem("RED");
c3.addItem("GREEN");
c3.addItem("BLUE");
c3.addItem("CYAN");
c3.addItem("YELLOW");
for(int i=10;i<100;i+=2)
c4.addItem(String.valueOf(i));
p1.add(l1);
p1.add(c1);
p1.add(l2);
p1.add(c2);
p1.add(l3);
p1.add(c3);
p1.add(l4);
p1.add(c4);
p2.setLayout(new BorderLayout());
add("NORTH",p1);
add("CENTER",p2);
}
public void itemStateChanged(ItemEventie)
{
repaint();
}
public void paint(Graphics g)
{
if(c2.getSelectedItem().equals("BOLD"))
f=Font.BOLD;
if(c2.getSelectedItem().equals("ITALIC"))
f=Font.ITALIC;
g.setFont(new Font(c1.getSelectedItem(),f,Integer.parseInt(c4.getSelectedItem())));
if(c3.getSelectedItem().equals("RED"))
g.setColor(Color.red);
if(c3.getSelectedItem().equals("GREEN"))

g.setColor(Color.green);
if(c3.getSelectedItem().equals("BLUE"))
g.setColor(Color.blue);
if(c3.getSelectedItem().equals("CYAN"))
g.setColor(Color.cyan);
if(c3.getSelectedItem().equals("YELLOW"))
g.setColor(Color.yellow);
g.drawString("WELCOME TO APPLET PROGRAM",200,200);
}}

Output:

EX NO:17
DATE:

Drawing Various Shape Using Graphical Methods

Aim:

Procedure:

Coding:
importjava.awt.*;
importjava.applet.*;

/*<applet code="face"width=1100 height=690>


</applet>*/
public class face extends Applet
{
public void paint(Graphics g)
{
g.drawOval(40,40,120,150);
g.drawOval(57,75,30,20);
g.drawOval(110,75,30,20);
g.fillOval(68,81,10,10);
g.fillOval(120,81,10,10);
g.fillArc(60,125,80,40,1801,180);
g.drawOval(25,92,15,30);
g.drawOval(160,92,15,30);
}
}

Output:

EX NO:18
DATE:

Working With Panel And All Type of Layout

Aim:

Procedure:

Coding:

importjava.awt.*;
importjava.applet.Applet.*;
importjava.applet.*;
importjava.awt.event.*;
/*<applet code="layout.class" width=300 height=300>
</applet>*/
public class layout extends Applet implements ActionListener
{
Panel p1,p2;
Button b1,b2;
Button b[]=new Button[6];
String msg="";
public void init()
{
p1=new Panel();
p2=new Panel();
b1=new Button("first");
b2=new Button("Second");
p1.setLayout(new FlowLayout(FlowLayout.CENTER));
b1.addActionListener(this);
b2.addActionListener(this);
p1.add(b1);
p1.add(b2);
p2.setLayout(new GridLayout(2,3));
for(int i=0;i<6;i++)
{
b[i]=new Button("panel2"+(i+1));
b[i].addActionListener(this);
p2.add(b[i]);
}
setLayout(new BorderLayout());

add(p1,BorderLayout.NORTH);
add(p2,BorderLayout.SOUTH);
}
public void actionPerformed(ActionEventae)
{
String st=ae.getActionCommand();
if (st.equals("first"))
{
msg="you pressed First";
}
else if(st.equals("second"))
{
msg="u pressed second";
}
else
{
msg="u pressed"+ae.getActionCommand();
}
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg,6,100);
}
}

Output:

EX NO:19
DATE:

Design a Panel With Simple Caculator

Aim:

Procedure:

Coding:

importjava.awt.*;
importjava.applet.*;
importjava.awt.event.*;
/*<applet code="Calculator" width=1100 height=690>
</applet>*/
public class Calculator extends Applet implements ActionListener
{
TextField t1;
String a="";
String oper="";
int first=0,result=0;
Panel p1;
Button b0,b1,b2,b3,b4,b5,b6,b7,b8,b9;
Button add,sub,mul,div,res,space;
public void init()
{
Panel p2,p3;
p1=new Panel();
p2=new Panel();
p3=new Panel();
t1=new TextField(a,20);
p1.setLayout(new BorderLayout());
p2.add(t1);
b0=new Button("0");
b1=new Button("1");
b2=new Button("2");
b3=new Button("3");
b4=new Button("4");
b5=new Button("5");
b6=new Button("6");
b7=new Button("7");
b8=new Button("8");
b9=new Button("9");
add=new Button("+");
sub=new Button("-");

mul=new Button("*");
div=new Button("/");
res=new Button("=");
space=new Button("c");
p3.setLayout(new GridLayout(4,4));
b0.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
add.addActionListener(this);
sub.addActionListener(this);
mul.addActionListener(this);
div.addActionListener(this);
res.addActionListener(this);
space.addActionListener(this);
p3.add(b0);
p3.add(b1);
p3.add(b2);
p3.add(b3);
p3.add(b4);
p3.add(b5);
p3.add(b6);
p3.add(b7);
p3.add(b8);
p3.add(b9);
p3.add(add);
p3.add(sub);
p3.add(mul);
p3.add(div);

p3.add(res);
p3.add(space);
p1.add(p2,BorderLayout.NORTH);
p1.add(p3,BorderLayout.CENTER);
add(p1);
}
public void actionPerformed(ActionEventae)
{
a=ae.getActionCommand();
if(a=="0"||a=="1"||a=="2"||a=="3"||a=="4"||a=="5"||a=="6"||a=="7"||a=="8"||
a=="9")
{
t1.setText(t1.getText()+a);
} if(a=="+"||a=="-"||a=="*"||a=="/")
{
first=Integer.parseInt(t1.getText());
oper=a;
t1.setText("");
} if(a=="=")
{
if(oper=="+")
result=first+Integer.parseInt(t1.getText());
if(oper=="-")
result=first-Integer.parseInt(t1.getText());
if(oper=="*")
result=first*Integer.parseInt(t1.getText());
if(oper=="/")
result=first/Integer.parseInt(t1.getText());
t1.setText(result+"");
} if(a=="c")
t1.setText("");
}
}
Output:

EX NO:20
DATE:

Usage of Buttons, Labels, Text Components in Suitable Applications

Aim:

Procedure:

Coding:

importjava.awt.*;
importjava.applet.*;
importjava.awt.event.*;
/*<applet code="buttonsdemo" width=1100 height=690>
</applet>*/
public class buttonsdemo extends Applet implements ActionListener
{
Button b1,b2,b3,b4;
Label l1,l2,l3;
TextField t1,t2,t3;
Panel p1,p2,p3;
public void init()
{
l1=new Label("First Number");
l2=new Label("Second Number");
l3=new Label("Result");
t1=new TextField(5);
t2=new TextField(5);
t3=new TextField(6);
b1=new Button("Addition");
b2=new Button("Subtraction");
b3=new Button("Multiplication");
b4=new Button("Division");
p1=new Panel();
p2=new Panel();
p3=new Panel();
p1.add(l1);
p1.add(t1);
p1.add(l2);
p1.add(t2);
p1.add(l3);
p1.add(t3);
p2.add(b1);
p2.add(b2);
p2.add(b3);

p2.add(b4);
p1.setBackground(Color.magenta);
p2.setBackground(Color.orange);
p3.setLayout(new BorderLayout());
p3.add(BorderLayout.CENTER,p1);
p3.add(BorderLayout.SOUTH,p2);
add(p3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}
public void actionPerformed(ActionEventae)
{
if(ae.getActionCommand()=="Addition")
{
t3.setText(Integer.toString(Integer.parseInt(t1.getText())+
Integer.parseInt(t2.getText())));
}
if(ae.getActionCommand()=="Subtraction")
{
t3.setText(Integer.toString(Integer.parseInt(t1.getText())Integer.parseInt(t2.getText())));
}
if(ae.getActionCommand()=="Multiplication")
{
t3.setText(Integer.toString(Integer.parseInt(t1.getText())*
Integer.parseInt(t2.getText())));
}
if(ae.getActionCommand()=="Division")
{
t3.setText(Integer.toString(Integer.parseInt(t1.getText())/
Integer.parseInt(t2.getText())));
}
}

Output:

EX:NO:21
DATE:

Usage of RadioButtons, CheckBox, Choice List in Suitable Applications

Aim:

Procedure:

Coding:
importjava.awt.*;

importjava.awt.event.*;
importjava.applet.*;
/*<applet code="chk_rad" height=500 width=500>
</applet>*/
public class chk_rad extends Applet implements ItemListener
{
String str=" ";
String msg=" ";
String str1=" ";
Checkbox c1,c2,c3;
Checkbox cg1,cg2,cg3;
CheckboxGroupcbg;
Choice Subject;
public void init()
{
c1=new Checkbox("Morning");
c2=new Checkbox("Evenging");
c3=new Checkbox("Afternoon");
cbg=new CheckboxGroup();
cg1=new Checkbox("B.C.A",cbg,true);
cg2=new Checkbox("B.Sc(Ism)",cbg,false);
cg3=new Checkbox("B.Sc",cbg,false);
Subject=new Choice();
Subject.add("C");
Subject.add("C++");
Subject.add("JAVA");
Subject.add("VB");
Subject.add("Tally");
add(c1);
add(c2);
add(c3);
add(cg1);
add(cg2);
add(cg3);
add(Subject);

c1.addItemListener(this);
c2.addItemListener(this);
c3.addItemListener(this);
cg1.addItemListener(this);
cg2.addItemListener(this);
cg3.addItemListener(this);
Subject.addItemListener(this);
}
public void itemStateChanged(ItemEventie)
{
repaint();
}
public void paint(Graphics g)
{
if(c1.getState()==true)
str="Morning Section";
if(c2.getState()==true)
str="Evening Section";
if(c3.getState()==true)
str="Afternoon Section";
msg=cbg.getSelectedCheckbox().getLabel();
g.drawString("Department...",50,175);
g.drawString(msg+"Selected",75,200);
g.drawString("Lab Timing...",50,250);
g.drawString(str+"Selected",75,275);
str1=Subject.getSelectedItem();
g.drawString("Subject Selection...",50,325);
g.drawString(str1+"Selected",75,350);
}
}
Output:

You might also like