class ContohFeometri
package main2;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
/**
*
* @author HP Envy
*/
public class ContohGeometri extends JPanel {
//Constructor
public ContohGeometri() {
this.setPreferredSize(new Dimension(400, 300));
this.setBackground(Color.red);
}
//Tambahkan kode untuk menampilkan objek grafik
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
//bintang
GeneralPath p = new GeneralPath(GeneralPath.WIND_NON_ZERO);
p.moveTo(- 100.0f, - 25.0f);
p.lineTo(+ 100.0f, - 25.0f);
p.lineTo(- 50.0f, + 100.0f);
p.lineTo(+ 0.0f, -100.0f);
p.lineTo(+ 50.0f, +100.0f);
p.closePath();
g2.translate(250.0f, 100.0f);
g2.draw(p);
}
}
Class main2
package main2;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
/**
*
* @author HP Envy
*/
public class Main2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//Buat frame dengan title sesuai kebutuhan
JFrame frame = new JFrame("Contoh objek-objek geometri");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
//tambahkan objek dari class ini (sesuai kebutan)
ContohGeometri canvas = new ContohGeometri();
frame.getContentPane().add(canvas);
frame.pack();
frame.setVisible(true);
}
}
Hasil
package main2;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
/**
*
* @author HP Envy
*/
public class ContohGeometri extends JPanel {
//Constructor
public ContohGeometri() {
this.setPreferredSize(new Dimension(400, 300));
this.setBackground(Color.red);
}
//Tambahkan kode untuk menampilkan objek grafik
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
//bintang
GeneralPath p = new GeneralPath(GeneralPath.WIND_NON_ZERO);
p.moveTo(- 100.0f, - 25.0f);
p.lineTo(+ 100.0f, - 25.0f);
p.lineTo(- 50.0f, + 100.0f);
p.lineTo(+ 0.0f, -100.0f);
p.lineTo(+ 50.0f, +100.0f);
p.closePath();
g2.translate(250.0f, 100.0f);
g2.draw(p);
}
}
Class main2
package main2;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
/**
*
* @author HP Envy
*/
public class Main2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//Buat frame dengan title sesuai kebutuhan
JFrame frame = new JFrame("Contoh objek-objek geometri");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
//tambahkan objek dari class ini (sesuai kebutan)
ContohGeometri canvas = new ContohGeometri();
frame.getContentPane().add(canvas);
frame.pack();
frame.setVisible(true);
}
}
Hasil
Post A Comment:
0 comments: