Thursday, October 9, 2014

TUGAS GRAFIKA KOMPUTER KE 3 MEMBUAT SMILE

Teman-teman yang saya sayang kita jumpa lagi di blog saya yach,saya ingin berbagi tugas saya ini..
jangan  jenuh yach kalau lihat blog saya yach...
ini tugas membuat smile.....



package penggunaanawt;

import java.awt.*;
import java.awt.event.*;

public class smile extends Frame implements ActionListener {

    int x = 100;
    int y = 100;

    public static void main(String[] args) {
        Frame frame = new smile();
        frame.setSize(640, 480);
        frame.setVisible(true);
    }

    public smile() {
        setTitle("orpa yunita pou Smile");
// create menu
        MenuBar mb = new MenuBar();
        setMenuBar(mb);
        Menu menu = new Menu("File");
        mb.add(menu);
        MenuItem mi = new MenuItem("Exit");
        mi.addActionListener(this);
        menu.add(mi);
// end program when window is closed
        WindowListener l = new WindowAdapter() {
            public void windowClosing(WindowEvent ev) {
                System.exit(0);
            }
        };
        this.addWindowListener(l);
// mouse event handler
        MouseListener mouseListener = new MouseAdapter() {
            public void mouseClicked(MouseEvent ev) {
                x = ev.getX();
                y = ev.getY();
                repaint();
            }
        };
        addMouseListener(mouseListener);
    }

    public void paint(Graphics g) {

        setBackground(Color.blue);

        g.setColor(Color.white);
        g.fillOval(320, 240, 200, 200);
        g.setColor(Color.BLACK);
        g.drawArc(360, 290, 50, 20, -180, -180);
        g.drawArc(440, 290, 50, 20, -180, -180);
        g.setColor(Color.black);
        g.drawArc(380, 360, 90, 50, 180, 180);
        g.fillOval(360, 310, 50, 20);
        g.fillOval(440, 310, 50, 20);

    }

    public void actionPerformed(ActionEvent ev) {
        String command = ev.getActionCommand();
        if ("Exit".equals(command)) {
            System.exit(0);
        }
    }
}

 

No comments:

Post a Comment