Nim : 11110101
Kelas : B
Lisning cara buat Mobil
package roswitha_mobil;
import java.awt.*;
import java.awt.event.*;
public class Roswitha_mobil extends
Frame implements ActionListener{
int x = 100;
int y = 100;
public static void main(String[]
args) {
Frame frame = new Roswitha_mobil();
frame.setSize(640, 480);
frame.setVisible(true);
}
public Roswitha_mobil() {
setTitle("Roswitha_mobil");
// create menu
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);
// 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.blue);
g.fillRect(550, 250, 550, 270);
//g.drawRect(x, y, WIDTH, WIDTH)
g.setColor(Color.black);
g.drawRect(299, 320, 250, 200);
g.setColor(Color.green);
g.fillOval(349, 520, 100, 100);
g.setColor(Color.green);
g.fillOval(470, 520, 100, 100);
g.setColor(Color.green);
g.drawOval(349, 560, 200, WIDTH);
g.setColor(Color.green);
g.fillOval(930, 520, 100, 100);
g.setColor(Color.green);
g.fillOval(800, 520, 100, 100);
g.drawOval(800, 560, 200, WIDTH);
g.setColor(Color.red);
g.fillOval(520, 240, 30, 30);
g.setColor(Color.black);
g.fillRect(550, 244, 550, 120);
g.setColor(Color.ORANGE);
g.fillRect(380, 370, 100, 100);
}
public void
actionPerformed(ActionEvent ev) {
String command =
ev.getActionCommand();
if ("Exit".equals(command))
{
System.exit(0);
}
}
}Hasil Outputnya :
0 komentar:
Posting Komentar