Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts
Friday, 11 July 2014
First Website using Servlets in J2EE

This is a step-by-step tutorial to show how to create your first website in J2EE. Some people also call it as Advanced Java. We have a .JSP page to display the website and a Java class i.e. a Action Servlet to handle the request generated in the .JSP page.

NOTE :- To create this website, you must have installed the IDE i.e. NetBeans with Apache Tomcat Server.

Here are the steps :-

Step 1 :- Create a new project.

File->New Project->Java Web->Web Application

Step 2:- 

Give it a name.

 

Step 3:- Choose the server

Please choose Apache Tomcat. If your IDE is not showing  it, then you have to reinstall the IDE and make sure that during re-installation, you customize the installation of by choosing the server. After choosing the server, click FINISH.

Step 4:-

After clicking finish button, your IDE will look like this. It means your project has been created.


Step 5:- 

Now next you have to do is edit the code in .JSP file i.e. index.jsp file.

CODE:-

    <body>
        <form action="ActionServlet" method="POST">
            <input type="text" name="text" value="" />
            <input type="submit" value="Ok" />
        </form>
    </body>

Step 6:- Create a new servlet.

Just right click the project -> New -> Servlet


Step 7:-

Give the name of servlet. THe name of the servlet must be same as you have set the value of action attribute in form. We have used " <form action="ActionServlet" method="POST"> ", so name of the servlet should be ActionServlet.


Step 8:- Configuration of Servlet Deployment

Remember to check the checkbox saying "Add information to deployment descriptor(Web.xml). It will add the information of the Servlet in Web.xml file for mapping. After that click FINISH.

Step 9:- 

Now your servlet will be created. Please change your servlet code as following.




Now your website is done. All you have to do is run your project and see your output.

Download the sample project :- Click Here

Please do comment if you have any queries. We value your comments.
Monday, 17 March 2014
Drawing lines, rectangles and ovals in Java



 Java Program illustrating how to draw Lines, Rectangles, Ovals using AWT :

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pkgbyte.koding;

/**
 *
 * @author BABU
 */

 import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;

 public class drawLineRect extends JFrame
 {
     private String s = "Using drawString!";

     public drawLineRect()
     {
         super( "Drawing lines, rectangles and ovals" );

         setSize( 400, 165 );
         show();
     }

     public void paint( Graphics g )
     {
         g.setColor( Color.red );
         g.drawLine( 5, 30, 350, 30 );

         g.setColor( Color.blue );
         g.drawRect( 5, 40, 90, 55 );
         g.fillRect( 100, 40, 90, 55 );

         g.setColor( Color.cyan );
         g.fillRoundRect( 195, 40, 90, 55, 50, 50 );
         g.drawRoundRect( 290, 40, 90, 55, 20, 20 );

         g.setColor( Color.yellow );
         g.draw3DRect( 5, 100, 90, 55, true );
         g.fill3DRect( 100, 100, 90, 55, false );

         g.setColor( Color.magenta );
         g.drawOval( 195, 100, 90, 55 );
         g.fillOval( 290, 100, 90, 55 );
     }

     public static void main( String args[] )
     {
         drawLineRect app = new drawLineRect();

         app.addWindowListener( new WindowAdapter()
         {
             public void windowClosing( WindowEvent e )
             {
                 System.exit( 0 );
             }
         });
     }
 }

For more Similar Posts : Click here


Wednesday, 12 March 2014
A Simple JAVA program to create a Draggable JWindow


This Program shows how to develop a Draggable JWindow using JAVA.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ab extends JWindow
    {
  
     private int X=0;
     private int Y=0;
  
     public ab()
         {
      
         setBounds(50,50,200,200);
      
         addWindowListener(new WindowAdapter()
             {
             public void windowClosing(WindowEvent e)
                 {
                 System.exit(0);
             }
         });
      
         addMouseListener(new MouseAdapter()
             {
             public void mousePressed(MouseEvent e)
                 {
                 X=e.getX();
                 Y=e.getY();
             }
         });
      
         addMouseMotionListener(new MouseMotionAdapter()
             {
             public void mouseDragged(MouseEvent e)
                 {
                 setLocation(getLocation().x+(e.getX()-X),getLocation().y+(e.getY()-Y));
             }
         });
      
         setVisible(true);
     }
     public static void main(String[] args)
         {
         new ab();
     }
}

OUTPUT :