1.string Extraction Coding
1.string Extraction Coding
STRING EXTRACTION
CODING:
import java.io.*;
import java.io.DataInputStream;
class tamil1
{
public static void main(String args[])
{
String Str1=new String();
String Str2=new String();
int m=0,n=0;
DataInputStream in=new DataInputStream(System.in);
try
{
System.out.println("Enter the string:");
Str1=in.readLine();
System.out.println("String is:"+Str1);
System.out.println("Enter no of character to be extracted from string:");
m=Integer.parseInt(in.readLine());
System.out.println("Enter starting Intex:");
n=Integer.parseInt(in.readLine());
}
catch(Exception e)
{
System.out.println("I/O error");
}
Str2=Str1.substring(n,(m+n));
System.out.println("Extracted string is:"+Str2);
}
}
OUTPUT:
2. MULTIPLE INHERITANCE USING INTERFACE
CODING:
import java.io.*;
interface Area
{
float compute(float x,float y);
}
class Rectangle implements Area
{
public float compute(float x,float y)
{
return(x*y);
}
}
class Triangle implements Area
{
public float compute(float x,float y)
{
return(x*y/2);
}
}
class tamil2
{
public static void main(String args[])
{
Rectangle rect=new Rectangle();
Triangle tri=new Triangle();
Area area;
area=rect;
System.out.println("Area of rectangle="+area.compute(1,2));
area=tri;
System.out.println("Area of triangle="+area.compute(10,2));
}
}
OUTPUT:
3. PAY OUT OF BOUNCE
CODING:
import java.io.*;
class cheque extends Exception
{
cheque()
{
String S;
System.out.println("SORRY YOUR CHEQUE IS DISHONOURED");
}
}
public class tamil3
{
public static void main(String p[])throws IOException
{
DataInputStream d=new DataInputStream(System.in);
int bal,wd;
System.out.println("****************");
System.out.println("PAY OUT BOUNCE");
System.out.println("****************");
System.out.println();
System.out.println("Enter your amt balance");
bal=Integer.parseInt(d.readLine());
System.out.println("Enter the withdrawl amount:");
wd=Integer.parseInt(d.readLine());
if(wd>=bal)
{
System.out.println();
new cheque();
System.out.println();}
else
{
System.out.println();
System.out.println("your cheque is passed!");
System.out.println();
}
}
}
OUTPUT:
4.MULTI THREADING
CODING:
import java.io.*;
class S extends Thread
{
int i,m;
public void run()
{
for(i=1;i<=5;i++)
{
m=7*i;
System.out.println("7"+"*"+i+"="+m);
}
}
}
class F extends Thread
{
int m,i;
public void run()
{
for(i=1;i<=5;i++)
{
m=5*i;
System.out.println("5"+"*"+i+"="+m);
}
}
}
class T extends Thread
{
int m,i;
public void run()
{
for(i=1;i<=5;i++)
{
m=13*i;
System.out.println("13"+"*"+i+"="+m);
}
}
}
public class tamil4
{
public static void main(String args[])
{
System.out.println("********");
System.out.println("PRIORITIES OF THREAD");
System.out.println("********");
S t1=new S();
F t2=new F();
T t3=new T();
t1.setPriority(10);
t2.setPriority(5);
t3.setPriority(1);
t1.start();
t2.start();
t3.start();
}
}
OUTPUT:
5.DRAWING SHAPES USING APPLET
CODING:
import java.awt.*;
import java.applet.*;
public class tamil5 extends Applet
{
public void paint(Graphics g)
{
int a[]={45,20,65,70,85};
int b[]={50,65,75,95,57};
int n=5;
g.drawLine(0,12,30,12);
g.drawOval(30,180,60,40);
g.setColor(Color.red);
g.fillOval(30,180,60,40);
g.drawRect(30,110,60,30);
g.setColor(Color.green);
g.fillRect(30,110,60,30);
g.drawPolygon(a,b,n);
g.setColor(Color.pink);
g.fillPolygon(a,b,n);
g.drawRect(250,100,70,70);
g.setColor(Color.blue);
g.fillRect(250,100,70,70);
g.drawRoundRect(250,180,100,90,50,50);
g.setColor(Color.yellow);
g.fillRoundRect(250,180,100,90,50,50);
} }
//<applet code=tamil5.class width=1000 height=1000>
//</applet>
OUTPUT:
6.FRAMES TO DISPLAY PERSONAL DETAILS
CODING:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class tamil6 extends Applet implements ActionListener
{
Label l1,l2,l3,l4;
TextField t1,t2,t3,t4;
Button b1,b2;
public void init()
{
setForeground(Color.black);
l1=new Label("Name");
l2=new Label("Street");
l3=new Label("City");
l4=new Label("Pin");
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
t4=new TextField(10);
b1=new Button("My Details");
b2=new Button("Clear");
add(l1);
add(l2);
add(l3);
add(l4);
add(t1);
add(t2);
add(t3);
add(t4);
add(b1);
add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void paint(Graphics g)
{
Font f1=new Font("Arial",Font.ITALIC+Font.BOLD,30);
g.setFont(f1);
g.setColor(Color.red);
g.drawString("WELCOME",10,30);
l1.setLocation(50,50);
t1.setLocation(100,50);
l2.setLocation(50,100);
t2.setLocation(100,100);
l3.setLocation(50,150);
t3.setLocation(100,150);
l4.setLocation(50,200);
t4.setLocation(100,200);
b1.setLocation(100,300);
b2.setLocation(200,300);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==b1)
{
t1.setText("karthik");
t2.setText("5th Street");
t3.setText("tirupur");
t4.setText("641603");
}
if(e.getSource()==b2)
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
}
}
}
//<applet code=tamil6.class width=500 height=500>
//</applet>
OUTPUT:
7. MULTIPLE SELECTION LIST
CODING:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
Label l1;
List c1;
String S[];
int i;
for(int i=0;i<5;i++)
S[i]=" ";
c1=new List(4,true);
c1.add("Audi");
c1.add("BMW");
c1.add("Jaguare");
c1.add("Lamborhini");
c1.add("Porsche");
add(l1);
add(c1);
c1.addItemListener(this);
if(e.getSource()==c1)
S=c1.getSelectedItems();
repaint();
} }
int y=300,x=200;
y=y+20;
for(int i=0;i<S.length;i++)
g.drawString(S[i],x,y);
y=y+10;
}}}
//</applet>
OUTPUT:
8.FRAME CREATION
CODING:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
String s1,s2,s3,s4;
Label l1,l2,l3,l4;
TextField t1,t2,t3;
TextArea t4;
Button b1,b2;
public tamil8()
l1=new Label("NAME:");
l2=new Label("AGE:");
l3=new Label("QUALIFICATION:");
l4=new Label("ADDRESS:");
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
t4=new TextArea(05,20);
b1=new Button("OK");
b2=new Button("Clear");
setLayout(new FlowLayout(FlowLayout.LEFT));
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t4);
add(b1);
add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
addWindowListener(new n());
setBackground(Color.blue);
setForeground(Color.red);
String Str=a.getActionCommand();
if(Str.equals("OK"))
s1="Name:"+t1.getText();
s2="Age:"+t2.getText();
s3="Qualification:"+t3.getText();
s4="Address:"+t4.getText();
else
t1.setText(" ");
t2.setText(" ");
t3.setText(" ");
t4.setText(" ");
repaint();
g.drawString(s1,220,200);
g.drawString(s2,220,220);
g.drawString(s3,220,240);
g.drawString(s4,220,260);
z.setVisible(true);
z.setSize(1000,600);
}
class n extends WindowAdapter
System.exit(0);
//</applet>
OUTPUT:
9.MENU BAR CREATION
CODING:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.applet.*;
TextArea textarea;
Submenu1.add(item);
menu1.add(Submenu1);
menu2.add(item3);
menu2.add(item4);
menu2.add(item5);
menubar.add(menu1);
menubar.add(menu2);
Component C=this;
C=C.getParent();
((Frame)C).setMenuBar(menubar);
textarea=new TextArea(10,30);
setLayout(new BorderLayout());
add("Center",textarea);
String arg=evt.getActionCommand();
if(arg.equals("Help Topics"))
repaint();
} } }
//</applet>
OUTPUT:
10.MOUSE EVENT
CODING:
import java.awt.*;
import java.awt.event.*;
Label l1;
tamil10()
setLayout(new FlowLayout());
add(l1);
addMouseListener(this);
addWindowListener(new w());
System.exit(0);
}}
l1.setText("MouseReleased");
l1.setText("MousePressed");
l1.setText("MouseExited");
l1.setText("MouseEntered");
l1.setText("MouseClicked");
w.setVisible(true);
w.setSize(300,500);
} } }
//</applet>
OUTPUT:
11. SHAPES
CODING:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
MouseListener, MouseMotionListener
int x=0,y=0;
addMouseListener(this);
addMouseMotionListener(this);
showStatus("x="+m.getX()+"y="+m.getY());
x=m.getX();
y=m.getY();
repaint();
}
g.drawRect(x,y,170,170);
g.setColor(Color.red);
g.fillRect(x,y,170,170);
g.drawOval(x,y+180,180,180);
g.setColor(Color.green);
g.fillOval(x,y+180,180,180);
g.drawRect(x+220,y+180,150,150);
g.setColor(Color.blue);
g.fillRect(x+220,y+180,150,150);
g.drawOval(x+220,y,160,160);
g.setColor(Color.yellow);
g.fillOval(x+220,y,160,160);
};
//</applet>
OUTPUT:
12. APPENDING TEXT TO EXISTING FILE
CODING:
import java.io.*;
class File
try
String S;
S=d1.readLine();
out.write(S);
out.close();
catch(Exception e)
System.out.println("Error");
}
OUTPUT: