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("LUCKY TANOUF");
// 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("LUCKY TANOUF");
// 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