Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.applet.Applet;
- import java.awt.event.*;
- import java.awt.*;
- /*<applet code="smile"width="300" height="400"></applet>*/
- public class smile extends Applet implements ActionListener {
- Button ha, sa;
- int f = 0;
- public void init() {
- setBackground(Color.LIGHT_GRAY);
- ha = new Button("happy");
- sa = new Button("sad");
- add(ha);
- add(sa);
- ha.addActionListener(this);
- sa.addActionListener(this);
- }
- public void actionPerformed(ActionEvent ae) {
- String s = ae.getActionCommand();
- if (s.equals("happy"))
- f = 1;
- else
- f = 2;
- repaint();
- }
- public void paint(Graphics g) {
- g.setColor(Color.YELLOW);
- g.fillOval(50, 50, 200, 200);
- g.setColor(Color.BLACK);
- g.drawOval(50, 50, 200, 200);
- g.fillOval(90, 100, 20, 20);
- g.fillOval(190, 100, 20, 20);
- if (f == 1) {
- g.drawArc(100, 130, 100, 50, 0, -180);
- } else if (f == 2) {
- g.drawArc(100, 170, 100, 50, 0, 150);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment