EstiBangun.java


// EstiBangun.java
// ditulis : Esti HPM
// Mahasiswi Politeknik Harapan Bersama Tegal
// Prodi Komputer
// Semester 2
// Kelas B
// 1 Mei 2009
import java.awt.*;
import javax.swing.*;
public class EstiBangun extends JPanel
{
public final static int PROFILESTI = 1,
LINGKARAN = 2,
BUJURSANGKAR = 3,
SEGITIGA = 4,
BELAHKETUPAT = 5,
PERSEGIPANJANG = 6;
private int shape;
String KPROFILESTI [] = { “Esti HPM”, “Mahasiswi Politeknik Harapan Bersama Tegal “, “D3 Komputer Multimedia ” };
String KLINGKARAN [] = { “Jumlah Sisi = 1”, “Luas + 3,14 x Jari-Jari x Jari-Jari “, “Keliling = 3,14 x diameter ” };
String KBUJURSANGKAR [] = { “Jumlah Sisi = 4″, ” Luas = sisi x sisi “, “Keliling = 4 x sisi ” };
String KSEGITIGA [] = { “Jumlah Sisi = 3”, “Luas = 0,5 x alas x tinggi “, “Keliling = Sisi + Sisi + Sisi ” };
String KBELAHKETUPAT [] = { “Jumlah Sisi = 4”, “Luas = 0,5 x perkalian diagonal-diagonalnya “, “Keliling = 4 x Sisi ” };
String KPERSEGIPANJANG [] = { “Jumlah Sisi = 4”, “Luas = panjang x lebar “, “Keliling = 2 x (panjang +lebar) ” };
public void paintComponent( Graphics g )
{
super.paintComponent( g );
switch ( shape ) {
case PROFILESTI:
g.setFont( new Font(“Monotype Corsiva”, Font.BOLD, 48));
g.setColor(Color.RED);
g.drawString(” PROFIL ESTI “, 50,50);
g.setFont( new Font(“Comic Sans MS”, Font.BOLD, 20));
g.drawString( KPROFILESTI[0], 50,150);
g.drawString( KPROFILESTI[1], 50,200);
g.drawString( KPROFILESTI[2], 50,250);
break;
case LINGKARAN:
g.setFont( new Font(“Times New Roman”, Font.BOLD, 36));
g.setColor(Color.BLUE);
g.drawString(” LINGKARAN “, 50,50);
g.setFont( new Font(“Times New Roman”, Font.BOLD, 20));
g.drawString( KLINGKARAN[0], 400,150);
g.drawString( KLINGKARAN[1], 400,200);
g.drawString( KLINGKARAN[2], 400,250);
g.fillOval( 100, 200, 100, 100 );
break;
case BUJURSANGKAR:
g.setFont( new Font(“Times New Roman”, Font.BOLD, 36));
g.setColor(Color.GRAY);
g.drawString(” BUJUR SANGKAR “, 50,50);
g.fillRect( 100, 200, 100, 100 );
g.setFont( new Font(“Times New Roman”, Font.BOLD, 20));
g.drawString( KBUJURSANGKAR[0], 400,150);
g.drawString( KBUJURSANGKAR[1], 400,200);
g.drawString( KBUJURSANGKAR[2], 400,250);
break;
case SEGITIGA:
g.setFont( new Font(“Times New Roman”, Font.BOLD, 36));
g.setColor(Color.MAGENTA);
g.drawString(” SEGITIGA “, 50,50);
int xValue[] = { 100,200,200,100 };
int yValue[] = { 200,200,300,200 };
Polygon polygon1 = new Polygon( xValue, yValue, 4);
g.fillPolygon( polygon1 );
g.setFont( new Font(“Times New Roman”, Font.BOLD, 20));
g.drawString( KSEGITIGA[0], 400,150);
g.drawString( KSEGITIGA[1], 400,200);
g.drawString( KSEGITIGA[2], 400,250);
break;
case BELAHKETUPAT:
g.setFont( new Font(“Times New Roman”, Font.BOLD, 36));
g.setColor(Color.BLACK);
g.drawString(” BELAH KETUPAT “, 50,50);
int xValue2[] = { 200,250,300,250,200 };
int yValue2[] = { 250,200,250,300,250 };
Polygon polygon2 = new Polygon( xValue2, yValue2, 5);
g.fillPolygon( polygon2 );
g.setFont( new Font(“Times New Roman”, Font.BOLD, 20));
g.drawString( KBELAHKETUPAT[0], 400,150);
g.drawString( KBELAHKETUPAT[1], 400,200);
g.drawString( KBELAHKETUPAT[2], 400,250);
break;
case PERSEGIPANJANG:
g.setFont( new Font(“Times New Roman”, Font.BOLD, 36));
g.setColor(Color.RED);
g.drawString(” PERSEGI PANJANG “, 50,50);
g.fillRect( 100, 150, 250, 100 );
g.setFont( new Font(“Times New Roman”, Font.BOLD, 20));
g.drawString( KPERSEGIPANJANG[0], 400,150);
g.drawString( KPERSEGIPANJANG[1], 400,200);
g.drawString( KPERSEGIPANJANG[2], 400,250);
break;
}
}
public void draw( int shapeToDraw )
{
shape = shapeToDraw;
repaint();
}
}

