Rabu, 30 Oktober 2013

GRAFIKA " MEMBUAT BANGUN RUANG MENGGUNAKAN JAVA".



1.      Main.java
package tugasgrafika;
import javax.swing.*;
import java.awt.*;
public class Main
{
     public static void main(String[] args)
                        {
JFrame frame = new JFrame("kotakkerucutdansegitiga");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new kotakkerucutdansegitiga());
frame.setSize(900,300;
frame.setLocationRelativeTo(null);
frame.setVisible(true);

                   }
        }








2.      Kotakkerucutdansegitiga.java
package tugasgrafika;
import java.awt.*;
import javax.swing.*;
public class kotakkerucutdansegitiga extends JPanel
{
    public void paintComponent (Graphics g)
    {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;

//Grafik Segitiga
       g2d.drawLine(20, 200, 100, 20);
       g2d.drawLine(180, 200, 100, 20);
       g2d.drawLine(20, 200, 180, 200);

//Grafik Persegi Panjang
                          g2d.drawLine(500, 40, 260, 40);
                          g2d.drawLine(260, 40, 260, 180);
                          g2d.drawLine(500, 40, 500, 180);
                          g2d.drawLine(500, 180, 260, 180);

     //Grafik Ketupat  
               g2d.drawLine(700, 50, 620, 180);
               g2d.drawLine(700, 300, 620, 180);
               g2d.drawLine(700, 50, 780, 180);
               g2d.drawLine(700, 300, 780, 180 );

                   }
 }



Hasil Run: