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("AWT Demo");
// 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.drawOval(120,140,200,200);
int jumlah=1;
while (jumlah <=5){
g.drawArc(180,260,90,60,180,180);
int jumlah2=1;
while
(jumlah2<=1000000000){
jumlah2++;
}
jumlah++;
g.setColor(Color.blue);
g.fillOval(240,210,50,20);
g.fillOval(160,210,50,20);
g.setColor(Color.black);
g.drawArc(160,190,50,20,-180,-180);
g.drawArc(240,190,50,20,-180,-180);
g.drawArc(180,260,90,60,180,180);
}
}
public void actionPerformed(ActionEvent ev) {
String command = ev.getActionCommand();
if ("Exit".equals(command)) {
System.exit(0);
}
}
}
0 komentar:
Posting Komentar