SERVLET / NOTES</>↗Servlet01 Jun 2012
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; […]
2D API / NOTES</>↗2D API23 May 2012
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 […]
2D API / NOTES</>↗2D API23 May 2012
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 { […]
SERVLET / NOTES</>↗Servlet23 May 2012
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...
2D API / NOTES</>↗2D API22 May 2012
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 […]
2D API / NOTES</>↗2D API22 May 2012
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...