~/paste/1313
~/paste/1313
~/paste/1313

  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.awt.geom.*;
  5.  
  6. public class Latihan extends JFrame implements ActionListener {
  7.    JComboBox comboBentuk, comboGaris, comboWarna;
  8.    JLabel lblBentuk, lblGaris, lblWarna;
  9.    JButton btnGambar;
  10.    String[] isiBentuk = {"Persegi", "Lingkaran", "Segitiga", "Belah Ketupat"};
  11.    String[] isiGaris = {"Tebal", "Tipis", "Putus2"};
  12.    String[] isiWarna = {"Hijau", "Biru", "Hitam"};
  13.    JPanel panelCombo, panelGambar, panelButton;
  14.    
  15.    public Latihan(){
  16.         lblBentuk = new JLabel("Objek :");
  17.         comboBentuk = new JComboBox(isiBentuk);
  18.        
  19.         lblGaris = new JLabel("Garis :");
  20.         comboGaris = new JComboBox(isiGaris);
  21.        
  22.         lblWarna = new JLabel("Warna :");
  23.         comboWarna = new JComboBox(isiWarna);
  24.        
  25.         btnGambar = new JButton("GAMBAR");
  26.        
  27.         panelCombo = new JPanel();
  28.         panelCombo.add(lblBentuk);
  29.         panelCombo.add(comboBentuk);
  30.         panelCombo.add(lblGaris);
  31.         panelCombo.add(comboGaris);
  32.         panelCombo.add(lblWarna);
  33.         panelCombo.add(comboWarna);
  34.                
  35.         panelGambar = new PanelGambar();
  36.  
  37.         panelButton = new JPanel();
  38.         panelButton.setLayout(new FlowLayout());
  39.         panelButton.add(btnGambar);
  40.        
  41.         getContentPane().setLayout(new BorderLayout());
  42.         getContentPane().add(panelCombo, BorderLayout.NORTH);
  43.         getContentPane().add(panelButton, BorderLayout.CENTER);
  44.         getContentPane().add(panelGambar, BorderLayout.SOUTH);          
  45.        
  46.         btnGambar.addActionListener(this);
  47.    }
  48.    
  49.    public void actionPerformed(ActionEvent evt){
  50.         Object obj = evt.getSource();
  51.         if (obj==btnGambar){
  52.            
  53.         }
  54.    }
  55.    
  56.    public static void main(String[] args){
  57.         Latihan frame = new Latihan();
  58.         frame.pack();
  59.         frame.setVisible(true);
  60.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  61.    }
  62. }
  63.  
  64. class PanelGambar extends JPanel{
  65.    public PanelGambar(){
  66.         setPreferredSize(new Dimension(500,400));
  67.         setBackground(Color.DARK_GRAY);
  68.    }
  69.    
  70.    public void paintComponent(Graphics g){
  71.         super.paintComponent(g);
  72.        
  73.         Graphics2D g2 = (Graphics2D) g;
  74.        
  75.         Rectangle2D.Double persegi = new Rectangle2D.Double(10,10,100,100);
  76.         g2.setColor(Color.CYAN);
  77.         g2.fill(persegi);
  78.         g2.setColor(Color.RED);
  79.         g2.setStroke(new BasicStroke(3.0f));
  80.         g2.draw(persegi);
  81.        
  82.         Ellipse2D.Double lingkaran = new Ellipse2D.Double(150, 10, 100, 100);
  83.         g2.setColor(Color.BLUE);
  84.         g2.fill(lingkaran);
  85.         g2.setColor(Color.GREEN);
  86.         g2.setStroke(new BasicStroke(3.0f));
  87.         g2.draw(lingkaran);
  88.        
  89.         Rectangle2D.Double persegiPanjang = new Rectangle2D.Double(10,150,100,150);
  90.         g2.setColor(Color.PINK);
  91.         g2.fill(persegiPanjang);
  92.         g2.setColor(Color.BLACK);
  93.         g2.setStroke(new BasicStroke(3.0f));
  94.         g2.draw(persegiPanjang);
  95.        
  96.         Ellipse2D.Double elips = new Ellipse2D.Double(150, 150, 100, 50);
  97.         g2.setColor(Color.YELLOW);
  98.         g2.fill(elips);
  99.         g2.setColor(Color.RED);
  100.         g2.setStroke(new BasicStroke(3.0f));
  101.         g2.draw(elips);
  102.    }  
  103.  
  104. }
Language: 4cs
Posted by code.breaker.07 at 27 Oct 2011, 04:09:27 Europe/Paris