Archive for January, 2010

How To Add JLabel To JApplet

package javaroach; import java.awt.Color; import java.awt.Container; import java.awt.GridLayout; import java.awt.LayoutManager; import javax.swing.JApplet; import javax.swing.JLabel; public class HowToAddJLabelToJApplet extends JApplet { // Declaration private Container container; private LayoutManager layoutManager; private JLabel label1; private JLabel label2; private JLabel label3; private JLabel label4; private JLabel label5; private JLabel label6; private JLabel label7; public HowToAddJLabelToJApplet() { // Instantiation layoutManager = new GridLayout(7, 1); label1 = new JLabel(“A Simple Label”); label2 = new JLabel(“A Label with LEFT alignment”, JLabel.LEFT); label3 = new JLabel(“A Label with CENTER alignment”, JLabel.CENTER); label4 = new JLabel(“A Label with RIGHT alignment”, JLabel.RIGHT); label5 = new JLabel(“A Label with LEADING alignment”, JLabel.LEADING); label6 = new JLabel(“A Label with TRAILING alignment”, JLabel.TRAILING); label7 = new JLabel(); [...]

How To Use Generic Servlet

GenericServlet is protocol independent. The code shows how to use it. package javaroach; import java.io.IOException; import javax.servlet.GenericServlet; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; public class HowToUseGenericServlet extends GenericServlet { public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException { // Handle the request here System.out.println(“The request will be handled here”); } }

How To Use HTTP Servlet

To handle HTTP protocol request, we need to use HTTPServlet. Depending on which HTTP protocol is calling the servlet (GET or POST), its respective method will be called. package javaroach; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class HowToUseHTTPServlet extends HttpServlet { public HowToUseHTTPServlet() { } public void doGet(HttpServletRequest request, HttpServletResponse response) { // if this is printed, HTTP GET protocol is used to call this servlet System.out.println(“HTTP GET protocol is used to call this servlet”); } public void doPost(HttpServletRequest request, HttpServletResponse response) { // if this is printed, HTTP POST protocol is used to call this servlet System.out.println(“HTTP POST protocol is used to call this servlet”); } }

What And How Do I Debug A Null Pointer Exception

Null pointer exception usually occurs when an object variable is either set as null or is not initialized. Note that primitives such as int, long, float, double, char, boolean, short and byte are not object hence the above rule does not apply. Calling a method from the object that is null will caused it to [...]


Powered by Yahoo! Answers