Preview:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code="LabTask36.class" width="700" height="200"> 
</applet>*/ 
public class LabTask36 extends Applet implements ActionListener 
{ 
 String str="";
 TextField t1,t2,t3;
 Button b1,b2,b3,b4,b5;
 Label l1,l2,l3;
public void init() 
 { 
 l1=new Label("Enter 1st value:");
add(l1);
 l2=new Label("Enter 2nd value:");
add(l2);
 l3=new Label("Result: ");
add(l3);
 t1=new TextField(10);
add(t1);
   t2=new TextField(10);

add(t2);

 t3=new TextField(10);

add(t3);

 b1=new Button("add");

 b2=new Button("sub");

 b3=new Button("mul");

 b4=new Button("div");

 b5=new Button("mod");

add(b1);

add(b2);

add(b3);

add(b4);

add(b5);

l1.setBounds(50,100,100,20);

l2.setBounds(50,140,100,20);

l3.setBounds(50,180,100,20);

t1.setBounds(200,100,100,20);

t2.setBounds(200,140,100,20);

t3.setBounds(200,180,100,20);

b1.setBounds(50,250,50,20);

b2.setBounds(110,250,50,20);

b3.setBounds(170,250,50,20);

b4.setBounds(230,250,50,20);
   b5.setBounds(290,250,50,20);

b1.addActionListener(this);

b2.addActionListener(this);

b3.addActionListener(this);

b4.addActionListener(this);

b5.addActionListener(this);

setLayout(null);

setVisible(true);

setSize(400,350);

setBackground(Color.black);

setForeground(Color.white);

 } 

public void paint(){} 

public void actionPerformed(ActionEvent e) 

 { 

str=e.getActionCommand();

double a=Double.parseDouble(t1.getText());

double b= Double.parseDouble(t2.getText());

if(str=="add") 

 { 

double sum=a+b;

t3.setText(""+sum);

 } 

else if(str=="sub")
  { 

double sub=a-b;

t3.setText(""+sub);

 } 

else if(str=="mul") 

 { 

doublemul=a*b;

t3.setText(""+mul);

 } 

else if(str=="div") 

 { 

double div=a/b;

t3.setText(""+div);

 } 

else if(str=="mod") 

 { 

int x=Integer.parseInt(t1.getText());

int y=Integer.parseInt(t2.getText());

int mod=x%y;

t3.setText(""+mod);

 } 

repaint();

 } 

}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter