Untitled

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 48

For the following code select the methods that can be used to handle event and register the

event.

importjava.awt.*;
importjava.applet.*;

/*

<applet code="S1Q50.class" width=300 height=100>

</applet>

*/

public class S1Q50 extends Applet implements MouseMotionListener

String msg = "";

intmouseX = 0, mouseY = 0

public void init()

add-------------(this);

public void ----------------(MouseEvent me)

mouseX = me.getX();

mouseY = me.getY();

msg = "*";

showStatus(" Mouse at " + mouseX + ", " + mouseY);

repaint();

public void ----------------(MouseEvent me)

showStatus("Mouse at " + me.getX() + ", " + me.getY());

}
public void paint(Graphics g)

g.drawString(msg, mouseX, mouseY);

What correction should be done in given code to generate following output


import java.awt.*;

import java.applet.*;

import java.awt.event.*;

/*<applet code=listevent width=400 height=400>

</applet>*/

public class listevent extends Applet implements ActionListener

List l=new List(10);


String msg=" ";

public void init()

l.add("AJP");

l.add("OMD");

l.add("MAN");

add(l);

l.addActionListener(this);

public void itemStateChanged(ItemEvent e)

msg=e.getActionCommand();

repaint();

public void paint(Graphics g)

g.drawString(msg,100,100);

}
What will be the output of following prgram?

import java.awt.*;
import java.awt.event.*;

class Sample extends Frame

Sample(String title)

super(title);

addWindowListener(new WindowAdapter());

setSize(400,400);

setVisible(true);

public void windowClosing(WindowEvent we)

setVisible(false);

System.exit(0);

public static void main(String args[])

Sample f=new Sample("Window Example");

}
For the following code, fill up the correct listener name and event name.

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

/* <applet code="SimpleKeyDemo" width=300 height=100>

</applet> */

public class SimpleKeyDemo extends Applet implements _____________

String msg = "";

int X = 10, Y = 20;

public void init()

addKeyListener(this);

requestFocus();
}

public void keyPressed( _________ ke)

showStatus("Key Down");

public void keyReleased( _________ ke)

showStatus("Key Up");

public void keyTyped( ____________ ke)

msg += ke.getKeyChar();

repaint();

public void paint(Graphics g)

g.drawString(msg, X, Y);

}
Which Statement is given the error in the following code

import java.sql.*;

class dataI

public static void main(String a[])

try

Driver d= new sun.jdbc.odbc.JdbcOdbcDriver();

DriverManager.registerDriver(d);

Connection con =DriverManager.getConnection("Jdbc:Odbc:xxx");

Statement s=con.createStatement();

s.executeUpdate("Insert into Table1 values('hhh',12)");

if(n==1)

{
System.out.println("Record inserted ");

con.close();

catch(Exception e)

System.out.println("not Inserted"+e);

What is output of following code

import java.sql.*;

import java.io.*;

public class StudentTableInsert


{

public static void main(String args[])

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

String Name;

int Age;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

System.out.println("Driver Loaded");

String URL = "jdbc:odbc:StudentDatabase";

Connection con = DriverManager.getConnection(URL);

System.out.println("Connection to database created.");

Statement state = con.createStatement();

System.out.println("Statement Object Created.");

}
Select missing lines in following code to get ouput .
import java.io.*;

import javax.servlet.*;

public class First implements Servlet{

ServletConfig config=null;

public void init(ServletConfig config){

this.config=config;

System.out.println("servlet is initialized");

public void service(ServletRequest req,ServletResponse res)

throws IOException,ServletException{

res.setContentType("text/html");
out.print("<html><body>");

out.print("<b>hello simple servlet</b>");

out.print("</body></html>");

public void destroy(){System.out.println("servlet is destroyed");}

public ServletConfig getServletConfig(){return config;}

public String getServletInfo(){return "copyright 2007-1010";}

}
Consider the following program and identify the missing statement.

public class HelloWorld extends HttpServlet {

private String message;

public void init() throws ServletException

message = "Hello World";

public void doGet(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException

response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println("<h1>" + message + "</h1>");

public void destroy()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy