Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Java Applets

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Thanked 0 Times in 0 Posts

    Default Java Applets

    Hi, I am relatively new to applets, hence having some problems when it comes to handling event driven code.

    Below is a java applet code. All I want is when the button called "Example" is pressed, the three textfields, tf1, tf2 and tf3 should show the values 5000, 6 and 8. will someone please help, thanks for the time.

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

    public class money_time extends JApplet implements ActionListener{
    JTextField tf1, tf2, tf3, tf4;
    JLabel label1, label2, label3, label4;
    JButton b1, b2;

    public void init(){
    setLayout( new FlowLayout());
    label1 = new JLabel( " Enter deposit amount" );
    tf1 = new JTextField( 10 );
    label2 = new JLabel( " Enter interest rate" );
    tf2 = new JTextField( 10 );
    label3 = new JLabel( " Enter number of years" );
    tf3 = new JTextField( 10 );
    label4 = new JLabel( " Future Amount" );
    tf4 = new JTextField( 10 );
    b1 = new JButton( "Enter" );
    b1.addActionListener( this );
    b2 = new JButton( "Example" );
    b2.addActionListener( this );
    add(label1); add(label2); add(label3); add(label4);
    add(tf1); add(tf2); add(tf3); add(tf4);
    add(b1); add(b2);

    public void actionPerformed( ActionEvent ae ) {
    Object obj = ae.getSource( );

    String a = "5000", b = "6", c = "8";

    String st1 = tf1.getText();
    String st2 = tf2.getText();
    String st3 = tf3.getText();

    double p = Double.parseDouble(st1);
    double i = Double.parseDouble(st2);
    double n = Double.parseDouble(st3);

    double f = p*Math.pow(1+i/100, n);
    DecimalFormat formatter = new DecimalFormat("0.00");

    if (obj == b2){
    else if (obj == b1)

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,626 Times in 2,576 Posts

    Default Re: Java Applets

    Code moved out of introductions section.

    Please explain what your problem is. What have you tried and what happened?

    Please edit your post and wrap your code with code tags:
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Thanked 0 Times in 0 Posts

    Default Re: Java Applets

    Thanks for trying to help me. The problem I had was when I pressed the "Example" button, the three textfields, tf1, tf2 and tf3 did not show the values 5000, 6 and 8. I just realized that was becasue of the getText methods I had assigned did not let setText methods to be executed. I enclosed all of getText method with "Enter" button and put all setText method items enclosed in "Example" button and then I get the desired effect.

    BTW, is there a way to increase the height of a textfield?.

Similar Threads

  1. How to draw a houses using Java Applets and Awt?
    By Heizzer10 in forum Object Oriented Programming
    Replies: 4
    Last Post: October 31st, 2012, 04:08 AM
  2. mysql in java applets
    By micro kid in forum JDBC & Databases
    Replies: 7
    Last Post: June 11th, 2012, 06:40 AM
  3. How do I debug my Java applets to see what's going wrong?
    By diyaots in forum AWT / Java Swing
    Replies: 2
    Last Post: November 10th, 2011, 09:37 AM
  4. Learn applets in java
    By mohsendeveloper in forum Java Applets
    Replies: 2
    Last Post: June 25th, 2009, 02:50 PM