Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculation in Swing Applet

Status
Not open for further replies.

tbarnes2788

Programmer
Feb 26, 2004
7
US
I created this swing applet to balance my checking account but I can not get it to calculate. Here's the code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
//Create a Swing applet that will calculats the current balance of a
//checking account in a JTextField.
public class JCalculateBalance extends JApplet implements ActionListener
{
JLabel beginBal = new JLabel("beginning balance");
JLabel check = new JLabel("check amount");
JLabel deposit = new JLabel("deposit amount");
JButton calcButton = new JButton("Calculate");
JLabel EndBalResult = new JLabel ("Thank You");
JLabel totalResult = new JLabel("Thank You");
Font bigFont = new Font("TimesRoman",Font.ITALIC,24);

public void init()
{
Container con = getContentPane();
con.setLayout(new FlowLayout());
beginBal.setFont(bigFont);
con.add(beginBal);
con.add(check);
con.add(deposit);
con.add(calcButton);
calcButton.addActionListener(this);
con.add(EndBalResult);
con.add(totalResult);
}
public void start()
{
EndBalResult.setText("Your Current Balance Is");
totalResult.setText("Thank You");
repaint();
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source == calcButton)
{
String response = JOptionPane.showInputDialog(null, "Enter beginning balance");
double[]beginBal = {300};
double[]check = {100, 10, 40};
double[] deposit = {200, 60, 40};

double doublebalance = Double.parseDouble("300.00");
double doublecheck = Double.parseDouble("150.00");
double doubledeposit = Double.parseDouble("300.00");
double x = 0.0, a = 0;



EndBal = beginBal + deposit - check;

EndBalResult.getText("$" + EndBal);
totalResult.setText("currentBalance");
}
}
}

 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
//Create a Swing applet that will calculats the current balance of a
//checking account in a JTextField.
public class JCalculateBalance extends JApplet implements ActionListener
{
JLabel beginBal = new JLabel("beginning balance");
JLabel check = new JLabel("check amount");
JLabel jLDeposit = new JLabel("deposit amount"); //
JButton calcButton = new JButton("Calculate");
JLabel EndBalResult = new JLabel ("Thank You");
JLabel totalResult = new JLabel("Thank You");
Font bigFont = new Font("TimesRoman",Font.ITALIC,24);

public void init()
{
Container con = getContentPane();
con.setLayout(new FlowLayout());
beginBal.setFont(bigFont);
con.add(beginBal);
con.add(check);
con.add(jLDeposit); //
con.add(calcButton);
calcButton.addActionListener(this);
con.add(EndBalResult);
con.add(totalResult);
}
public void start()
{
EndBalResult.setText("Your Current Balance Is");
totalResult.setText("Thank You");
repaint();
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source == calcButton)
{
String response = JOptionPane.showInputDialog(null, "Enter beginning balance");
double beginBal = 300;
double check = 100;
double deposit = 200;
System.out.println(Double.parseDouble(response)); //
double doublebalance = Double.parseDouble("300.00"); // what is the array for ?
double doublecheck = Double.parseDouble("150.00"); //
double doubledeposit = Double.parseDouble("300.00"); //
double x = 0.0, a = 0;


double EndBal = 0.0; //
EndBal = beginBal + deposit - check;

EndBalResult.setText("$" + EndBal); //
totalResult.setText("currentBalance");
}
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top