AbdulFathaah

smile

Aug 14th, 2025 (edited)
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import java.applet.Applet;
  2. import java.awt.event.*;
  3. import java.awt.*;
  4. /*<applet code="smile"width="300" height="400"></applet>*/
  5.  
  6. public class smile extends Applet implements ActionListener {
  7.     Button ha, sa;
  8.     int f = 0;
  9.  
  10.     public void init() {
  11.         setBackground(Color.LIGHT_GRAY);
  12.         ha = new Button("happy");
  13.         sa = new Button("sad");
  14.         add(ha);
  15.         add(sa);
  16.         ha.addActionListener(this);
  17.         sa.addActionListener(this);
  18.     }
  19.  
  20.     public void actionPerformed(ActionEvent ae) {
  21.         String s = ae.getActionCommand();
  22.         if (s.equals("happy"))
  23.             f = 1;
  24.         else
  25.             f = 2;
  26.  
  27.         repaint();
  28.     }
  29.  
  30.     public void paint(Graphics g) {
  31.  
  32.         g.setColor(Color.YELLOW);
  33.         g.fillOval(50, 50, 200, 200);
  34.         g.setColor(Color.BLACK);
  35.         g.drawOval(50, 50, 200, 200);
  36.         g.fillOval(90, 100, 20, 20);
  37.         g.fillOval(190, 100, 20, 20);
  38.         if (f == 1) {
  39.             g.drawArc(100, 130, 100, 50, 0, -180);
  40.         } else if (f == 2) {
  41.             g.drawArc(100, 170, 100, 50, 0, 150);
  42.         }
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment