Codingnya :
package
penggunaanawt;
import java.awt.*;
import
java.awt.event.*;
public class AWTDemo
extends Frame implements ActionListener{
int x = 100;
int y = 100;
public static void
main(String[] args) {
Frame frame = new AWTDemo();
frame.setSize(640, 480);
frame.setVisible(true);
}
public AWTDemo() {
setTitle("Manusia
By David");
// create menu
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu menu = new Menu("Click Untuk
Keluar");
mb.add(menu);
MenuItem mi = new
MenuItem("Close");
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.PINK);
g.drawOval(200,200,400,400);
g.fillOval(200,200,400,400);
g.setColor(Color.PINK);
g.fillOval(150,350,100,100);
g.fillOval(550,350,100,100);
g.setColor(Color.DARK_GRAY);
g.drawRect(200,170,400,170);
g.fillRect(200,160,400,180);
g.setColor(Color.black);
g.drawOval(240,330,80,80);
g.drawOval(480,330,80,80);
g.drawOval(275,345,30,50);
g.fillOval(275,345,30,50);
g.drawOval(515,345,30,50);
g.fillOval(515,345,30,50);
g.setColor(Color.white);
g.drawOval(287,350,15,15);
g.fillOval(287,350,15,15);
g.drawOval(527,350,15,15);
g.fillOval(527,350,15,15);
g.setColor(Color.white);
g.drawOval(290,400,220,180);
g.fillOval(290,400,220,180);
g.setColor(Color.pink);
g.drawRect(290,400,220,90);
g.fillRect(290,400,220,90);
g.setColor(Color.black);
g.drawLine(305,535,495,535);
g.drawLine(345,490,345,568);
g.drawLine(452,490,452,570);
g.drawLine(400,490,400,580);
Font f = new Font ("David Sio
Design",Font.BOLD, 48);
g.setFont(f);
g.setColor(Color.red);
g.drawString("CREATED By DAVID SIO!!
",200,680);
}
public void
actionPerformed(ActionEvent ev) {
String command =
ev.getActionCommand();
if
("Exit".equals(command)) {
System.exit(0);
}
}
}
Coding dan hasilnya sudah ditampilkan. Harapan saya, DOSEN saya memberikan kritik dan saran juga nilai yang sesuai.
Thanks buat kunjungannya sobat, GOD BLESS YOU...^_^
Thanks buat kunjungannya sobat, GOD BLESS YOU...^_^
Tidak ada komentar:
Posting Komentar