<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>text field in applet | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/text-field-in-applet/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Sun, 04 Oct 2009 14:49:29 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>Java applet program for calculator</title>
		<link>https://studentprojects.in/software-development/java/java-programs/applet/java-applet-program-for-calculator/</link>
					<comments>https://studentprojects.in/software-development/java/java-programs/applet/java-applet-program-for-calculator/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Sun, 04 Oct 2009 14:49:29 +0000</pubDate>
				<category><![CDATA[Applet programs]]></category>
		<category><![CDATA[java calculator]]></category>
		<category><![CDATA[calculator in java]]></category>
		<category><![CDATA[applet programe]]></category>
		<category><![CDATA[simple calculator]]></category>
		<category><![CDATA[grid layout]]></category>
		<category><![CDATA[text field in applet]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=886</guid>

					<description><![CDATA[<p>Write a Java program that works as a simple calculator. Use a grid layout to arrange buttons for the digits and for the + - * % operations.Add a text field to display the result.</p>
<p>The post <a href="https://studentprojects.in/software-development/java/java-programs/applet/java-applet-program-for-calculator/">Java applet program for calculator</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Write a Java program that works as a simple calculator. Use a grid layout to arrange buttons for the digits and for the + &#8211; * % operations. Add a text field to display the result.</p>
<pre lang="java" escaped="true" line="1">
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

/* 
<applet code="Cal" width=300 height=300>
</applet>
*/

public class Cal extends Applet
implements ActionListener
{
	String msg=" ";
	int v1,v2,result;
	TextField t1;
	Button b[]=new Button[10];
	Button add,sub,mul,div,clear,mod,EQ;
	char OP;
	public void init()
	{
		Color k=new Color(120,89,90);
		setBackground(k);
		t1=new TextField(10);
		GridLayout gl=new GridLayout(4,5);
		setLayout(gl);
		for(int i=0;i<10;i++)
		{
			b[i]=new Button(""+i);
		}
		add=new Button("add");
		sub=new Button("sub");
		mul=new Button("mul");
		div=new Button("div");
		mod=new Button("mod");
		clear=new Button("clear");
		EQ=new Button("EQ");
		t1.addActionListener(this);
		add(t1);
		for(int i=0;i<10;i++)
		{
			add(b[i]);
		}
		add(add);
		add(sub);
		add(mul);
		add(div);
		add(mod);
		add(clear);
		add(EQ);
		for(int i=0;i<10;i++)
		{
			b[i].addActionListener(this);
		}
		add.addActionListener(this);
		sub.addActionListener(this);
		mul.addActionListener(this);
		div.addActionListener(this);
		mod.addActionListener(this);
		clear.addActionListener(this);
		EQ.addActionListener(this);
	}

	public void actionPerformed(ActionEvent ae)
	{
		String str=ae.getActionCommand();
		char ch=str.charAt(0);
		if ( Character.isDigit(ch))
		t1.setText(t1.getText()+str);
		else
		if(str.equals("add"))
		{
			v1=Integer.parseInt(t1.getText());
			OP='+';
			t1.setText("");
		}
		else if(str.equals("sub"))
		{
			v1=Integer.parseInt(t1.getText());
			OP='-';
			t1.setText("");
		}
		else if(str.equals("mul"))
		{
			v1=Integer.parseInt(t1.getText());
			OP='*';
			t1.setText("");
		}
		else if(str.equals("div"))
		{
			v1=Integer.parseInt(t1.getText());
			OP='/';
			t1.setText("");
		}
		else if(str.equals("mod"))
		{
			v1=Integer.parseInt(t1.getText());
			OP='%';
			t1.setText("");
		}
		if(str.equals("EQ"))
		{
			v2=Integer.parseInt(t1.getText());
			if(OP=='+')
				result=v1+v2;
			else if(OP=='-')
				result=v1-v2;
			else if(OP=='*')
				result=v1*v2;
			else if(OP=='/')
				result=v1/v2;
			else if(OP=='%')
				result=v1%v2;
			t1.setText(""+result);
		}	
		if(str.equals("clear"))
		{
			t1.setText("");
		}
	}
}
</pre>
<p><strong>Output:</strong><br />
<figure id="attachment_885" aria-describedby="caption-attachment-885" style="width: 308px" class="wp-caption aligncenter"><img decoding="async" src="https://studentprojects.in/wp-content/uploads/2009/10/Java_calculator.jpg" alt="Java program base calculator output" title="Java program base calculator output" width="308" height="193" class="size-full wp-image-885" /><figcaption id="caption-attachment-885" class="wp-caption-text">Java program base calculator output</figcaption></figure></p><p>The post <a href="https://studentprojects.in/software-development/java/java-programs/applet/java-applet-program-for-calculator/">Java applet program for calculator</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/java/java-programs/applet/java-applet-program-for-calculator/feed/</wfw:commentRss>
			<slash:comments>66</slash:comments>
		
		
			</item>
	</channel>
</rss>
