Write a program that displays a frame with the following GUI

Write a program that displays a frame with the following GUI elements: a label that displays a simple icon with a circle initially colored solid red - a button labeled \"Green\" a button labeled \"Blue\" a button labeled \"Red\" When the user clicks a button, the circle color must change to that indicated by the button\'s label. Implementation requirements: when a button is clicked you need to change the icon\'s color, then call the label\'s repaint() method. This, in turn will call the icon\'s paintIcon() method, so that the icon is redrawn with the new color. In other words, you don\'t call paintIcon() directly, the ILabel object does it. the buttons\' action listener objects must be of anonymous classes. the buttons must be created in main() and set up in a loop with loop index from 0 to 2, like this: for (I = 0; I

Solution

Delete:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;

public class DeleteDemo extends HttpServlet
{
   public void doPost(HttpServletRequest req,HttpServletResponse res)
   {
       Connection con = null;
       PreparedStatement ps = null;
       int rs = 0;
       try
       {
           PrintWriter pw = res.getWriter();
           res.setContentType(\"text/html\");
           pw.println(\"<html><form target = \'display\'>\");
           int sid = Integer.parseInt(req.getParameter(\"stu_id\"));
           Class.forName(\"oracle.jdbc.driver.OracleDriver\");
           con = DriverManager.getConnection(\"jdbc:oracle:thin:@localhost:1521:satya\",\"scott\",\"tiger\");
           ps = con.prepareStatement(\"delete from student_info where stu_id=?\");
           ps.setInt(1,sid);
           rs = ps.executeUpdate();
           if(rs!=1)
               pw.println(\"<h2>Student id is problem</h2>\");
           else
               pw.println(\"<h2 style = \'position:absolute;left:50;top:50\'>One Record Deleted</h2>\");

           ps.close();
           con.close();
       }
       catch(Exception e)
       {
           e.printStackTrace();
       }
   }
   public void doGet(HttpServletRequest req,HttpServletResponse res)
   {
       try{
           doPost(req,res);
       }
       catch(Exception e)
       {
           e.printStackTrace();
       }
   }
}

Insert:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;

public class InsertDemo extends HttpServlet
{
   public void doPost(HttpServletRequest req,HttpServletResponse res)
   {
       Connection con = null;
       PreparedStatement ps = null;
       int rs = 0;
       try
       {
           PrintWriter pw = res.getWriter();
           res.setContentType(\"text/html\");
           pw.println(\"<html><form target = \'display\'>\");
           int sid = Integer.parseInt(req.getParameter(\"stu_id\"));
           String sname = req.getParameter(\"stu_name\");
           String sadd = req.getParameter(\"stu_add\");
           Class.forName(\"oracle.jdbc.driver.OracleDriver\");
           con = DriverManager.getConnection(\"jdbc:oracle:thin:@localhost:1521:satya\",\"scott\",\"tiger\");
           System.out.println(\"connection\");
           ps = con.prepareStatement(\"insert into student_info values(?,?,?)\");
           ps.setInt(1,sid);
           ps.setString(2,sname);
           ps.setString(3,sadd);
           rs = ps.executeUpdate();
           if(rs!=1)
               pw.println(\"<h2>Record is problem</h2>\");
           else
               pw.println(\"<h2 style = \'position:absolute;left:50;top:50\'>One Record Inserted Successfully</h2>\");

           ps.close();
           con.close();
       }
       catch(Exception e)
       {
           e.printStackTrace();
       }
   }
   public void doGet(HttpServletRequest req,HttpServletResponse res)
   {
       try
       {
           doPost(req,res);
       }
       catch(Exception e)
       {
           e.printStackTrace();
       }
   }
}

Update:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;

public class UpdateDemo extends HttpServlet
{
   public void doPost(HttpServletRequest req,HttpServletResponse res)
   {
       Connection con = null;
       PreparedStatement ps = null;
       int rs = 0;
       try
       {
           PrintWriter pw = res.getWriter();
           res.setContentType(\"text/html\");
           pw.println(\"<html><form target = \'display\'>\");
           int sid = Integer.parseInt(req.getParameter(\"stu_id\"));
           String sname = req.getParameter(\"stu_name\");
           String sadd = req.getParameter(\"stu_add\");
           Class.forName(\"oracle.jdbc.driver.OracleDriver\");
           con = DriverManager.getConnection(\"jdbc:oracle:thin:@localhost:1521:satya\",\"scott\",\"tiger\");
           ps = con.prepareStatement(\"update student_info set stu_name=?,stu_add=? where stu_id=?\");
           ps.setString(1,sname);
           ps.setString(2,sadd);
           ps.setInt(3,sid);
           rs = ps.executeUpdate();
           if(rs!=1)
               pw.println(\"<h2>Student ID problem</h2>\");
           else
               pw.println(\"<h2 style = \'position:absolute;left:50;top:50\'>One Record Updated</h2>\");

           ps.close();
           con.close();
       }
       catch(Exception e)
       {
           e.printStackTrace();
       }
   }
   public void doGet(HttpServletRequest req,HttpServletResponse res)
   {
       try
       {
           doPost(req,res);
       }
       catch(Exception e)
       {
           e.printStackTrace();
       }
   }
}

Xml:

<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<!DOCTYPE web-app
PUBLIC \"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN\"
\"http://java.sun.com/dtd/web-app_2_3.dtd\">

<web-app>
   <welcome-file-list>
   <welcome-file>Main.html</welcome-file>
</welcome-file-list>

   <servlet>
       <servlet-name>insert</servlet-name>
       <servlet-class>InsertDemo</servlet-class>
   </servlet>
   <servlet-mapping>
       <servlet-name>insert</servlet-name>
       <url-pattern>/insert</url-pattern>
   </servlet-mapping>


       <servlet>
       <servlet-name>delete</servlet-name>
       <servlet-class>DeleteDemo</servlet-class>
   </servlet>
   <servlet-mapping>
       <servlet-name>delete</servlet-name>
       <url-pattern>/delete</url-pattern>
   </servlet-mapping>


   <servlet>
       <servlet-name>update</servlet-name>
       <servlet-class>UpdateDemo</servlet-class>
   </servlet>
   <servlet-mapping>
       <servlet-name>update</servlet-name>
       <url-pattern>/update</url-pattern>
   </servlet-mapping>


</web-app>

 Write a program that displays a frame with the following GUI elements: a label that displays a simple icon with a circle initially colored solid red - a button
 Write a program that displays a frame with the following GUI elements: a label that displays a simple icon with a circle initially colored solid red - a button
 Write a program that displays a frame with the following GUI elements: a label that displays a simple icon with a circle initially colored solid red - a button
 Write a program that displays a frame with the following GUI elements: a label that displays a simple icon with a circle initially colored solid red - a button

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site