Java Record
Java Record
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
</applet>
*/
TextField tf;
// boolean firstop;
boolean found;
double mem,te,result;
String msg,temp;
result=0.0;
msg=" ";
tf=new TextField(20);
setBackground(Color.white);
b[0]=new Button("0");
b[1]=new Button("1");
b[2]=new Button("2");
b[3]=new Button("3");
b[4]=new Button("4");
b[5]=new Button("5");
b[6]=new Button("6");
b[7]=new Button("7");
b[8]=new Button("8");
b[9]=new Button("9");
b[10]=new Button("ce");
b[11]=new Button("ac");
b[12]=new Button("m");
b[13]=new Button("mr");
b[14]=new Button("mc");
b[15]=new Button("mp");
b[16]=new Button("sqrt");
b[17]=new Button("bs");
b[18]=new Button("+");
b[19]=new Button("-");
b[20]=new Button("/");
b[21]=new Button("*");
b[22]=new Button("=");
for(int i=0;i<23;i++)
add(b[i]);
}
// firstop=true;
//clearText=true;
add(tf);
for(int j=0;j<23;j++)
b[j].addActionListener(this);
/*b[1].addActionListener(this);
b[2].addActionListener(this);
b[3].addActionListener(this);
b[4].addActionListener(this);
b[5].addActionListener(this);
b[6].addActionListener(this);
b[7].addActionListener(this);
b[8].addActionListener(this);
b[9].addActionListener(this);
b[10].addActionListener(this);
b[11].addActionListener(this);
b[12].addActionListener(this);
b[13].addActionListener(this);
b[14].addActionListener(this);
b[15].addActionListener(this);
b[16].addActionListener(this);
b[17].addActionListener(this);
b[18].addActionListener(this);
b[19].addActionListener(this);
b[20].addActionListener(this);
b[21].addActionListener(this);
b[22].addActionListener(this);*/
tf.addActionListener(this);
String str=ae.getActionCommand();
found=false;
for(int k=0;k<=22&&!found;k++)
if(ae.getSource()==b[k])
found=true;
switch(k)
case 0:
msg=msg+0;
tf.setText(msg);
break;
}
case 1:
msg=msg+1;
tf.setText(msg);
break;
case 2:
msg=msg+2;
tf.setText(msg);
break;
case 3:
msg=msg+3;
tf.setText(msg);
break;
case 4:
msg=msg+4;
tf.setText(msg);
break;
}
case 5:
msg=msg+5;
tf.setText(msg);
break;
case 6:
msg=msg+6;
tf.setText(msg);
break;
case 7:
msg=msg+7;
tf.setText(msg);
break;
case 8:
msg=msg+8;
tf.setText(msg);
break;
case 9:
{
msg=msg+9;
tf.setText(msg);
break;
case 10:
msg=" ";
tf.setText(msg);
break;
case 11:
msg=" ";
mem=0.0;result=0.0;temp=" ";te=0;
tf.setText("0");
break;
case 12:
mem=Double.parseDouble(msg);
te=mem;
break;
}
case 13:
msg=String.valueOf(te);
tf.setText(msg);
msg=" ";
break;
case 14:
mem=0.0;
temp=" ";
te=0.0;
break;
case 15:
double t=te+Double.parseDouble(msg);
result=t;
msg=String.valueOf(result);
tf.setText(" "+result);
break;
case 16:
{
double s=Double.parseDouble(msg);
s=Math.sqrt(s);
msg=String.valueOf(s);
tf.setText(msg);
break;
case 17:
if(msg.length()>0)
msg=msg.substring(0,msg.length()-1);
tf.setText(msg);
break;
case 18:
temp=str;
result=Double.parseDouble(msg);
msg=" ";
tf.setText(msg);
break;
case 19:
temp=str;
result=Double.parseDouble(msg);
msg=" ";
tf.setText(msg);
break;
case 20:
temp=str;
result=Double.parseDouble(msg);
msg=" ";
tf.setText(msg);
break;
case 21:
temp=str;
result=Double.parseDouble(msg);
msg=" ";
tf.setText(msg);
break;
case 22:
if(str.equals("="))
{
if(temp.equals("+"))
result=(result+Double.parseDouble(msg));
msg=String.valueOf(result);
tf.setText(msg);
else if(temp.equals("-"))
result=result-Double.parseDouble(msg);
msg=String.valueOf(result);
tf.setText(msg);
else if(temp.equals("*"))
result=result*Double.parseDouble(msg);
msg=String.valueOf(result);
tf.setText(msg);
else if(temp.equals("/"))
result=(result/Double.parseDouble(msg));
msg=String.valueOf(result);
tf.setText(msg);
break;
BorderInsetEx
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
</applet>
*/
String msg="";
Button c1,c2,c3,c4;
TextArea c5;
setLayout(f);
c1 = new Button("Chummaaaaa");
c2 = new Button("Vetttteeeeeeee");
c3 = new Button("Borrrrreeeeeee");
c4 = new Button("Mudiyala..");
add(c1,BorderLayout.NORTH);
add(c2,BorderLayout.EAST);
add(c3,BorderLayout.SOUTH);
add(c4,BorderLayout.WEST);
add(c5,BorderLayout.CENTER);
c1.addActionListener(this);
c2.addActionListener(this);
c3.addActionListener(this);
c4.addActionListener(this);
//c5.addActionListener(this);
repaint();
BorderLayoutEx
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
</applet>
*/
String msg="";
Checkbox c1,c2,c3,c4,c5;
setLayout(f);
c1 = new Checkbox("Chummaaaaa",null,true);
c2 = new Checkbox("Vetttteeeeeeee");
c3 = new Checkbox("Borrrrreeeeeee");
c4 = new Checkbox("Mudiyala..");
add(c2,BorderLayout.EAST);
add(c3,BorderLayout.SOUTH);
add(c4,BorderLayout.WEST);
add(c5,BorderLayout.CENTER);
c1.addItemListener(this);
c2.addItemListener(this);
c3.addItemListener(this);
c4.addItemListener(this);
c5.addItemListener(this);
repaint();
g.drawString(msg,6,80);
g.drawString(msg,6,100);
g.drawString(msg,6,140);
Editor
import java.awt.*;
import java.awt.event.*;
import java.io.*;
Button btn;
Panel p;
editor e;
super(title);
this.e = e;
p = new Panel();
t1 = new TextField(10);
t2 = new TextField(10);
p.add(new Label("Find"));
p.add(t1);
p.add(new Label("Replace"));
p.add(t2);
p.add(btn);
add(p);
btn.addActionListener(this);
addWindowListener(new MyWindowAdapter(this));
if(ae.getSource() == btn)
{
String msg = e.ta.getText();
if(msg.indexOf(t1.getText()) != -1)
e.ta.setText(msg);
this.setVisible(false);
TextField t1;
Button btn;
Panel p;
editor e;
super(title);
this.e = e;
p = new Panel();
t1 = new TextField(10);
p.add(btn);
add(p);
btn.addActionListener(this);
addWindowListener(new MyWindowAdapter(this));
if(ae.getSource() == btn)
int strt;
e.ta.select(strt, strt+t1.getText().length());
this.setVisible(false);
TextArea ta;
editor(String title)
super(title);
ta = new TextArea();
setMenuBar(mb);
mb.add(file);
mb.add(edit);
add(ta);
mi[i].addActionListener(this);
addWindowListener(new MyWindowAdapter(this));
String s = ae.getActionCommand();
if(s.equals("New"))
ta.setText("");
else if(s.equals("Open"))
{
FileDialog fd = new FileDialog(this, "Open...", FileDialog.LOAD);
fd.setVisible(true);
if(fd.getFile() != null)
/*
try
byte b;
String h = String.valueOf((char)b);
ta.append(h);
catch(Exception e) { }*/
try
String temp;
ta.setText("");
ta.append(temp+"\n");
fr.close();
}
catch(Exception e) { }
else if(s.equals("Save"))
fd.setVisible(true);
if(fd.getFile() != null)
/*
try
fo.write(ta.getText().getBytes());
fo.close();
catch(Exception e) { }
*/
try
fw.close();
catch(Exception e) { }
else if(s.equals("Exit"))
dispose();
System.exit(0);
else if(s.equals("Cut"))
clpbrd = ta.getSelectedText();
sb.delete(strt, ta.getSelectionEnd());
ta.setText(sb.substring(0));
ta.setCaretPosition(strt);
else if(s.equals("Copy"))
clpbrd = ta.getSelectedText();
else if(s.equals("Paste"))
{
ta.insert(clpbrd, strt);
else if(s.equals("Replace"))
fnr.setSize(200, 100);
fnr.setVisible(true);
else if(s.equals("Find"))
f.setSize(200, 100);
f.setVisible(true);
mf.setSize(600, 500);
mf.setVisible(true);
}
}
editor e;
findnreplace fnr;
find f;
if(we.getSource() == e)
e.setVisible(false);
System.exit(0);
fnr.setVisible(false);
else if(we.getSource() == f)
f.setVisible(false);
Ex1
import java.io.*;
import java.util.*;
class Mobile
Mobile()
name = null;
model = null;
cost = 0;
color = null;
memory = null;
this(15000,"BLUE","2GB");
this.name = name;
this.model = model;
}
this.cost = cost;
this.color = color;
this.memory = memory;
Mobile(String name, String model, double cost, String color, String memory)
this.name = name;
this.model = model;
this.cost = cost;
this.color = color;
this.memory = memory;
void display()
class Ex1
a.display();
b.display();
c.display();
FlowLayoutEx
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
</applet>
*/
String msg="";
Checkbox c1,c2,c3,c4;
setLayout(f);
c1 = new Checkbox("Chummaaaaa",null,true);
c2 = new Checkbox("Vetttteeeeeeee");
c3 = new Checkbox("Borrrrreeeeeee");
c4 = new Checkbox("Mudiyala..");
add(c1);
add(c2);
add(c3);
add(c4);
c1.addItemListener(this);
c2.addItemListener(this);
c3.addItemListener(this);
c4.addItemListener(this);
repaint();
g.drawString(msg,6,80);
g.drawString(msg,6,100);
g.drawString(msg,6,120);
msg = c4.getLabel()+" : " +c4.getState();
g.drawString(msg,6,140);
Font
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
</applet>
*/
Choice typesoffont;
String msg,msg1,msg2;
int msg3,msg4,msg5,msg6;
int ascent,descent;
typesoffont=new Choice();
String FontList[];
GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
FontList=ge.getAvailableFontFamilyNames();
for(int i=0;i<FontList.length;i++)
{
msg=FontList[i];
typesoffont.add(msg);
add(typesoffont);
typesoffont.addItemListener(this);
String s=typesoffont.getSelectedItem();
Graphics g=this.getGraphics();
this.setFont(f);
msg1=f.getName();
msg2=f.getFamily();
msg3=f.getSize();
FontMetrics fm=g.getFontMetrics();
msg4=fm.getAscent();
msg5=fm.getDescent();
msg6=fm.getHeight();
repaint();
STUDENTFORM
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
</applet>*/
Label name;
Label reg;
Label sex;
Label deg;
Label br;
Label yrst;
Label dob;
Label address;
Label email;
Label hec;
TextField name1;
TextField reg1;
TextField email1;
CheckboxGroup sex1;
Checkbox male;
Checkbox female;
Choice yrst1;
Choice date;
Choice month,bt,d;
Choice year;
TextArea address1;
TextArea hec1;
TextArea details;
Button submit;
name=new Label("Name:");
sex=new Label("Sex:");
deg=new Label("Degree:");
br=new Label("Branch:");
address=new Label("Address:");
name1=new TextField(20);
reg1=new TextField(20);
d=new Choice();
d.add("B.Tech");
d.add("M.Tech");
bt=new Choice();
bt.add("ICT");
bt.add("CSE");
bt.add("IT");
bt.add("IBT");
bt.add("MECH");
bt.add("CIVIL");
email1=new TextField(20);
sex1=new CheckboxGroup();
male=new Checkbox("Male",sex1,true);
female=new Checkbox("Female",sex1,false);
yrst1=new Choice();
date=new Choice();
month=new Choice();
year=new Choice();
yrst1.add("2005");
yrst1.add("2006");
yrst1.add("2007");
yrst1.add("2008");
yrst1.add("2009");
yrst1.add("2010");
yrst1.add("2011");
yrst1.add("2012");
yrst1.add("2013");
date.add("1");
date.add("2");
date.add("3");
date.add("4");
date.add("5");
date.add("6");
date.add("7");
date.add("8");
date.add("9");
date.add("10");
date.add("11");
date.add("12");
date.add("13");
date.add("14");
date.add("15");
date.add("16");
date.add("17");
date.add("18");
date.add("19");
date.add("20");
date.add("21");
date.add("22");
date.add("23");
date.add("24");
date.add("25");
date.add("26");
date.add("27");
date.add("28");
date.add("29");
date.add("30");
date.add("31");
month.add("1");
month.add("2");
month.add("3");
month.add("4");
month.add("5");
month.add("6");
month.add("7");
month.add("8");
month.add("9");
month.add("10");
month.add("11");
month.add("12");
year.add("1988");
year.add("1989");
year.add("1990");
year.add("1991");
year.add("1992");
year.add("1993");
year.add("1994");
year.add("1995");
year.add("1996");
address1=new TextArea();
hec1=new TextArea();
details=new TextArea();
submit=new Button("Submit");
add(name);add(name1);
add(reg);add(reg1);
add(sex);add(male);add(female);
add(deg);add(d);
add(br);add(bt);
add(yrst);add(yrst1);
add(dob);add(date);add(month);add(year);
add(address);add(address1);
add(email);add(email1);
add(hec);add(hec1);
add(submit);
add(details);
name1.addActionListener(this);
reg1.addActionListener(this);
email1.addActionListener(this);
submit.addActionListener(this);
yrst1.addItemListener(this);
date.addItemListener(this);
month.addItemListener(this);
year.addItemListener(this);
male.addItemListener(this);
female.addItemListener(this);
d.addItemListener(this);
bt.addItemListener(this);
{repaint();}
{repaint();}
{String msg1,msg2,msg3,msg4,msg5;
details.setText(msg1+msg2+msg3+msg4+msg5);
}
}
Gpaint
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
</applet> */
CheckboxMenuItem red,blue;
brush(String title)
super(title);
setMenuBar(mbar);
MenuItem d1,d2,d3,d4,d5,d6;
draw.add(d1=new MenuItem("LINE"));
draw.add(d2=new MenuItem("CIRCLE"));
draw.add(d3=new MenuItem("SQUARE"));
draw.add(d4=new MenuItem("-"));
MenuItem s1,s2,s3;
sub.add(s1=new MenuItem("Circle"));
sub.add(s2=new MenuItem("Square"));
draw.add(sub);
draw.add(d5=new MenuItem("-"));
draw.add(d6=new MenuItem("Close"));
mbar.add(draw);
mbar.add(col);
d1.addActionListener(this);
d2.addActionListener(this);
d3.addActionListener(this);
d4.addActionListener(this);
d5.addActionListener(this);
d6.addActionListener(this);
s1.addActionListener(this);
s2.addActionListener(this);
red.addItemListener(this);
blue.addItemListener(this);
blue.setState(true);
String arg=ae.getActionCommand();
if(arg.equals("LINE"))
mg="Line";
else if(arg.equals("CIRCLE"))
mg="Circle";
else if(arg.equals("SQUARE"))
mg="Square";
else if(arg.equals("Circle"))
mg="Fillc";
else if(arg.equals("Square"))
mg="Fills";
else
mg="Close";
repaint();
if(red.getState())
g.setColor(Color.red);
blue.setState(false);
else if(blue.getState())
g.setColor(Color.blue);
red.setState(false);
}
else
red.setState(false);
blue.setState(false);
g.setColor(Color.black);
if(mg=="Line")
g.drawLine(150,150,200,200);
else if(mg=="Circle")
g.drawOval(0,0,200,200);
else if(mg=="Square")
g.drawRect(100,100,200,200);
if(mg=="Fillc")
g.fillOval(150,150,200,200);
else if(mg=="Fills")
g.fillRect(100,100,200,200);
if(mg=="Close")
setVisible(false);
brush br;
this.br=bru;
br.setVisible(false);
Frame f;
f.setSize(300,300);
f.setVisible(true);
f.setVisible(true);
f.setVisible(false);
}
}
GridLayoutEx
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
</applet>
*/
String msg="";
Button c1,c2,c3,c4;
Button[] b;
TextArea c5;
setLayout(f);
b = new Button[10];
c1 = new Button("Chummaaaaa");
c2 = new Button("Vetttteeeeeeee");
c3 = new Button("Borrrrreeeeeee");
c4 = new Button("Mudiyala..");
add(c1);
add(c2);
add(c3);
add(c4);
for(int i=0;i<10;i++)
add(b[i]);
c1.addActionListener(this);
c2.addActionListener(this);
c3.addActionListener(this);
c4.addActionListener(this);
}
repaint();
DEPARTMENT
import java.io.*;
import java.util.*;
class Dept
String deptname;
void dept(String s)
deptname=s;
void show()
String name,address;
int regno,yr;
name=a;
address=b;
regno=c;
yr=d;
void sdisplay()
System.out.println("Address is"+address);
System.out.println("reg no"+regno);
System.out.println("year of joining"+yr);
int m1,m2,m3;
m1=a;
m2=b;
m3=c;
int tot,avg;
String grade;
tot=m1+m2+m3;
avg=(tot)/3;
if(avg>=85)
grade="S";
}
else if(avg>85&&avg<=75)
grade="A";
else if(avg>75&&avg<=65)
grade="B";
else if(avg>65&&avg<=55)
grade="D";
else
grade="F";
void display()
System.out.println("m1=\t"+m1);
System.out.println("m2=\t"+m2);
System.out.println("m3=\t"+m3);
System.out.println("total=\t"+tot);
System.out.println("grade=\t"+grade);
}
}
String staff_name;
int id,dateofjoinin;
staff_name=x;
id=a;
dateofjoinin=b;
String qual,skills,area_of_intrest;
qual=a;
skills=b;
area_of_intrest=c;
System.out.println("staff name"+staff_name);
System.out.println("Id "+id);
System.out.println("date of joining:"+dateofjoinin);
System.out.println("qual "+qual);
System.out.println("skills "+skills);
String certification,expertise;
int yrs_of_exp;
certification=m;
expertise=n;
yrs_of_exp=p;
System.out.println("date of joining"+dateofjoinin);
System.out.println("certification"+certification);
System.out.println("years of experience"+yrs_of_exp);
System.out.println("Expertise "+expertise);
}
class College
int ch,a;
int x,y,m1,m2,m3,e,f,g;
String s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16;
String st,st1;
st=din.readLine();
ch=Integer.parseInt(st);
st1=din.readLine();
if(ch==1)
System.out.println("student");
st1=din.readLine();
System.out.println("Enter Name:");
s1=din.readLine();
System.out.println("Enter Address");
s2=din.readLine();
System.out.println("Enter Reg.no");
s3=din.readLine();
x=Integer.parseInt(s3);
System.out.println("Enter Year");
s4=din.readLine();
y=Integer.parseInt(s4);
r.getstudentdetails(s1,s2,x,y);
r.sdisplay();
s5=din.readLine();
m1=Integer.parseInt(s5);
s6=din.readLine();
m2=Integer.parseInt(s6);
s7=din.readLine();
m3=Integer.parseInt(s7);
r.getmarkdetails(m1,m2,m3);
r.computegrade();
r.display();
else if(ch==2)
System.out.println("Staff");
st=d.readLine();
a=Integer.parseInt(st);
if(a==1)
System.out.println("teaching staff");
s11=d.readLine();
System.out.println("Enter id:");
s12=d.readLine();
e=Integer.parseInt(s12);
s13=d.readLine();
f=Integer.parseInt(s13);
t.getdata(s11,e,f,st1);
System.out.println("Enter Qualification");
s8=d.readLine();
System.out.println("Enter Skills");
s9=d.readLine();
s10=d.readLine();
t.getpersonaldetails(s8,s9,s10,s11);
t.display();
}
if(a==2)
System.out.println("non-teaching staff");
s11=d.readLine();
System.out.println("Enter id:");
s12=d.readLine();
e=Integer.parseInt(s12);
s13=d.readLine();
f=Integer.parseInt(s13);
n.getdata(s11,e,f,st1);
System.out.println("Enter certification:");
s14=d.readLine();
System.out.println("Enter Expertise:");
s15=d.readLine();
s16=d.readLine();
g=Integer.parseInt(s16);
n.inputdata(s14,s15,g);
n.showdata();
}
}
vehicle
import java.io.*;
class Vehicle
String name,service_station_name;
int model_no,price;
name=a;
service_station_name=b;
model_no=c;
price=d;
void display()
System.out.print("Name is:"+name);
{
int x,discount=5;
void calculate()
x=(price*discount)/100;
void disp()
System.out.print("\ndiscount is:\t"+discount);
String s1,s2,s3,s4;
int a,b;
System.out.print("\nEnter name:");
s1=din.readLine();
s2=din.readLine();
System.out.print("\nEnter model_no:");
s3=din.readLine();
a=Integer.parseInt(s3);
System.out.print("\nEnter price:");
s4=din.readLine();
b=Integer.parseInt(s4);
ob.get(s1,s2,a,b);
ob.display();
ob.calculate();
ob.disp();
INTERFACEMAINLAB
import java.io.*;
interface plumber
void unplugdrain();
interface electrician
void changebulb();
class Human
String name;
void HumanName(String s)
name=s;
void name()
void name()
void name()
class Methods
int ch;
String st,st1;
DataInputStream din=new DataInputStream(System.in);
st1=din.readLine();
ch=Integer.parseInt(st1);
st=din.readLine();
if(ch==1)
un.HumanName(st);
un.name();
un.unplugdrain();
un.changebulb();
else if(ch==2)
no.HumanName(st);
no.name();
no.unplugdrain();
no.changebulb();
else
in.name();
in.unplugdrain();
interfaceprelab
import java.io.*;
interface inter1
interface inter2
int a=20,b=30,c=40,d;
System.out.println("marks in a:"+a);
System.out.println("marks in b:"+b);
System.out.println("marks in c:"+c);
}
public void meth2()
d=a+b+c;
System.out.println("total:"+d);
void grade()
System.out.println("grade is:A");
class inter
t.meth1();
t.meth2();
t.grade();
KEYEVE
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*<applet code="keyeve" height=600 width=500>
</applet>*/
int mx=10,my=10;
addKeyListener(this);
requestFocus();
setBackground(Color.red);
showStatus("Key down");
setBackground(Color.blue);
showStatus("Key up");
}
setBackground(Color.green);
msg+=ke.getKeyChar();
repaint();
g.drawString(msg,mx,my);
LOGIN
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
<applet code="Login"
height=300
width=300 >
</applet>*/
{
String v1,v2,st1;
add(l1);
add(t1);
add(l2);
add(t2);
add(b1);
add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
st1=ae.getActionCommand();
repaint();
{
v1=t1.getText();
v2=t2.getText();
t2.setEchoChar('*');
if(st1.equals("okay"))
if(v2.equals("sastra"))
else
g.drawString("failed",100,100);
if( st1.equals("cancel"))
t1.setText("");
t2.setText("");
THREADS
import java.io.*;
import java.lang.*;
class Fact implements Runnable
Thread t1;
int n=10;
int i,fact;
try
for(i=1;i<=n;i++)
fact=1;
for(int j=1;j<=i;j++)
fact=fact*j;
Thread.sleep(1000);
catch( InterruptedException e )
e.printStackTrace();
}
class SumofNos implements Runnable
Thread t2;
int n=10;
int i,sum;
try
for(i=1;i<=n;i++)
sum=0;
for(int j=1;j<=i;j++)
sum+=j;
Thread.sleep(1000);
catch( InterruptedException e )
e.printStackTrace();
}
class FiveTable implements Runnable
Thread t3;
int n=10;
int i,pdt;
try
for(i=1;i<=n;i++)
pdt=5*i;
System.out.println("5x"+i+"="+pdt);
Thread.sleep(1000);
catch( InterruptedException e )
e.printStackTrace();
class ThreadTest
{
public static void main(String args[])
//try
//{
T1.start();
T1.suspend();
T2.start();
T1.resume();
//T1.stop();
//T1.join();
System.out.println("Thread T1 is "+T1.isAlive());
T3.start();
//}
/*catch(InterruptedException e)
}*/
}
MYCAR
import java.awt.*;
import java.applet.*;
/*
</applet>
*/
Thread t;
Color maroon;
int x=0,stx=20,sty=150;
boolean test=true;
setForeground(Color.blue);
setBackground(maroon);
g.drawRoundRect(stx+x,sty+20,200,30,10,10);
g.fillOval(stx+20+x,sty+40,20,20);
g.fillOval(stx+160+x,sty+40,20,20);
g.drawLine(stx+50+x,sty,stx+150+x,sty);
g.drawLine(stx+50+x,sty,stx+20+x,sty+20);
g.drawLine(stx+150+x,sty,stx+180+x,sty+20);
t=new Thread(this);
t.start();
while(test)
try
repaint();
Thread.sleep(200);
x = x+10;
if(x>400)
x=5;
catch(Exception e)
{}
}
}
PRETHREAD
int i;
Thread t=Thread.currentThread();
thread()
System.out.println("First thread:"+t);
t.start();
try
for(i=0;i<5;i++)
System.out.println("First thread:"+i);
Thread.sleep(2000);
catch(InterruptedException e)
{
System.out.println("Interrupt");
System.out.println("Exit1");
class prethread
int j;
new thread();
try
for(j=0;j<5;j++)
System.out.println("Main thread:"+j);
Thread.sleep(2000);
catch(InterruptedException e)
System.out.println("Interrupted");
}
System.out.println("ExitM");
SHAPES
import java.lang.*;
import java.io.*;
class shape
double x;
double y;
String st;
st=din.readLine();
x=Integer.parseInt(st);
st=din.readLine();
y=Integer.parseInt(st);
void area(){}
}
void area()
double a;
a=x*y;
System.out.println("area of rectangle="+a);
void area()
double a;
a=(x*y)/2;
System.out.println("area of triangle="+a);
class dnd
int choice;
String k;
System.out.println("enter choice\n1.rectangle\n2.triangle");
k=br.readLine();
choice=Integer.parseInt(k);
shape s;
if(choice==1)
s=r;
s.get();
s.area();
else
s=t;
s.get();
s.area();
TEXT EDIT
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
MenuBar mb;
Menu file,edit;
MenuItem ne,save,open,exit;
MenuItem copy,cut,paste,find,replace;
TextArea ta;
String cpText="";
NotePad()
mb = new MenuBar();
setMenuBar(mb);
ne = new MenuItem("New");
file.add(ne);
file.add(open);
file.add(save);
file.add(exit);
edit.add(cut);
edit.add(copy);
edit.add(paste);
edit.add(find);
edit.add(replace);
mb.add(file);
mb.add(edit);
ne.addActionListener(this);
open.addActionListener(this);
save.addActionListener(this);
exit.addActionListener(this);
cut.addActionListener(this);
copy.addActionListener(this);
paste.addActionListener(this);
find.addActionListener(this);
replace.addActionListener(this);
ta = new TextArea(10,100);
add(ta);
addWindowListener(new MyWinAda(this));
setSize(300,300);
setVisible(true);
if(src == exit)
System.exit(1);
cpText = ta.getSelectedText();
{
ta.insertText(cpText,ta.getSelectionStart());
// ta.insert(cpText,ta.getCaretPosition());
System.out.println("\n"+ta.getSelectionStart());
System.out.println(ta.getSelectionEnd());
System.out.println(ta.getCaretPosition());
System.out.println(ta.getRows());
System.out.println(ta.getColumns());
cpText = ta.getSelectedText();
ta.replaceRange("",ta.getSelectionStart(),ta.getSelectionEnd());
NotePad txt;
MyWinAda(NotePad t)
{
txt = t;
txt.setVisible(false);
System.exit(1);
new NotePad();