import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class Summa1 extends Applet implements ActionListener{ TextField a=new TextField(2), b=new TextField(2), c=new TextField(2), d=new TextField(2), s=new TextField(10); Button b1=new Button(" = "); Label p1=new Label("/",Label.CENTER), p2=new Label("+",Label.CENTER), p3=new Label("/",Label.CENTER); public void init(){ add(a);add(p1);add(b);add(p2); add(c);add(p3);add(d);add(b1); add(s); b1.addActionListener(this); } public void actionPerformed(ActionEvent e){ s.setText(num(a)*num(d)+num(c)*num(b)+" / "+num(b)*num(d)); Graphics g=getGraphics(); g.setColor(Color.white); g.fillRect(40, 40, 200, 50); g.setColor(Color.black); if(num(b)==0 || num(d)==0){g.drawString("Division by ZERO !!!",50 ,70);} else{ g.drawString(num(a)+"", 50, 60); g.drawString(num(b)+"", 50, 80); g.drawString(num(c)+"", 90, 60); g.drawString(num(d)+"", 90, 80); // g.drawString(num(a)*num(d)+num(c)*num(b)+"", 130, 60); // g.drawString(num(b)*num(d)+"", 130, 80); g.drawString(num(a)+"*"+num(d)+"+"+num(c)+"*"+num(b), 130, 60); g.drawString(num(b)+"*"+num(d), 130, 80); g.drawLine(50, 65, 70, 65); g.drawLine(90, 65, 110, 65); g.drawLine(130, 65, 190, 65); g.drawString("+", 76, 70); g.drawString("=", 116, 70); } } int num(TextField tf){ return Integer.parseInt(tf.getText().trim()); } }