java applet problem 1 Answer(s) 3 years and 4 months ago
Posted in : Applet
i was doing a program using java applet. I want to make a simple calculator. So i added four labels,textboxes. And 6 buttons for add,multiply,divide,minus and a clear and exit button to clear the textboxes and to exit from the applet respectively.Now i want to display a message when the user clicks the add button after entering the nos in the textboxes. And the this will have to change everytime the user clicks in the various buttons. Suppose i hv entered four nos in the textboxes and i pressed the Add button then a message that 'the addition of four nos is' should be displayed. And i click the minus button then a message that Subtraction of four nos is' should be displayed. It means that a string should always change its content depending upon the action performed by the user. Please help me to solve this. Thanks.
public class Calculator extends Applet implements ActionListener{ TextField text1,text2,text3,text4; Label l1,l2,l3,l4; Label lab; Panel p; String Add, Subtract,Multiply,Divide,Clear,Exit; public void init(){
text1 = new TextField(12); text2= new TextField(12); text3 = new TextField(12); text4 = new TextField(12); l1=new Label("Enter Number 1:"); l2=new Label("Enter Number 2:"); l3=new Label("Enter Number 3:"); l4=new Label("Enter Number 4:"); lab=new Label(); p=new Panel(new GridLayout(1,3)); Panel p1=new Panel(new GridLayout(7,2)); Panel p2=new Panel(new GridLayout(1,1)); Button add = new Button("Add"); Button sub = new Button("Subtract"); Button mul = new Button("Multiply"); Button div = new Button("Divide"); Button clear = new Button("Clear"); Button exit = new Button("Exit"); add.addActionListener(this); sub.addActionListener(this); mul.addActionListener(this); div.addActionListener(this); clear.addActionListener(this); exit.addActionListener(this); p1.add(l1); p1.add(text1); p1.add(l2); p1.add(text2); p1.add(l3); p1.add(text3); p1.add(l4); p1.add(text4); p1.add(add); p1.add(sub); p1.add(mul); p1.add(div); p1.add(clear); p1.add(exit); p2.add(lab); p.add(p1); p.add(p2); add(p); } public void actionPerformed(ActionEvent e){ String value1=text1.getText(); int num1=Integer.parseInt(value1); String value2=text2.getText(); int num2=Integer.parseInt(value2); String value3=text3.getText(); int num3=Integer.parseInt(value3); String value4=text4.getText(); int num4=Integer.parseInt(value4); Button source = (Button)e.getSource(); if(source.getLabel() == "Add"){ int cal=num1+num2+num3+num4; lab.setText("Addition of four numbers is: "+cal); } if(source.getLabel() == "Subtract"){ int cal=num1-num2-num3-num4; lab.setText("Subtraction of four numbers is: "+cal); } if(source.getLabel() == "Multiply"){ int cal=num1*num2*num3*num4; lab.setText("Multiplication of four numbers is: "+cal); } if(source.getLabel() == "Divide"){ int cal=num1/num2; lab.setText("Division of two numbers is: "+cal); } if(source.getLabel() == "Clear"){ text1.setText(""); text2.setText(""); text3.setText(""); text4.setText("");
} if(source.getLabel() == "Exit"){ } } }
Thanks
Related Pages:
applet problem - Applet applet problem How can I create a file in client side by a javaapplet . Surely it will need a signed applet .But how can a signed applet create a file in the client side
java applet problem - Applet javaapplet problem i was doing a program using javaapplet. I want... and to exit from the applet respectively.Now i want to display a message when...*;
import java.awt.*;
public class Calculator extends Applet implements
Problem in show card in applet. Problem in show card in applet. The following link contained the card demo with applet.
http://www.roseindia.net/java/java... On Run as JavaApplet then only show the Applet, not show any one card,hence any
Problem with display of images in applets - Applet
, this);
}
}
---------------------------------------
Display image in JavaApplet... information.
http://www.roseindia.net/java/example/java/applet...Problem with display of images in applets Hi all,
When I run
how to run applet - Applet
://www.roseindia.net/java/example/java/applet/
http://www.roseindia.net/java/example/java/applet/FirstApplet.shtml
Hope that it will be helpful for you.Even... in applet program. this is executed successfully with appletviewer command
>
applet servlet communication - Applet
into WebRoot it is working. So my problem is when I made some changes in any java...();
}
}
}
3)Call this applet with the html file.
JavaApplet Demo...applet servlet communication Can anybody tell me applet - servlet
problem with applet plugin - Applet problem with applet plugin hello friends,
iam using Eclipse IDE. i created one applet and i want to plugin that applet into webpage.. when i am...-->com.ezsoft.applets.Upload.java
please friends how can i resolve that problem
Applet
Applet Draw the class hierarchy of an Applet class. Also explain how to set background and forground colors in java
applet
applet what is applet in java
An applet is a small program that can be sent along with a Web page to a user. Java applets can perform... the following link:
Applet Tutorials
Applet
Applet Write a Javaapplet that drwas a line between 2 points. The co-ordinates of 2 points should be passed as parametrs from html file. The color of the line should be red
unable to see the output of applet. - Applet
://www.roseindia.net/java/example/java/applet/FirstApplet.html
but the problem...unable to see the output of applet. Sir,
I was going through the following tutorial
http://www.roseindia.net/java/example/java/applet
Applet run with appletviewer but not in browser, any code problem. Applet run with appletviewer but not in browser, any code problem. Hi,My problem is when I am running my applet in appletviewer index.html, Its work... the 52 cards will be show in browser as by "appletviewer" and run as "javaapplet"
I
problem of writing to a local file ( JApplet ) - Applet problem of writing to a local file ( JApplet ) Dear All,
I want to program a guestbook using java applets but now I have
problem of writing to a file from JApplet.
it is working without any problem if i run the program using
applet - Applet
in JavaApplet.",40,20);
}
}
2) Call this applet with html code...:
http://www.roseindia.net/java/example/java/applet/
Thanks.... Hi Friend,
Try the following code:
1)Create an applet
Swing - Applet
Swing Hello,
I am creating a swing gui applet, which is trying... on in order to retrieve the result.
The problem i have is that i think the solution... information on swing visit to :
http://www.roseindia.net/java/example/java
Applet - Applet
,
AppletApplet is java program that can be embedded into HTML pages. Java applets... in details to visit....
http://www.roseindia.net/java/example/java/applet...Applet what is the concept of applet?
what is different between
applet - Applet
*;
import java.awt.*;
public class CreateTextBox extends Applet implements... information,visit the following link:
http://www.roseindia.net/java/example/java/applet/
Thanks
Applet - Applet
------------------------");
g.drawString("Demo of JavaApplet Window Event Program");
g.drawString("Java...Applet Namaste, I want to create a Menu, the menu name is "Display... java.awt.event.*;
public class menu2frame extends Applet implements WindowListener
Java GUI - Applet Java GUI HELLO,
i am working on java chat server, i add... to help in solving the problem :
import java.awt.GridLayout;
import... but not resolve my prob.
dear friend, i add JFrame Form in java package and put
java applet - Applet java applet wants to creat address bar on my javaapplet. Hi
Applet don't provide a facility to create a address bar directly. You just create a text box. In this text box if you enter any http address
loading Java Applet - Applet
loading Java Applet Hi,
I use the archive tag to download my applet into the Browser
It takes too long to load. Can I do it in several steps... control the loading within the applet?
thanks
Java Applet JavaApplet How to add Image in JavaApplet? what is getDocumentBase
java applet - Applet java applet I want to close applet window which is open by another button of applet program. plz tell me! Hi Friend,
Try...://www.roseindia.net/java/example/java/applet/
Thanks
java - Applet
java how to connect database table with scrollbar in javaapplet
java - Applet
java how to connect database table with scrollbar in javaapplet
java - Applet
java what is applet? Hi Friend,
Please visit the following link:
http://www.roseindia.net/java/example/java/applet/
Thanks
applet program code - Applet applet program code hello sir,
i did't get the code for below problem... please help me...
1.An applet program to draw a line graph for y=2x+5.[for suitable values of x & y
Java applet Java applet What tags are mandatory when creating HTML to display an applet
Java applet Java applet How do I go from my applet to another JSP or HTML page
java applet java applet If i insert in database from applet this work, but from applet.html don't
integration of webcam - Applet
integration of webcam Hello sir,
I have a small problem...*;
public class JavaCam extends Applet implements Runnable{
boolean boolean...){
trace("Image get exception:"+e.toString());
showStatus("Problem getting
Java Applet Java Applet Hi,
What is JavaApplet and how it can be useful in development of Java programs?
Can anyone tell me the url to learn JavaApplet?
Thanks
Hi,
See the tutorial at: Applications and Applets
Thanks
applet Question applet Question Write a javaapplet to display a circle in a rectangle
applet question applet question Write a javaapplet to display a rectangle inside a circle
applet question applet question Write a javaapplet to display atriangle inside a circle
What is Applet? - Applet
. Applet viewer is a command line program to run Java applets. It is included... any further, lets see what an applet is?http://www.roseindia.net/java/java-introduction/javatools/java_applet_viewer.shtmlThanks
applet running but no display - Applet
strDefault = "Hello! JavaApplet.";
public void paint(Graphics g) {
String...applet running but no display Hai,
Thanks for the post. I have... from a client, the page appears with a blank applet part (just whitescreen
java - Applet
java how to communicate to my servlet through applet.
 ... this information to the servlet in the normal way.
The applet pretends... is concerned, the applet is just another HTTP client.
For more infomation
Applet query - Applet
link:
http://www.roseindia.net/java/example/java/applet/
Thanks...Applet query i want to knw d complete detail of why does applet... with their container.It runs under the control of a Java-capable browser.The java-capable browser
java applet javaapplet I want code to implement
(1) user will enter how many nodes
(2)it should allow that no. of clicks and
circle should be displayed at that
position
JavaThread "AWT-EventQueue-176 - Applet
of sudden. How to prevent Browser from crashing and solve the problem of dumps...
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_05-b05 mixed mode)
# Problematic frame...: [0x018a0000,0x019a0000), sp=0x0199f550, free space=1021k
Native frames: (J=compiled Java
java - Applet
java i have button browse button in my applet form.when i click on browse button i have to go to file storage box(what ever files stored in my... in the mail).i have display that file path in my applet form.am learner please send me
methods in the applet - Applet
(Graphics g)
{
g.drawString(m,10,10);
}
}
The init() method used in the javaapplet is simular to the contructor defined in a java application. The purpose...;
public class applet1 extends Applet
{
String m;
public void init
java - Applet
java 1.An applet program to draw a line graph for y=2x+5.[for suitable values of x & y]
2. An applet program to draw following shapes
(1)cone... java.applet.Applet;
public class CubeExample extends Applet {
Stroke
drawing shapes in applet - Applet
drawing shapes in applet hi,
i need a single applet prgm which... java.applet.Applet;
public class CubeExample extends Applet {
Stroke... Applet {
public void paint (Graphics g){
Graphics2D ga = (Graphics2D)g