Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Java Tutorials


 

 

Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Application To Applet, Java Example Java Applet Applet Versus Application

User Comments
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl
  Blink   Furl   Simpy   Y! MyWeb 

;
 
Java Examples for Beginners
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (post your own) View All Comments Latest 10 Comments:

Hi!
I am trying to convert an application program to an applet and it keeps giving me errors. Can someone look at it and let me know what the problem is?
thanks.
heres' my source code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class LoanPay2 extends JApplet implements ItemListener
{
private JLabel amount, interest, months, payment, total;
private JTextField amountTF, interestTF, monthsTF, paymentTF,

totalTF;
private JButton calculate, reset;

public void init()
{
// Create the Title for the Window
//setTitle("Loan Payment");

// Set the Size of the Window
//setSize(300,300);

//Get the container
Container c = getContentPane();

// Set the Layout
c.setLayout(null);

// Create, Size, and Locate Labels and Text Fields
amount = new JLabel("Loan Amount");
amount.setSize(140,30);
amount.setLocation(10, 10);
amountTF = new JTextField(10);
amountTF.setSize(100,30);
amountTF.setLocation(150,10);

interest = new JLabel("Yearly Interest Rate");
interest.setSize(140,30);
interest.setLocation(10,50);
interestTF = new JTextField(10);
interestTF.setSize(100,30);
interestTF.setLocation(150, 50);

months = new JLabel("Number of Loan Months");
months.setSize(140,30);
months.setLocation(10, 90);
monthsTF = new JTextField(10);
monthsTF.setSize(100,30);
monthsTF.setLocation(150,90);

payment = new JLabel("Amount of Payment");
payment.setSize(140,30);
payment.setLocation(10, 170);
paymentTF = new JTextField(10);
paymentTF.setSize(100,30);
paymentTF.setLocation(150,170);

total = new JLabel("Total Payments");
total.setSize(100,30);
total.setLocation(10, 210);
totalTF = new JTextField(10);
totalTF.setSize(100,30);
totalTF.setLocation(150,210);

//Create Calculate Button
calculate = new JButton("Calculate");
calculate.addActionListener(this);
calculate.setSize(100, 30);
calculate.setLocation(30, 130);

//Create Reset Button
reset = new JButton("Reset");
reset.addActionListener(this);
reset.setSize(100,30);
reset.setLocation(150, 130);

//Place the Componenets in the Pane
c.add(amount);
c.add(amountTF);

c.add(interest);
c.add(interestTF);

c.add(months);
c.add(monthsTF);

c.add(calculate);
c.add(reset);

c.add(payment);
c.add(paymentTF);

c.add(total);
c.add(totalTF);

//Call method addWindowListener using an anonymous class.
this.addWindowListener(new WindowAdapter()
//{
// public void windowClosing(WindowEvent e)
// {
// System.exit(0);
//}
//}
);

//setVisible(true);
} //End of Constructor

public void actionPerformed(ActionEvent e)
{
//Get the string associated with the action being performed.
String str = e.getActionCommand();

//Decide which action to take, based on the first character.
switch(str.charAt(0))
{
case 'C':
//The calculate button was clicked.
evaluate();
break;

case 'R':
//The reset button was pressed.
zero();
break;
}
} // End of method actionPerformed.

private void zero()
{
amountTF.setText("");
interestTF.setText("");
monthsTF.setText("");
paymentTF.setText("");
totalTF.setText("");
} // End of method zero.

private void evaluate()
{
final char beep = '\u0007';
double payAmount;

try
{
double principle = Double.parseDouble(amountTF.getText());
double rate = Double.parseDouble(interestTF.getText());
double time = Double.parseDouble(monthsTF.getText());
payAmount = (principle*rate/12*Math.pow(rate/12+1,time)) /
(Math.pow(rate/12+1,time)-1);
paymentTF.setText(String.format("%.2f", payAmount));
payAmount *= time;
totalTF.setText(String.format("%.2f", payAmount));
}

catch (Exception e)
{
System.out.print(beep);
paymentTF.setText("input ERROR");
}
}


} //End of Applet.

Posted by sonya on Saturday, 02.28.09 @ 20:53pm | #85337

Ask programming questions?

 

 

Back to Tutorial
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name

 

 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.