Codingnya :
package
Gambar_OPELET;
import java.awt.*;
import
java.awt.event.*;
public class
Gambar_OPELET extends Frame implements ActionListener{
int x = 100;
int y = 100;
public static void
main(String[] args) {
Frame frame = new Gambar_OPELET();
frame.setSize(640, 480);
frame.setVisible(true);
}
public
Gambar_OPELET() {
setTitle("DAVID
PUNG MOBIL");
// create menu
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu menu = new Menu("KELUAR
SU");
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.GREEN);
g.setColor(Color.black);
g.fillRect(150,150,125,150);
g.setColor(Color.white);
g.drawString("DAVID
SIO",190,250);
g.setColor(Color.black);
g.drawLine(x
+240,150 , 200 , 150);
g.drawLine(x
+300,300 , 270 ,300);
g.drawLine(x
+300,230,x +300,300);
g.drawLine(x
+270,230,x +300,230);
g.drawLine(x
+270,230,x +240,150);
g.setColor(Color.red);
g.fillRect(160,160,50,50);
g.fillRect(x
+115,160,50,50);
g.fillRect(x
+185,160,50,50);
g.setColor(Color.blue);
g.fillOval(190, 270,
50, 60);
g.fillOval(330, 270,
50, 60);
}
public void
actionPerformed(ActionEvent ev) {
String command =
ev.getActionCommand();
if
("Close".equals(command)) {
System.exit(0);
}
}
}
Nah buat sobat yang kebingungan untuk tentukan titik koordinatnya, silahkan sobat bisa pelajari kodingnya. Saya aja hampir botakkkk. hehehehehe
Outputnya :
Coding dan hasilnya sudah ditampilkan. Harapan saya, DOSEN saya memberikan kritik dan saran juga nilai yang sesuai.
Thanks buat kunjungannya sobat, GOD BLESS YOU...^_^
Tidak ada komentar:
Posting Komentar