Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 132,125 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,999 people online right now. Registration is fast and FREE... Join Now!




a java based GUI for calculating simple interest

 
Reply to this topicStart new topic

a java based GUI for calculating simple interest, creating a graphical user interface

kalonji
post 10 Oct, 2008 - 11:02 AM
Post #1


New D.I.C Head

*
Joined: 10 Oct, 2008
Posts: 2

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class InterestCalcApplet extends Applet implements ActionListener {
TextField principalField, rateField, numYearsField;

double simpleInterest = 0;
double amount = 0;
double principal = 0;
double numYears = 0;
double rate = 0;

public void init()
{
principalField = new TextField (6);
rateField = new TextField (6);
numYearsField = new TextField (6);
Label principalLabel = new Label ("Principal ");
Label rateLabel = new Label ("Rate (%) ");
Label numYearsLabel = new Label ("Time (in years) ");
Button calcButton = new Button ("Calculate");

add (principalLabel);
add (principalField);
add (rateLabel);
add (rateField);
add (numYearsLabel);
add (numYearsField);
add (calcButton);

calcButton.addActionListener (this);
}


public void actionPerformed (ActionEvent e)
{
String principalString = principalField.getText ();

principalString = principalString.trim ();

Double principalDouble = new Double (principalString);

principal = principalDouble.doubleValue ();

String numYearsString = numYearsField.getText ();
numYearsString = numYearsString.trim ();
Double numYearsDouble = new Double (numYearsString);
numYears = numYearsDouble.doubleValue ();

rate = new Double (rateField.getText().trim()).doubleValue();

simpleInterest = (principal * rate * numYears) / 100;
amount = principal + simpleInterest;
repaint();
}
public void paint (Graphics g)
{
g.drawString ("The simple interest and amount after " + numYears + " years", 60,100);
g.drawString (" Simple Interest: " + simpleInterest, 60,120);
g.drawString (" Total amount: " + amount, 60,140);
}
}








User is offlineProfile CardPM

Go to the top of the page

JeroenFM
post 10 Oct, 2008 - 11:49 AM
Post #2


D.I.C Head

Group Icon
Joined: 30 Jun, 2008
Posts: 182



Thanked 9 times

Dream Kudos: 100
My Contributions


Welcome to DIC! Please use code tags the next time you post, include your question in your post, mention any errors you have, so we can help you.

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.



java

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class InterestCalcApplet extends Applet implements ActionListener {
TextField principalField, rateField, numYearsField;

double simpleInterest = 0;
double amount = 0;
double principal = 0;
double numYears = 0;
double rate = 0;

public void init()
{
principalField = new TextField (6);
rateField = new TextField (6);
numYearsField = new TextField (6);
Label principalLabel = new Label ("Principal ");
Label rateLabel = new Label ("Rate (%) ");
Label numYearsLabel = new Label ("Time (in years) ");
Button calcButton = new Button ("Calculate");

add (principalLabel);
add (principalField);
add (rateLabel);
add (rateField);
add (numYearsLabel);
add (numYearsField);
add (calcButton);

calcButton.addActionListener (this);
}


public void actionPerformed (ActionEvent e)
{
String principalString = principalField.getText ();

principalString = principalString.trim ();

Double principalDouble = new Double (principalString);

principal = principalDouble.doubleValue ();

String numYearsString = numYearsField.getText ();
numYearsString = numYearsString.trim ();
Double numYearsDouble = new Double (numYearsString);
numYears = numYearsDouble.doubleValue ();

rate = new Double (rateField.getText().trim()).doubleValue();

simpleInterest = (principal * rate * numYears) / 100;
amount = principal + simpleInterest;
repaint();
}
public void paint (Graphics g)
{
g.drawString ("The simple interest and amount after " + numYears + " years", 60,100);
g.drawString (" Simple Interest: " + simpleInterest, 60,120);
g.drawString (" Total amount: " + amount, 60,140);
}
}

User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/21/08 11:22AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month