Home Answers Viewqa Java-Beginners addActionListener(this) in java applets program or in java Frames program

 
 


venkateshmadisetty
addActionListener(this) in java applets program or in java Frames program
1 Answer(s)      a year ago
Posted in : Java Beginners

use of this keyword in addActionListener(this) in java applets program or in java Frames program.

View Answers

May 7, 2012 at 11:14 AM


The given code allowed the user to enter any number in the first textbox. Every time, when the user enters the number and click the button, its sum will get displayed in another textbox.

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

    public class SApplet extends Applet implements ActionListener { 
        TextField input,output;
        Label label1,label2; 
        Button b1;
        JLabel lbl; 
        int num, sum = 0;
        public void init(){ 
            label1 = new Label("please enter number : ");
            add(label1); 
            label1.setBackground(Color.yellow);
            label1.setForeground(Color.magenta);
            input = new TextField(5);
            add(input);
            label2 = new Label("Sum : ");
            add(label2); 
            label2.setBackground(Color.yellow); 
            label2.setForeground(Color.magenta);
            output = new TextField(20); 
            add(output);
            input.addActionListener( this );
            b1 = new Button("Add");
            add(b1);
            b1.addActionListener(this);
            lbl = new JLabel("This is the Swing Applet Example. ");
            add(lbl);
            setBackground(Color.yellow);

    output.addActionListener(this ); 
    }
    public void actionPerformed(ActionEvent ae){ 
        try{ 
     num = Integer.parseInt(ae.getActionCommand()); 
     num = Integer.parseInt(input.getText());
     sum = sum+num;
     input.setText("");
     output.setText(Integer.toString(sum));
     lbl.setForeground(Color.blue);
     lbl.setText("Output of the second Text Box : " + output.getText());
     } 
     catch(NumberFormatException e){ 
         lbl.setForeground(Color.red);
         lbl.setText("Invalid Entry!");
         }
         }
         }









