SupportWriter space ↗
REFERENCE LIBRARY

References from other publishers

Republished articles with source attribution. This collection is separate from Diary Coding’s original guides and does not display ads.

Read original guides → · Editorial policy

FOR YOUR CURIOSITY

Latest notes.

SERVLET / NOTES</>↗
Servlet01 Jun 2012

How do I define a filter using @WebFilter annotation?

The following example show you how to create a servlet filter using the @WebFilter annotation. We will create a simple filter that will check whether an attribute is exists in the http session object. If no attribute found this filter will redirect user into a login page. package org.kodejava.filter; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; […]

Wayan · 2 min read
2D API / NOTES</>↗
2D API23 May 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 min read
2D API / NOTES</>↗
2D API23 May 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 min read
SERVLET / NOTES</>↗
Servlet23 May 2012

How do I define a servlet with @WebServlet annotation?

Annotations is one new feature introduces in the Servlet 3.0 Specification. Previously to declare servlets, listeners or filters we must do it in the web.xml file. Now, with the new annotations feature we can just annotate servlet classes using the @WebServlet annotation. package org.kodejava.servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebInitParam; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import ja...

Wayan · 3 min read
2D API / NOTES</>↗
2D API22 May 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 min read
2D API / NOTES</>↗
2D API22 May 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 min read
✳

Knowledge grows when shared.

Stay curious. There is always something new to learn.

Explore notes ↗
Putu Adi Guna Permana
ABOUT THE AUTHOR

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

Writer and founder of Diary Coding — sharing notes, tutorials, and experiences about programming for anyone who wants to keep learning.