You are on page 1of 18

Experiment No: .

04 Regd no: 06H71A0545

 Code the user-defined JavaBean


 Package the JavaBean.
 Load and test the Java-Bean.

Code the user-defined JavaBean


package sunw.demo.beansex;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
public class Click extends Canvas {
int Clickcount;
String sc;
public Click()
{
Clickcount=0;
sc="Clickcount:0";
setSize(100,100);
addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent me)
{
Clickcount++;
sc="count="+Clickcount;
repaint();
}
});
}
public void paint(Graphics g)
{
String msg="$"+Clickcount;
g.drawString(msg,10,10);
}
}

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

Package the JavaBean


1.Select the start->program->accessories->commandPrompt command to display the
commandPrompt window.
2.Compile the Userdefined JavaBean.The Click JavaBean is compiled using javac compiler of
Java.
The command to compile the UserDefined JavaBean is:
Javac Click.java
Java Click

3.create the Manifest file for the user-defined Click JavaBean.


Manifest-Version: 1.0

Name: sunw/demo/beansex/Click.class
Java-Bean: True

4. Save the Manifest file as MANIFEST.mf in the folder META-INF which is in jars directory
of beans.

5.Create Beansex.jar JAR file using following command:

Jar cfm c:\beans\jars\beansex.jar c:\jars\META-INF\MANIFEST.mf


c:\beans\demo\sunw\demo\beansex\*.class

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

Load and Test the JAVABEAN


The steps to load and test the user-defined JAVABEAN in the BDK environment are:
1.Load the JAR file for the userdefined JAVABEAN in the TOOLBOX window.
2.Test the JAVABEAN in the BEANBOX window.
To load the JAR file:
1.Select the File->loader command in the Beanbox window. This displays the Load beans
from JAR FILE dialog box.
2.Select the JAR file to open and click the open button.
Or
Select the start->program->accessories->commandPrompt command to display the
commandPrompt window
Go to beans->beanbox.Type run then your jar file will be automatically loaded into the
ToolBox.

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

AIM:
Create two Beans Trafic Light(implementer as a label with only three
dackground colors-Red,Green,Yellow) and Automobile (Implemented as a
TextBox which states its state/movement). The state of the Automobile should
depend on the following Light Transition Table.

Light Transition Automobile State


Red->Yellow Ready
Yellow->Green Move
Green->Red Stopped

package sunw.demo.beansex;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
public class TrafficSignal extends Canvas
{
public Color color;
int red,green,blue;
int flag=1;
public TrafficSignal()
{
setSize(100,200);
redcolorchange();
greencolorchange();
yellowcolorchange();
}
public void redcolorchange()
{
if(flag==1)
{
red=255;
green=0;

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

blue=0;
color=new Color(red,green,blue);
repaint();
}
}
public void yellowcolorchange()

{
if(flag==2)
{
red=255;
green=200;
blue=0;
color=new Color(red,green,blue);
repaint();
}
}
public void greencolorchange()
{
if(flag==3)
{
red=0;
green=255;
blue=0;
color=new Color(red,green,blue);
repaint();
}
}
public void paint(Graphics g)
{
g.drawOval(10,10,50,50);
g.drawOval(10,60,50,50);
g.drawOval(10,110,50,50);
if(flag==1)
{
g.setColor(color);
g.fillOval(10,10,50,50);
flag=2;
}
else if(flag==2)
{
g.setColor(color);
g.fillOval(10,60,50,50);
flag=3;
}

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

else if(flag==3)
{
g.setColor(color);
g.fillOval(10,110,50,50);
flag=1;
}
}
}

AIM:
Create a simple Bean with a label – which is the count of number of
clicks.Then create a BeanInfo class such that only the “count” property is
visible in the Property Window.

package sunw.demo.beansex;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
public class Click extends Canvas {
int Clickcount;
String sc;
public Click()
{
Clickcount=0;
sc="Clickcount:0";
setSize(100,100);
addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent me)
{
Clickcount++;
sc="count="+Clickcount;
repaint();
}
});
}
public void paint(Graphics g)
{
String msg="$"+Clickcount;
g.drawString(msg,10,10);
}
}

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

AIM:
Create a JavaBeans which gives the exchange value of INR(Indian
rupees) into equivalent American/Canadian/Australian Dollar value.

package sunw.demo.beansex;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
public class Convertor extends Canvas
{
public double Rupees;
public double Australiandoller;
public double Canadiandoller;
public double Americandoller;
public double amount=0;
public Convertor()
{
setSize(100,100);
Rupees=0.0;
Americandoller=1.0;
Australiandoller=1.0;
Canadiandoller=1.0;
American();
Canadian();
Australian();
}
public double getrupees()
{
return Rupees;
}
public void setrupees(double Rupees)
{
this.Rupees=Rupees;
}
public double getAmericandoller()

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

{
return Americandoller;
}
public void setAmericandoller(double
Americandoller)
{
this.Americandoller=Americandoller;
}

public double getAustraliandoller()


{
return Australiandoller;
}
public void setAustraliandoller(double Australiandoller)
{
this.Australiandoller=Australiandoller;
}
public double getCanadiandoller()
{
return Canadiandoller;
}
public void setCanadiandoller(double Canadiandoller)
{
this.Canadiandoller=Canadiandoller;
}
public void American()
{
amount=Rupees/Americandoller;
repaint();
}
public void Australian()
{
amount=Rupees/Australiandoller;
repaint();
}
public void Canadian()
{
amount=Rupees/Canadiandoller;
repaint();
}
public void paint(Graphics g)
{

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology
Experiment No: . 04 Regd no: 06H71A0545

g.drawString("$"+amount,10,10);
}
}

Devineni Venkata Ramana & Dr.Hima Sekhar


M I C College of Technology

You might also like