Coding :
package
penggunaanawt;
import java.awt.*;
import
java.awt.event.*;
public class
Segitiga extends Frame implements ActionListener{
int x = 100;
int y = 100;
public static void
main(String[] args) {
Frame frame = new Segitiga();
frame.setSize(640, 480);
frame.setVisible(true);
}
public Segitiga() {
setTitle("DAVID
SIO SEGITIGA");
// create menu
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu menu = new Menu("KELUAR
SU");
mb.add(menu);
MenuItem mi = new
MenuItem("Yes");
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.drawLine(x, y,
400, 100);
g.setColor(Color.black);
g.drawLine(x, y,100
, 300);
g.setColor(Color.black);
g.drawLine(x,
y+200,400 , 100);
g.setColor(Color.black);
}
public void
actionPerformed(ActionEvent ev) {
String command =
ev.getActionCommand();
if
("Close".equals(command)) {
System.exit(0);
}
}
}
Outoutnya :
Nah itu dia gambarnya sobat. Saya berharap mendapat kritik, saran, juga nilai dari dosen saya. Thanks buat kunjungannya, GOD BLESS YOU...
Tidak ada komentar:
Posting Komentar