Related Pages:
Applets
Java NotesApplets Why no applets in these notes These notes were... changed to applications. The only really portable applets are written in Java... because the lack of a content pane distorts the program. Java WebStart
java Frames - Java Beginners
java Frames  Hi friend, Thanks for your reply. Can i use frames in socket program.  Hi anita, I am sending you a link...://www.roseindia.net/java/network/client-socket-information.shtml Thanks
Applications and Applets
Applications and Applets       Now a days, Java is widely used for applications and applets. The code... using a Java interpreter. Whereas, A Java applet produces object code which
java applets - Java Beginners
applet to display clock without using swing or jframes 15.write a java program...java applets  1.write main method for display clock applet including... calculator using java codes?... 4.write a java application to open the file
Applications and Applets
Applications and Applets       Now a days, Java is widely used for applications and applets. The code... using a Java interpreter. Whereas, A Java applet produces object code which
Applets
Applets  Create an applet, on running which shows the following output. Source Java Output file Compiler .java javac .class JVM All the text within the circle and rectangles should be taken as parameters with names heading1
applets
Java Applet  when i performing the output as appletviewer.filename.java the applet window is opening and it shows that start applet not initialized. please give me solution for this problem.   just
Applets in Java
Applet is a Java program embedded within HTML pages. Java applets is compatible with almost all the web browsers like Mozilla Firefox, Google Chrome, Internet explorer, Netscape navigator and others that are java enabled. Applets
Finding Lost Frames - Java tutorial
Finding Lost Frames 2001-05-10 The Java Specialists' Newsletter [Issue 019] - Finding Lost Frames Author: Dr. Heinz M. Kabutz If you are reading... issue of "The Java(tm) Specialists' Newsletter". This newsletter is my
problem with addactionlistener on JComboBox - Java Beginners
problem with addactionlistener on JComboBox  ViewElements.java:225: expected jccourse.addActionListener(new ActionListener.... You can use addActionListener() on Combo Box in the following way: import
Free Java Applets
etc. These applets are Java program developed by different programmer... are Java program that runs on the web browser or applet viewer. Java applets are used... Free Java Applets      
Jav Applets - Applet
Jav Applets  I need to write a small payroll program, using applet, that provides a text field for the number of hours, a text field for the pay...*rate; t3.setText(Integer.toString(total)); } } 2)applet.html: Java
program
program  write a program different between to dates in terms of days in java
Applets - IDE Questions
Applets  Someone please help how to solve this JAVA programs.... B)program that will have the buttons one, two and three run from left to right along the top of the frame C) Program that tosses a coin several times
program
program  WAP a java program to form 1/2+3/4+5/6+7/8 series
program
program  explanation of program on extending thread class   Hi Friend, Please go through the following link: Java Threads Thanks
program
program  write a java program to input a no. and print wheather the no. is a special no or not. (special no. are those no whose factorial of the sum of digit of the no is same as the original
program
is working in Java department and salary is 10000". Instantiate the Employee class
Problem with display of images in applets - Applet
this program, the appletviewer window is showing no output (i.e. no image). I'm..., this); } } --------------------------------------- Display image in Java Applet... information. http://www.roseindia.net/java/example/java/applet
Java Program - Java Beginners
Java Program  Write a program to demonstrate use of Grid Layout. On a frame with grid layout place buttons labeled respectively with the letters...); buttons[i].setActionCommand(b[i]); buttons[i].addActionListener(new ActionListener
java program for
java program for   java program for printing documents,images and cards
frames - Java3D
frames  how can i create multiple frames in java?  Hi Friend, You can use JInternalFrame class to create multiple frames in java as we...("Multiple Frames"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE
need a java program - Java Beginners
need a java program  Draw a bar chart for the following data using frames Year: 2000 2001 2002 2003 2004 2005 TurnOver:7 8 4 5 9 12
Java Program
Java Program  A Java Program that print the data on the printer but buttons not to be printed
a Java program
a Java program    Write a Java program to print even numbers from 2 to 1024? Write a Java program to print ? My Name is Mirza? 100 times? Write a Java program to print Fibonacci Series? Write a Java program to reverse a number
java program
java program  write a program to print 1234 567 89 10
java program
java program  write java program for constructor,overriding,overriding,exception handling
java program
java program  write a java program to display array list and calculate the average of given array
java program
java program  how to write an addition program in java without using arithematic operator
java program
java program  write a java program to display array list and calculate the average of given array
Java Program
Java Program  java program to insert row in excel sheet after identifying an object
java program
java program  java program to implement the reflection of a particular class details like constructor,methods and fields with its modifiers
java program
java program  Write a program to demonstrate the concept of various possible exceptions arising in a Java Program and the ways to handle them.  ... in Java
APPLETS - Security
APPLETS  In java applets sun.misc is not working can any body help me for the alternate solution. while using new sun.misc.BASE64Encoder().encode(enc); i got runtime error... java.security.AccessControlException
java program
java program  write a java program to compute area of a circle.square,rectangle.triangle,volume of a sphere ,cylinder and perimeter of cube using method over riding
java program
java program  write a java program to compute area of a circle.square,rectangle.triangle,volume of a sphere ,cylinder and perimeter of cube using method over riding
java program
java program  write a program to create text area and display the various mouse handling events
java program
java program   Write a program to find the difference between sum of the squares and the square of the sums of n numbers
JAVA
addActionListener(this) in java applets program or in java Frames program  use of this keyword in addActionListener(this) in java applets program or in java Frames program.   The given code allowed the user to enter
java program
java program  Develop the program calculatePipeArea. It computes the surface area of a pipe, which is an open cylinder. The program accpets three values: the pipes inner radius, its length, and the thickness of its wall
java program
java program  . Write a program which performs to raise a number to a power and returns the value. Provide a behavior to the program so as to accept any type of numeric values and returns the results
Java program
Java program  Write a program which performs to raise a number to a power and returns the value. Provide a behavior to the program so as to accept any type of numeric values and returns the results
java program
java program  . Develop the program calculatePipeArea. It computes the surface area of a pipe, which is an open cylinder. The program accpets three values: the pipes inner radius, its length, and the thickness of its wall
program in java
program in java  write a reverse program in java using string buffer.the input and out put as follows. input- hi good mornig out put-ih doog ginrom
program in java
program in java  a program to develop a client, server application to satisfy the requests from multiple clients
program in java
program in java  a program to develop a client, server application to satisfy the requests from multiple clients
java program
java program   A B C D E F F E D C B A A B C D E E D C B A A B C D D C B A A B C C B A A B B A A A java program to display above triangle
java program
java program  write a program to create server and client such that server receives data from client using BuuferedReader and sends reply to client using PrintStream
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
Java Program
Java Program  I want to Write a program in JAVA to display to create a class called MATRIX using a two-dimensional array of integers. Perform the addition and subtraction of two matrices. Help me

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.