Indikator Pencapai Modul TIK SMK REKAYASA PERANGKAT LUNAK kelompok kompetensi D
objek akan diput derajat_rotasi be
Perhatikan conto
Contoh 2, Rotas
package contoh2
; import
java .
awt .;
import javax
. swing
.;
publicclass Contoh2
extends JPanel
{
publicvoid paintComponent
Graphics g
{ super
. paintComponent
g ;
Graphics2D g2d =
Graphics2D g
;
Gambar bujur sangkar g2d
. setColor
Color .
BLUE ;
g2d .
fillRect 10
, 100
, 140
, 90
;
g2d .
drawRect 10
, 100
, 140
, 90
;
g2d .
drawString Objek Tanpa Rotasi
, 10
, 250
;
g2d .
translate 450
, 100
;
g2d .
rotate 45
; method untuk rotasi
g2d .
fillRect 10
, 100
, 140
, 90
;
g2d .
drawString Objek Rotasi Positif
, 10
, 250
;
g2d .
translate 30
, 100
;
g2d .
rotate -
90 ;
method untuk rotasi g2d
. fillRect
10 ,
100 ,
140 ,
90 ;
g2d .
drawString Objek Rotasi Minus
, 10
, 250
; }
publicstaticvoid main
String []
args {
JFrame frame =
new JFrame
Transformasi Objek 2 Dimensi ;
frame .
setDefaultCloseOperation JFrame
. EXIT_ON_CLOSE
;
frame .
add new
Contoh2 ;
frame .
setSize 700
, 420
;
frame .
setLocationRelativeTo null
;
frame .
setVisible true
; }
}
Jika kode diatas utar berlawanan arah jarum jam. Sedangkan
bernilai negatif, maka objek akan diputar seara toh berikut
tasi Objek Persegi Panjang;
package contoh2
; import
java .
awt .;
import javax
. swing
.;
publicclass Contoh2
extends JPanel
{
publicvoid paintComponent
Graphics g
{ super
. paintComponent
g ;
Graphics2D g2d =
Graphics2D g
;
Gambar bujur sangkar g2d
. setColor
Color .
BLUE ;
g2d .
fillRect 10
, 100
, 140
, 90
;
g2d .
drawRect 10
, 100
, 140
, 90
;
g2d .
drawString Objek Tanpa Rotasi
, 10
, 250
;
g2d .
translate 450
, 100
;
g2d .
rotate 45
; method untuk rotasi
g2d .
fillRect 10
, 100
, 140
, 90
;
g2d .
drawString Objek Rotasi Positif
, 10
, 250
;
g2d .
translate 30
, 100
;
g2d .
rotate -
90 ;
method untuk rotasi g2d
. fillRect
10 ,
100 ,
140 ,
90 ;
g2d .
drawString Objek Rotasi Minus
, 10
, 250
; }
publicstaticvoid main
String []
args {
JFrame frame =
new JFrame
Transformasi Objek 2 Dimensi ;
frame .
setDefaultCloseOperation JFrame
. EXIT_ON_CLOSE
;
frame .
add new
Contoh2 ;
frame .
setSize 700
, 420
;
frame .
setLocationRelativeTo null
;
frame .
setVisible true
; }
}
s dikompilasi, maka output-nya adalah
113 an jika parameter
rah jarum jam.
package contoh2
; import
java .
awt .;
import javax
. swing
.;
publicclass Contoh2
extends JPanel
{
publicvoid paintComponent
Graphics g
{ super
. paintComponent
g ;
Graphics2D g2d =
Graphics2D g
;
Gambar bujur sangkar g2d
. setColor
Color .
BLUE ;
g2d .
fillRect 10
, 100
, 140
, 90
;
g2d .
drawRect 10
, 100
, 140
, 90
;
g2d .
drawString Objek Tanpa Rotasi
, 10
, 250
;
g2d .
translate 450
, 100
;
g2d .
rotate 45
; method untuk rotasi
g2d .
fillRect 10
, 100
, 140
, 90
;
g2d .
drawString Objek Rotasi Positif
, 10
, 250
;
g2d .
translate 30
, 100
;
g2d .
rotate -
90 ;
method untuk rotasi g2d
. fillRect
10 ,
100 ,
140 ,
90 ;
g2d .
drawString Objek Rotasi Minus
, 10
, 250
; }
publicstaticvoid main
String []
args {
JFrame frame =
new JFrame
Transformasi Objek 2 Dimensi ;
frame .
setDefaultCloseOperation JFrame
. EXIT_ON_CLOSE
;
frame .
add new
Contoh2 ;
frame .
setSize 700
, 420
;
frame .
setLocationRelativeTo null
;
frame .
setVisible true
; }
}