/// EstiBangunTest.java
// ditulis : Esti HPM
// Mahasiswi Politeknik Harapan Bersama Tegal
// Prodi Komputer
// Semester 2
// Kelas B
// 1 Mei 2009
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
public class EstiBangunTest extends JFrame
{
private JPanel buttonPanel;
private EstiBangun myPanel;
private JButton profilestiButton,
lingkaranButton,
bujursangkarButton,
segitigaButton,
belahketupatButton,
persegipanjangButton ;
public EstiBangunTest()
{
super(” EstiBangun Test”);
myPanel = new EstiBangun();
myPanel.setBackground( Color.CYAN );
profilestiButton = new JButton(” Profil Esti “);
profilestiButton.addActionListener(
new ActionListener() {
public void actionPerformed ( ActionEvent event )
{
myPanel.draw( EstiBangun.PROFILESTI );
}
}
);
bujursangkarButton = new JButton(” BujurSangkar “);
bujursangkarButton.addActionListener(
new ActionListener() {
public void actionPerformed ( ActionEvent event )
{
myPanel.draw( EstiBangun.BUJURSANGKAR );
}
}
);
lingkaranButton = new JButton(” Lingkaran “);
lingkaranButton.addActionListener(
new ActionListener() {
public void actionPerformed ( ActionEvent event )
{
myPanel.draw( EstiBangun.LINGKARAN );
}
}
);
segitigaButton = new JButton(” Segitiga “);
segitigaButton.addActionListener(
new ActionListener() {
public void actionPerformed ( ActionEvent event )
{
myPanel.draw( EstiBangun.SEGITIGA );
}
}
);
belahketupatButton = new JButton(” BelahKetupat “);
belahketupatButton.addActionListener(
new ActionListener() {
public void actionPerformed ( ActionEvent event )
{
myPanel.draw( EstiBangun.BELAHKETUPAT );
}
}
);
persegipanjangButton = new JButton(” Persegi Panjang “);
persegipanjangButton.addActionListener(
new ActionListener() {
public void actionPerformed ( ActionEvent event )
{
myPanel.draw( EstiBangun.PERSEGIPANJANG );
}
}
);
buttonPanel = new JPanel();
buttonPanel.setLayout( new GridLayout( 1, 2));
buttonPanel.add(profilestiButton);
buttonPanel.add( lingkaranButton );
buttonPanel.add( bujursangkarButton );
buttonPanel.add( segitigaButton );
buttonPanel.add( belahketupatButton );
buttonPanel.add(persegipanjangButton);
Container container = getContentPane();
container.add( myPanel, BorderLayout.CENTER );
container.add( buttonPanel, BorderLayout.SOUTH );
setSize( 1000, 600 );
setVisible( true );}
public static void main ( String args[] )
{
EstiBangunTest application = new EstiBangunTest();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );}
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s