Thursday, October 9, 2014

TUGAS GRAFIKA KOMPUTER 2 MEMBUAT ORANG ....

hay choy kita ketemu lagi ini dalam blog saya ..saya ingin memposting contoh program tentang netbeans java.awt...
ayo choy kita lihat sama-sama..
ini contoh programnya.........

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("yunita pou");
// create menu
    MenuBar mb = new MenuBar();
    setMenuBar(mb);
    Menu menu = new Menu("Close");
    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.black);


     g.setColor(Color.LIGHT_GRAY);
     g.drawOval(200,200,400,400);
     g.fillOval(200,200,400,400);
   
     g.setColor(Color.LIGHT_GRAY);
     g.fillOval(150,350,100,100);
   g.fillOval(550,350,100,100);
   
     g.setColor(Color.white);
     g.drawRect(200,170,400,170);
     g.fillRect(200,160,400,180);
 
     g.setColor(Color.blue);
     g.drawOval(240,330,80,80);
     g.drawOval(480,330,80,80);
 
     g.drawOval(275,345,30,50);
     g.fillOval(275,345,30,50);
     g.drawOval(515,345,30,50);
     g.fillOval(515,345,30,50);
 
     g.setColor(Color.white);
     g.drawOval(287,350,15,15);
     g.fillOval(287,350,15,15);
     g.drawOval(527,350,15,15);
     g.fillOval(527,350,15,15);
 
     g.setColor(Color.white);   
     g.drawOval(290,400,220,180);
     g.fillOval(290,400,220,180);
   
     g.setColor(Color.LIGHT_GRAY);
     g.drawRect(290,400,220,90);
     g.fillRect(290,400,220,90);
 
     g.setColor(Color.black);
     g.drawLine(305,535,495,535);
     g.drawLine(345,490,345,568);
     g.drawLine(452,490,452,570);
     g.drawLine(400,490,400,580);
 

}
public void actionPerformed(ActionEvent ev) {
String command = ev.getActionCommand();
if ("Keluar".equals(command)) {
System.exit(0);
}
}
}





No comments:

Post a Comment