INTEREST CALCULATION USING APPLET

AIM:
            To write a applet program to design label box and button to calculate simple interest
Algorithm:
Step 1: start the process.
Step 2: import the applet header files AWT classes it support for                                          window based graphics interface.
Step 3: next import statements in applet packages which contains class                                applets.
Step 4: design the screen with label boxes and buttons.
Step 5: add the action listener interface event which is to do action performed.
Step 6: use the required formula to calculate the simple interest.
Step 7: display the result in the screen using drawing method.
Step 8: stop the program.

PROGRAM

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code="ex" width=400 height=200>
</applet>*/
public class ex extends Applet implements ActionListener
{
String str="THE AMOUNT IS";
float amount;
Button b1;
Label l1,l2,l3;
TextField t1,t2,t3;
public void init()
{

setBackground(Color.magenta);
setForeground(Color.blue);

l1=new Label("PRINCIPAL");
t1=new TextField(6);
l2=new Label("RATE ");
t2=new TextField(6);
l3=new Label("YEAR");
t3=new TextField(6);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
b1=new Button("CALCULATE");
add(b1);
b1.addActionListener(this);
}
public  void actionPerformed(ActionEvent e)
{
int pri=Integer.parseInt(t1.getText().trim());
int year=Integer.parseInt(t2.getText().trim());
int rate=Integer.parseInt(t3.getText().trim());
amount=(pri*year*rate)/100;
repaint();
}
public void paint(Graphics g)
{
Font font=new Font("Monotype corsiva",Font.BOLD,30);
g.setFont(font);
FontMetrics fm=g.getFontMetrics();
g.setColor(Color.GREEN);
g.drawString(" THE AMOUNT   "+amount,40,100);
}
}

1 comments:

Anonymous said...

: Main method not found in class ex, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
i got this error