LIST
import java.awt.*;
import java.applet.*;
/*
<applet code="listdemo.class" width=400 height=400>
</applet>
*/
public class listdemo extends Applet
{
List ch1,ch2,ch3;
public void init()
{
ch1=new List();
ch2=new List(2);
ch3=new List(2,true);
ch1.add("mango");
ch1.add("apple");
ch1.add("grapes");
ch1.add("guava");
ch2.addItem("Internet");
ch2.addItem("Opera");
ch2.addItem("mozilla");
ch3.addItem("train");
ch3.addItem("bus");
ch3.addItem("car");
add(ch1);
add(ch2);
add(ch3);
}
}
COMBO BOX
import java.awt.*;
import java.applet.*;
/*
<applet code="combodemo.class" width=400 height=400>
</applet>
*/
public class combodemo extends Applet
{
Choice ch1,ch2,ch3;
Label s,s1;
public void init()
{ Choice ch=new Choice();
s=new Label("state");
ch1=new Choice();
s1=new Label("course");
ch2=new Choice(2);
ch1.add("mango");
ch1.add("apple");
ch1.add("grapes");
ch1.add("guava");
ch2.addItem("Internet");
ch2.addItem("Opera");
ch2.addItem("mozilla");
add(s);
add(ch1);
add(s1);
add(ch2);
}
}
TEXT AREA \
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*
<applet code="txtdemo.class" width=400 height=400>
</applet>
*/
public class txtdemo extends Applet implements ActionListener
{
String msg="";
int a,b1,r;
TextField t1,t2,t3;
Label s,s1,s2;
Button add,sub,mul,div;
char OP;
public void init()
{
//GridLayout gl=new GridLayout (1,2);
//setLayout(gl);
setBackground(Color.pink);
t1=new TextField(6);
t2=new TextField(6);
t3=new TextField(20);
s=new Label("First Number");
s1=new Label("Second Number");
s2=new Label("Result");
add=new Button("Add");
sub=new Button("Subtract");
mul=new Button("Multiply");
div=new Button("Divide");
add(s);
add(t1);
add(s1);
add(t2);
add(add);
add(sub);
add(mul);
add(div);
add(s2);
add(t3);
t1.addActionListener(this);
t2.addActionListener(this);
t3.addActionListener(this);
add.addActionListener(this);
sub.addActionListener(this);
mul.addActionListener(this);
div.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str =ae.getActionCommand();
char ch=str.charAt(0);
if (Character.isDigit(ch))
{ t1.setText(t1.getText()+str);
t2.setText(t2.getText()+str);}
else if (str.equals("Add"))
{
a=Integer.parseInt(t1.getText());
b1=Integer.parseInt(t2.getText());
OP='+';
t1.setText("");
t2.setText("");
}
else if (str.equals("Subtract"))
{
a=Integer.parseInt(t1.getText());
b1=Integer.parseInt(t2.getText());
OP='-';
t1.setText("");
t2.setText("");
}
else if (str.equals("Multiply"))
{
a=Integer.parseInt(t1.getText());
b1=Integer.parseInt(t2.getText());
OP='*';
t1.setText("");
t2.setText("");
}
else if (str.equals("Divide"))
{
a=Integer.parseInt(t1.getText());
b1=Integer.parseInt(t2.getText());
OP='/';
t1.setText("");
t2.setText("");
}
if (OP=='+')
r=a+b1;
else if (OP=='-')
r=a-b1;
else if (OP=='*')
r=a*b1;
else if (OP=='/')
r=a/b1;
t3.setText(""+r);
}
}
import java.awt.*;
import java.applet.*;
/*
<applet code="listdemo.class" width=400 height=400>
</applet>
*/
public class listdemo extends Applet
{
List ch1,ch2,ch3;
public void init()
{
ch1=new List();
ch2=new List(2);
ch3=new List(2,true);
ch1.add("mango");
ch1.add("apple");
ch1.add("grapes");
ch1.add("guava");
ch2.addItem("Internet");
ch2.addItem("Opera");
ch2.addItem("mozilla");
ch3.addItem("train");
ch3.addItem("bus");
ch3.addItem("car");
add(ch1);
add(ch2);
add(ch3);
}
}
COMBO BOX
import java.awt.*;
import java.applet.*;
/*
<applet code="combodemo.class" width=400 height=400>
</applet>
*/
public class combodemo extends Applet
{
Choice ch1,ch2,ch3;
Label s,s1;
public void init()
{ Choice ch=new Choice();
s=new Label("state");
ch1=new Choice();
s1=new Label("course");
ch2=new Choice(2);
ch1.add("mango");
ch1.add("apple");
ch1.add("grapes");
ch1.add("guava");
ch2.addItem("Internet");
ch2.addItem("Opera");
ch2.addItem("mozilla");
add(s);
add(ch1);
add(s1);
add(ch2);
}
}
TEXT AREA \
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*
<applet code="txtdemo.class" width=400 height=400>
</applet>
*/
public class txtdemo extends Applet implements ActionListener
{
String msg="";
int a,b1,r;
TextField t1,t2,t3;
Label s,s1,s2;
Button add,sub,mul,div;
char OP;
public void init()
{
//GridLayout gl=new GridLayout (1,2);
//setLayout(gl);
setBackground(Color.pink);
t1=new TextField(6);
t2=new TextField(6);
t3=new TextField(20);
s=new Label("First Number");
s1=new Label("Second Number");
s2=new Label("Result");
add=new Button("Add");
sub=new Button("Subtract");
mul=new Button("Multiply");
div=new Button("Divide");
add(s);
add(t1);
add(s1);
add(t2);
add(add);
add(sub);
add(mul);
add(div);
add(s2);
add(t3);
t1.addActionListener(this);
t2.addActionListener(this);
t3.addActionListener(this);
add.addActionListener(this);
sub.addActionListener(this);
mul.addActionListener(this);
div.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str =ae.getActionCommand();
char ch=str.charAt(0);
if (Character.isDigit(ch))
{ t1.setText(t1.getText()+str);
t2.setText(t2.getText()+str);}
else if (str.equals("Add"))
{
a=Integer.parseInt(t1.getText());
b1=Integer.parseInt(t2.getText());
OP='+';
t1.setText("");
t2.setText("");
}
else if (str.equals("Subtract"))
{
a=Integer.parseInt(t1.getText());
b1=Integer.parseInt(t2.getText());
OP='-';
t1.setText("");
t2.setText("");
}
else if (str.equals("Multiply"))
{
a=Integer.parseInt(t1.getText());
b1=Integer.parseInt(t2.getText());
OP='*';
t1.setText("");
t2.setText("");
}
else if (str.equals("Divide"))
{
a=Integer.parseInt(t1.getText());
b1=Integer.parseInt(t2.getText());
OP='/';
t1.setText("");
t2.setText("");
}
if (OP=='+')
r=a+b1;
else if (OP=='-')
r=a-b1;
else if (OP=='*')
r=a*b1;
else if (OP=='/')
r=a/b1;
t3.setText(""+r);
}
}
No comments:
Post a Comment