hy prkenalkan....
Nama : Apsyalom Magang
Nim : 11110053
kelas : B
saya akan posting tugas dari Dosen saya mudah-mudahan bermanfaat ya,.,......
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.drawLine(x, y, 100, 50);
g.setColor(Color.green);
g.drawOval(100, 100,100, 200);
g.drawRect(150, 150, 200, 200); //g.drawRect(x, y, WIDTH, WIDTH)
g.fillOval(100, 200, 80, 150); //g.fillOval(x, y, WIDTH, WIDTH);
g.setColor(Color.red);
g.fillOval(10, 20, 80, 150);
g.setColor(Color.BLUE);
g.drawOval(320,240, 200, 200);
g.setColor(Color.yellow);
g.drawArc(360, 290, 50, 20, -180, -180);
g.drawArc(440, 290, 50, 20, -180, -180);
g.setColor(Color.black);
g.drawArc(380, 360, 90, 50, 180, 180);
g.fillOval(360, 310, 50, 20);
g.fillOval(440, 310, 50, 20);
}
public void actionPerformed(ActionEvent ev) {
String command = ev.getActionCommand();
if ("Exit".equals(command)) {
System.exit(0);
}
}
}
Tidak ada komentar:
Posting Komentar