Ruang penulis
SEBUAH JURNAL TENTANG TEKNOLOGI

Belajar hal baru.
Tulis. Bagikan.

Ruang untuk merangkai pengetahuan, satu baris kode setiap hari.
Temukan tutorial, ide, dan catatan dari perjalanan belajar.

1914 catatan & terus bertumbuh
UNTUK RASA INGIN TAHUMU

Catatan terbaru.

2D API / CATATAN</>
2D API07 Jan 2024

How do I write a simple analog clock using Java 2D?

Here is a simple Java code for an analog clock using Java 2D features in Swing. Please adjust the code according to your needs. This code will create a new JFrame and continually update it every second with the current time. package org.kodejava.swing; import javax.swing.*; import java.awt.*; import java.util.Calendar; import java.util.GregorianCalendar; public class AnalogClock extends […]

Wayan · 3 menit baca
2D API / CATATAN</>
2D API23 Mei 2012

How do I draw a vertical text in Java 2D?

To draw a text / string vertically we need to do a transform on the Graphics2D object. First, create an instance of AffineTransform and set the rotation using the setToRotation() method. And then pass this transform object into g2.setTransform() method. package org.kodejava.awt.geom; import javax.swing.*; import java.awt.*; import java.awt.geom.AffineTransform; public class DrawVerticalText extends JPanel { public […]

Wayan · 1 menit baca
2D API / CATATAN</>
2D API23 Mei 2012

How do I draw a string in Java 2D?

The code snippet below show you how to draw a string using Graphics2D. The drawString() method accept the string to be drawn and their x and y coordinate. Here you can also see how to set the antialiasing mode using the setRenderingHint() method. package org.kodejava.awt.geom; import javax.swing.*; import java.awt.*; public class DrawString extends JPanel { […]

Wayan · 1 menit baca
2D API / CATATAN</>
2D API22 Mei 2012

How do I create a dashed stroke in Java 2D?

package org.kodejava.awt.geom; import javax.swing.*; import java.awt.*; import java.awt.geom.RoundRectangle2D; public class DrawDashedStroke extends JComponent { public static void main(String[] args) { JFrame frame = new JFrame("Draw Dashed Stroke Demo"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.getContentPane().add(new DrawDashedStroke()); frame.pack(); frame.setSize(new Dimension(420, 250)); frame.setVisible(true); } @Override public void paint(...

Wayan · 1 menit baca
2D API / CATATAN</>
2D API22 Mei 2012

How do I define stroke when drawing a shape in Java 2D?

package org.kodejava.awt.geom; import javax.swing.*; import java.awt.*; import java.awt.geom.Line2D; public class DrawStrokeDemo extends JComponent { public static void main(String[] args) { JFrame frame = new JFrame("Draw Stroke Demo"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.getContentPane().add(new DrawStrokeDemo()); frame.pack(); frame.setSize(new Dimension(420, 200)); frame.setVisible(true); } @Override public void paint(Graphics g) { Graphic...

Wayan · 1 menit baca
2D API / CATATAN</>
2D API22 Mei 2012

How do I create a gradient paint in Java 2D?

To change the color of a graphics shape we can use the setPaint() method. For a simple coloring we can pass the color object into this method, such as Color.RED or Color.GREEN. If you want to paint with a gradient paint you can use the GradientPaint class. This class provides a way to fill a […]

Wayan · 2 menit baca

Pengetahuan tumbuh ketika dibagikan.

Simpan rasa ingin tahu. Selalu ada hal baru untuk dipelajari.

Jelajahi catatan ↗
Putu Adi Guna Permana
TENTANG PENULIS

Dr (C). Ir. Putu Adi Guna Permana, S.Kom., M.Kom., IPM., ASEAN Eng.

Penulis dan pendiri Diary Coding — berbagi catatan, tutorial, dan pengalaman seputar pemrograman untuk siapa pun yang ingin terus belajar.