Object3Test.java


/*Object3Test.java
This example uses an object to determine the product of two floats.*/
import java.applet.*;
import java.awt.*;

public class Object3Test extends Applet
{
	TextField num1Fld=new TextField(3);
	TextField num2Fld=new TextField(3);
	Button Calculate = new Button("Find Product");
	Object3 mult=new Object3();

	public void init()
	{
		add(new Label("Enter a number:"));  
		add(num1Fld);
		add(new Label("Enter another:"));  
		add(num2Fld);
		add(Calculate);
		
	}

	public boolean action(Event evt, Object obj)
	{
		
		Graphics g;
		Font original=getFont();
		setFont(new Font("TimesRoman", Font.ITALIC, 15));	
		
		mult.setX(Float.valueOf(num1Fld.getText()).floatValue());
		mult.setY(Float.valueOf(num2Fld.getText()).floatValue());
		mult.findProduct();
		g=getGraphics();
		g.setColor(Color.blue); // Control the color of your font.
		g.drawString("The product of "+mult.x+" and "+mult.y+"",5,100);
		g.drawString("is "+mult.p+"", 5,115);
		return true;
		
		}
}

/*====================================================
Object3.java
*/
import java.applet.*;
import java.awt.*;

public class Object3 extends Applet
{
	float x, y, p;
        
        //constructor method
	Object3()
	{	
		x=0;  y=0;  p=0;	
	}

	//methods section
        public void setX(float value)
	{	
		x=value;	
	}

	public void setY(float value)
	{	
		y=value;	
	}

	public void findProduct()
	{	
		p=(float)(x * y);	
	}
	
}


Output for Object3Test.java