TUGAS GRAFIKA KOMPUTER 2
Smile()
pertemuan kali ini
saya akan membuat smile dengan mengunakan java netbins
package smile;
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() {
setBackground (Color.cyan);
setTitle("AMARYA");
// create menu
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu menu = new Menu("File");
mb.add(menu);
Menu menu1 = new Menu("Edit");
mb.add(menu1);
Menu menu2 = new Menu("Run");
mb.add(menu2);
Menu menu3 = new Menu("Tools");
mb.add(menu3);
Menu menu4 = new Menu("Windows");
mb.add(menu4);
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) {
g.setColor(Color.red);
g.fillOval(120,140, 200, 200);
g.setColor(Color.black);
g.drawArc(160, 190, 50, 20, -180, -180);
g.drawArc(240, 190, 50, 20, -180, -180);
g.setColor(Color.black);
g.drawOval(160, 210, 50, 20);
g.fillOval(160, 215, 10, 10);
g.drawOval(240, 210, 50, 20);
g.fillOval(240, 215, 10, 10);
g.drawArc(180, 280, 90, 10, -180, -180);
g.drawArc(180, 280, 90, 10, 180, 180);
g.setColor(Color.blue);
g.fillOval(320,400, 200, 200);
g.setColor(Color.black);
g.drawArc(360, 450, 50, 20, -180, -180);
g.drawArc(440, 450, 50, 20, -180, -180);
g.setColor(Color.black);
g.drawOval(360, 460, 50, 20);
g.fillOval(380, 465, 10, 10);
g.drawOval(440, 460, 50, 20);
g.fillOval(460, 465, 10, 10);
g.drawArc(380, 560, 90, 40, -160, -160);
g.drawArc(380, 530, 90, 40, 160, 160);
g.setColor(Color.black);
g.fillOval(500,140, 200, 200);
g.setColor(Color.white);
g.drawArc(540, 190, 50, 20, -180, -180);
g.drawArc(630, 190, 50, 20, -180, -180);
g.setColor(Color.white);
g.drawOval(540, 200, 50, 20);
g.fillOval(565, 205, 10, 10);
g.drawOval(630, 200, 50, 20);
g.fillOval(650, 200, 10, 10);
g.drawArc(580, 260, 40, 70, -160, -160);
g.drawArc(580, 230, 40, 70, 160, 160);
g.setColor(Color.yellow);
g.fillOval(800,140, 200, 200);
g.setColor(Color.black);
g.drawArc(840, 190, 50, 20, -180, -180);
g.drawArc(930, 190, 50, 20, -180, -180);
g.setColor(Color.black);
g.drawOval(840, 200, 50, 20);
g.fillOval(865, 205, 10, 10);
g.drawOval(930, 200, 50, 20);
g.fillOval(945, 200, 10, 10);
g.drawArc(865, 280, 70, 5, -180, -160);
g.drawArc(865, 280, 70, 5, 180, 160);
g.setColor(Color.gray);
g.fillOval(600,400, 200, 200);
g.setColor(Color.black);
g.drawArc(640, 440, 50, 20, -180, -180);
g.drawArc(720, 440, 50, 20, -180, -180);
g.setColor(Color.black);
g.drawOval(640, 450, 50, 20);
g.fillOval(665, 460, 10, 10);
g.drawOval(720, 450, 50, 20);
g.fillOval(750, 460, 10, 10);
g.drawArc(665, 500, 40, 20, 100, 160);
}
public void actionPerformed(ActionEvent ev) {
String command = ev.getActionCommand();
if ("Exit".equals(command)) {
System.exit(0);
}
}
}
package smile;
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() {
setBackground (Color.cyan);
setTitle("AMARYA");
// create menu
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu menu = new Menu("File");
mb.add(menu);
Menu menu1 = new Menu("Edit");
mb.add(menu1);
Menu menu2 = new Menu("Run");
mb.add(menu2);
Menu menu3 = new Menu("Tools");
mb.add(menu3);
Menu menu4 = new Menu("Windows");
mb.add(menu4);
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) {
g.setColor(Color.red);
g.fillOval(120,140, 200, 200);
g.setColor(Color.black);
g.drawArc(160, 190, 50, 20, -180, -180);
g.drawArc(240, 190, 50, 20, -180, -180);
g.setColor(Color.black);
g.drawOval(160, 210, 50, 20);
g.fillOval(160, 215, 10, 10);
g.drawOval(240, 210, 50, 20);
g.fillOval(240, 215, 10, 10);
g.drawArc(180, 280, 90, 10, -180, -180);
g.drawArc(180, 280, 90, 10, 180, 180);
g.setColor(Color.blue);
g.fillOval(320,400, 200, 200);
g.setColor(Color.black);
g.drawArc(360, 450, 50, 20, -180, -180);
g.drawArc(440, 450, 50, 20, -180, -180);
g.setColor(Color.black);
g.drawOval(360, 460, 50, 20);
g.fillOval(380, 465, 10, 10);
g.drawOval(440, 460, 50, 20);
g.fillOval(460, 465, 10, 10);
g.drawArc(380, 560, 90, 40, -160, -160);
g.drawArc(380, 530, 90, 40, 160, 160);
g.setColor(Color.black);
g.fillOval(500,140, 200, 200);
g.setColor(Color.white);
g.drawArc(540, 190, 50, 20, -180, -180);
g.drawArc(630, 190, 50, 20, -180, -180);
g.setColor(Color.white);
g.drawOval(540, 200, 50, 20);
g.fillOval(565, 205, 10, 10);
g.drawOval(630, 200, 50, 20);
g.fillOval(650, 200, 10, 10);
g.drawArc(580, 260, 40, 70, -160, -160);
g.drawArc(580, 230, 40, 70, 160, 160);
g.setColor(Color.yellow);
g.fillOval(800,140, 200, 200);
g.setColor(Color.black);
g.drawArc(840, 190, 50, 20, -180, -180);
g.drawArc(930, 190, 50, 20, -180, -180);
g.setColor(Color.black);
g.drawOval(840, 200, 50, 20);
g.fillOval(865, 205, 10, 10);
g.drawOval(930, 200, 50, 20);
g.fillOval(945, 200, 10, 10);
g.drawArc(865, 280, 70, 5, -180, -160);
g.drawArc(865, 280, 70, 5, 180, 160);
g.setColor(Color.gray);
g.fillOval(600,400, 200, 200);
g.setColor(Color.black);
g.drawArc(640, 440, 50, 20, -180, -180);
g.drawArc(720, 440, 50, 20, -180, -180);
g.setColor(Color.black);
g.drawOval(640, 450, 50, 20);
g.fillOval(665, 460, 10, 10);
g.drawOval(720, 450, 50, 20);
g.fillOval(750, 460, 10, 10);
g.drawArc(665, 500, 40, 20, 100, 160);
}
public void actionPerformed(ActionEvent ev) {
String command = ev.getActionCommand();
if ("Exit".equals(command)) {
System.exit(0);
}
}
}
semoga dapat
bermanfaat
Tugaz Grafika Komputer 3
Tugas ini dibuat dengan menggunakan
program java Neatbeans IDE 7.0.1.dibawah ini adalah lisning dan hasinlnya.
LISNINGNYA:
LISNINGNYA:
package AMARYA_NITSAE;
import java.awt.*;
import java.awt.event.*;
public class MEMBUAT_OTO extends
Frame implements ActionListener{
int x = 100;
int y = 100;
public static void main(String[]
args) {
Frame frame = new MEMBUAT_OTO();
frame.setSize(640, 480);
frame.setVisible(true);
}
public MEMBUAT_OTO() {
setTitle("MEMBUAT_OTO");
// create menu ....................
STIKOM ARTHA BUANA
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()
{
@Override
public void windowClosing(WindowEvent ev) {
System.exit(0);
}
};
this.addWindowListener(l);
// mouse event
handler....................STIKOM ARTHA BUANA
MouseListener mouseListener = new
MouseAdapter() {
public void mouseClicked(MouseEvent
ev) {
x = ev.getX();
y = ev.getY();
repaint();
}
};
addMouseListener(mouseListener);
}
@Override
public void paint(Graphics g) {
g.setColor(Color.black);
g.drawRect(200, 149, 100, 100);
g.setColor(Color.red);
g.fillRect(239, 200,60, 49);
g.setColor(Color.red);
g.fillRect(300,125,300,125);
//g.drawRect(x, y, WIDTH, WIDTH)
g.setColor(Color.black);
g.fillOval(275, 240, 40, 40);
g.fillOval(515, 240, 40, 40);
g.fillOval(400, 240, 40, 40);
g.drawRect(195, 200, 5, 35);
g.setColor(Color.orange);
g.fillOval(190, 210, 10,10);
}
@Override
public void
actionPerformed(ActionEvent ev) {
String command =
ev.getActionCommand();
if
("Exit".equals(command)) {
System.exit(0);
}
}
}
========================================================================
HASILNYA setelah di run