Koding :
package iaa.grafikakomputer;import java.awt.*;
import java.awt.event.*;
public class IAAGrafikaKomputer extends Frame implements ActionListener {
int x = 100;
int y = 100;
public static void main(String[] args) {
Frame frame = new IAAGrafikaKomputer();
frame.setSize(640, 480);
frame.setVisible(true);
}
public IAAGrafikaKomputer() {
setTitle("AWT Titik");
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);
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent ev) {
System.exit(0);
}
};
this.addWindowListener(l);
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.green);
int jumlahtitik = 1;
while (jumlahtitik <=100){
g.fillRect(100+jumlahtitik, 100+jumlahtitik, 1, 1);
jumlahtitik++; }
}
public void actionPerformed(ActionEvent ev) {
String command = ev.getActionCommand();
if ("Exit".equals(command)) {
System.exit(0);
}
}
}
Hasil
Oleh : Izma Alhudya Ahmad (15110362)
0 komentar:
Posting Komentar