AJP - QB Solved

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

Chapter 1

1. Which class can be used to represent the Checkbox with a textual label that can appear
in a menu?
A. MenuBar
B. MenuItem
C. CheckboxMenuItem
D. Menu

2. Which are various AWT controls from following?


A. Labels, Push buttons, Check boxes, Choice lists.
B. Text components, Threads, Strings, Servelts, Vectors
C. Labels, Strings, JSP, Netbeans, Sockets
D. Push buttons, Servelts, Notepad, JSP

3. JPanel and Applet use as their default layout


A. FlowLayout
B. GridLayout
C. BorderLayout
D. GridBagLayout

4. Which of the following is true about AWT and Swing Component?


A. AWT Components create a process where as Swing Component create a thread
B. AWT Components create a thread where as Swing Component create a process
C. Both AWT and Swing Component create a process
D. Both AWT and Swing Component create a thread

5. Which components are used in the following output?

A. Label, TextF eld, Button


B. Applet, Label
C. Applet, Button
D. Grid Layout, Label, Button
6.Choose the correct sequence for the following output

A. importjava.awt.*;
importjava.applet.*; public class
app1 extends Applet
{
Public void init()
{
TextFieldtf = new TextField();
TextArea t1=new TextArea(3,20);
Checkbox c=new Checkbox("a",true); Checkbox
c1=new Checkbox("b",false);
add(t1);
add(c);
add(tf);
add(c1); }
}
/*<applet code=app1.class width=200 height=200>
</applet>*/ B. importjava.awt.*;
importjava.applet.*; public class app1 extends
Applet
{
public void init()
{
TextFieldtf = new TextField();
TextArea t1=new TextArea(3,20);
Checkbox c=new Checkbox("a",true);
Checkbox c1=new
Checkbox("b",false); add(tf); add(t1);
add(c); add(c1); }
}
/*<applet code=app1.class width=200 height=200>
</applet>*/

C. importjava.awt.*;
importjava.applet.*; public class
app1 extends Applet
{
public void init()
{
TextFieldtf = new TextField();
TextArea t1=new TextField();
Checkbox c=new Checkbox("a",true);
Checkbox c1=new
Checkbox("b",false); add(tf); add(t1);
add(c); add(c1); }
}
E. All of above

7.Select proper code for given output

A.
importjava.awt.*;
importjava.applet.*;
public class choice11 extends Applet
{
public void i it()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
add(os);
}
}
/ <applet code="choice11" height=200 width=300>
</applet>*/

B. importjava.awt.*;
importjava.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new
Choice();
os.add("wnn18");
os.add("wnnxp");
add(os); }
}
/*<applet code="choice11" height=200 width=300>
</applet>*/

C. importjava.awt.*;
importjava.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
add(os); }
}

D. importjava.awt.*;
importjava.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt"); os.add("win
2000");
}
}
/*<applet code="choice11" height=200 width=300>
</applet>*/
8.Select the missing statement in the program for following output
import java.awt.*;
public class MenuDemo extends Frame
{
public static void main(String args[])
{
MenuDemo m = new MenuDemo();
m.setVisible(true);
MenuBar mbr = new MenuBar();
m.setMenuBar(mbr);
Menu filemenu = new Menu("File");
Menu editmenu = new Menu("Edit");
Menu viewmenu = new Menu("View");
mbr.add(filemenu);
mbr.add(editmenu);
MenuItem new1 = new MenuItem("New");
MenuItem open1 = new MenuItem("Open");
filemenu.add(new1);
filemenu.add(open1);
}
}

A. mbr.add(view);
B. mbr.add(menu);
C. mbr.add(vieweditmenu);
D. mbr.add(viewmenu);

9.What are controls or components?

A. Controls or components allow users to interact with application


B. Controls or components do not allow users to interact with users
C. Controls or components allow users to interact with users

D. Controls or components allow application to interact with user

10.Which object is needed to group Checkboxes to make them exclusive?

A. CheckboxGroup
B. Checkbox
C. RadioButton
D. TextField
11. Which components are needed to get above shown output
A. TextField, Label
B. List, Button
C. Choice, Button
D. Button, TextField

12. What components will be needed to get following output?

A. Label, TabbedPane, CheckBox


B. TabbedPane, List, Applet
C. Panel, TabbedPane, List
D. Applet, TabbedPane, Panel
13. Select proper code for given output

a) import java.awt.*;
import java.applet.*; public class choice11
extends Applet
{
public void init()
{
Choice os=new
Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
add(os);
}
}
/*<applet code="choice11" height=200 width=300>
</ap

plet

>*/

b)

import java.awt.*;
import
java.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice(); os.add("wnn18");
os.add("wnnx
p"); add(os);
}
}
/*<applet code="choice11" height=200 width=300>
</applet>*/

c) import
java.awt.*; import
java.applet.*;
public class choice11 extends Applet
{

public void init()


{
Choice os=new
Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
add(os);
}
}

d)
import java.awt.*; import
java.applet.*;
public class choice11 extends Applet
{

public void init()


{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
}
}
/*<applet code="choice11" height=200 width=300>
</applet>*/

Chapter 2

1. Which of these methods is used to get x coordinate of the mouse?


A. getX()
B. getXCoordinate()
C. getCoordinateX()
D. getPointX()

2.Which of these methods cannot be called on JLabel object?


A. setIcon()
B. getText()
C. setLabel()
D. setBorderLayout()

3.____ pane can be used to add component to container


A. Glass
B. Cotent
C. Container
D. All of above
4. Which of the following is not a constructor of JTree
A. JTree(Object obj[])
B. JTree(TreeNodetn)
C. JTree(Vector v)
D. JTree(int x)

5.Swing Components are


A. Platform dependent
B. Platform Independent
C. Both a & b
D. Platform oriented

6.What is the purpose of JTable?


• A. JTable object displays rows of data.
B. JTable object displays columns of data.
C. JTable object displays rows and columns of data.
D. JTable object displays data in Tree form.

7.Which method is used to display icon on a component?


A. rollOverIcon(ImageIcon i)
B. setIcon(ImageIcon i)
C. displayIcon(ImageIcon i)
D. removeIcon (ImageIconi )






8.Which components will be needed to get following output?

A. Label, TabbedPane, CheckBox


B. TabbedPane, List, Applet
C. Panel, TabbedPane, List
D. Applet, TabbedPane, Panel

9.Select the proper output for following


code importjava.awt.*; importjava.applet.*;
public class list2 extends Applet
{
public void init()
{
List l= new List(2,true);
l.add("java");
l.add("c++");
l.add(“kkk”)
; add(l); }
}
/*<applet code=list2.class height=200 width=200>
</applet>*/
a)

b)

c)

d)
10.Consider the following program. Find which statement contains error.

importjava.awt.*;
importjavax.swing.*;
/*
<applet code="JTableDemo" width=400 height=200>
</applet>
*/ public class JTableDemo extends
JApplet
{ public void
init() {
Container contentPane = getContentPane(); contentPane.setLayout(new
BorderLayout());
final String[] colHeads = { "emp_Name", "emp_id", "emp_salary" };
final Object[][] data = {
{ "Ramesh", "111", "50000" },
{ "Sagar", "222", "52000" }, {
"Virag", "333", "40000" },
{ "Amit", "444", "62000" },
{ "Anil", "555", "60000" },
};
JTable table = new JTable(data);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int
h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPanejsp = new JScrollPane(table, v, h);
contentPane.add(jsp, BorderLayout.CENTER);
}
}
A. Error in statement in which JTable is created
B. Error in statement in which JScrollPane is created
C. Error in statement in which applet tag is declared
D. None of the above

11.Select the proper command to run the following code


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
/*
<applet code="combodemo11" width=300 height=100>
</applet>
*/
public class combodemo11 extends JApplet
{
public void init()
{
Container co = getContentPane();
co.setLayout(new FlowLayout());
JComboBoxjc=new JComboBox();
jc.addItem("cricket");
jc.addItem("football");
jc.addItem("hockey");
jc.addItem("tennis"); co.add(jc);
}
}

A. Javac combodemo11.java
B. java combodemo11
C. appletviewer combodemo11.java
D. All of above

12. Observe the following code.


What will be the output of the program?

importjava.awt.*;
importjava.applet.*;
public class LayoutDemo5 extends Applet
{
public void init()
{ inti,j,k,n=4;
setLayout(new BorderLayout());
Panel p1=new Panel(); Panel
p2=new Panel();

p1.setLayout(new
FlowLayout()); p1.add(new
TextField(20)); p1.add(new
TextField(20));

p2.setLayout(new GridLayout(5,3));
p2.add(new Button("OK"));
p2.add(new Button("Submit"));
add(p1,BorderLayout.EAST);
add(p2,BorderLayout.WEST);
}
}
/ <applet code=LayoutDemo5.class width=300 height=400>
</applet>*/

E. The output is obtained in Frame with two layouts: Frame layout and Flow Layout.
F. The output is obtained in Applet with two layouts: Frame layout and Flow Layout.
G. The output is obtained in Applet with two layouts: Frame layout and Border Layout.
H. The output is obtained in Applet with two layouts: Border layout and Flow Layout.

13. Select output for given code


importjava.awt.event.*; import
java.awt.*;
importjava.applet.*;
public class checkbackg extends Applet implements ItemListener
{
Checkbox m1,m2,m3; public
void init()
{
m1=new
Checkbox("A");
m2=new
Checkbox("B"); m3=new
Checkbox("C");
add(m1); add(m2);
add(m3);
m1.addItemListener(thi
s);
m2.addItemListener(thi
s); }
public void itemStateChanged(ItemEventie)
{
if(ie.getSource()==m1) setBackground(Color.red);
if(ie.getSource()==m2) setBackground(Color.green);
}
}
/*<applet code=checkbackg.class height=150 width=150>

</applet>*

/ a)
b)

c)

d)
Chapter 3

1. Which of these are constants defined in WindowEvent class?


A. WINDOW_ACTIVATED
B. WINDOW_CLOSED
C. WINDOW_DEICONIFIED
D. All of the mentioned

2.Which of these is super class of WindowEvent class?


A. WindowEvent
B. ComponentEvent
C. ItemEvent
D. InputEvent

3.Which of these methods is used to obtain the object that generated a WindowEvent?
A. getMethod()
B. getWindow()
C. getWindowEvent()
D. getWindowObject()

4.Select the missing statement in given code

importjava.awt.*;
importjava.applet.*;
/*
<applet code="mouse" width=300 height=100>
</applet>
*/
public class mouse extends Applet implements MouseListener, MouseMotionListener
{
String msg = ""; intmouseX
= 0, mouseY = 0
public void init()
{ } public void mouseClicked(MouseEvent
me)
{ mouseX = 0; mouseY
= 10; msg = "Mouse
clicked.";
repaint();
} public void mouseEntered(MouseEvent
me)
{ mouseX = 0; mouseY
= 10; msg = "Mouse
entered.";
repaint();
} public void mouseExited(MouseEvent
me)
{ mouseX = 0;
mouseY = 10; msg =
"Mouse exited.";
repaint();
} public void mousePressed(MouseEvent
me)
{ mouseX =
me.getX(); mouseY
= me.getY();
msg = "Down";
repaint();
}
public void mouseReleased(MouseEvent me)
{ mouseX =
me.getX(); mouseY
= me.getY();
msg = "Up";
repaint();
}
public void mouseDragged(MouseEvent me)
{ mouseX =
me.getX(); mouseY =
me.getY(); msg =
"*";
showStatus("Dragging mouse at " + mouseX + ", " + mouseY);
repaint();
}
public void mouseMoved(MouseEvent me)
{
showStatus("Moving mouse at " + me.getX() + ", " + me.getY());
} public void paint(Graphics
g)
{
g.drawString(msg, mouseX, mouseY);
}
}
a) addMouseMotionListener(this);
b) paddMouseListener(this);
c) import java.awt.event.*;
d) all of above

5. Consider the following output. Find the missing statement in the program.

import java.awt.*; import


java.awt.event.*; import
java.applet.*; import
javax.swing.*;
/*
<applet code="SimpleKey1" width=300 height=100>
</applet>
*/
public class SimpleKey1 extends JApplet
implements KeyListener
{
String msg = "";
int X = 10, Y = 20; public void init()
{ addKeyListener(this)
; requestFocus();
}
public void keyPressed(KeyEvent ke)
{
showStatus("Key Down");
}
public void keyReleased(KeyEvent ke)
{
showStatus("Key Up");
public void keyTyped(KeyEvent ke)
{
msg += ke.getKeyChar();
repaint(); }
public void paint(Graphics g)
{
g.drawString(msg, X, Y);
}
}
A. Missing Semicolon
B. }
C. {
D. ()

6. For the following code select the method that can be used to handle event.
importjava.awt.event.*; import java.awt.*; importjava.applet.*;
public class checkbackg extends Applet implements ItemListener
{
Checkbox m1,m2,m3;
public void init()
{
m1=new Checkbox("A");
m2=new Checkbox("B");
m3=new Checkbox("C");
add(m1); add(m2);
add(m3);
m1.addItemListener(this)
;
m2.addItemListener(this)
;
}

public void (ItemEvent ie)


{
if(ie.getSource()==m1)
setBackground(Color.red);
if(ie.getSource()==m2)
setBackground(Color.green);
}
}
/*<applet code=checkbackg.class height=150 width=150>
</applet>*/

A. actionPerformed(ActionEvent ae)
B. itemStateChanged(ActionEvent ie)
C. itemStateChanged(ItemEvent ie)
D. adjustmentPerformed(AdjustmentEvent ae)

7. Which of these methods are used to register a mouse motion listener?


a) addMouse()
b) addMouseListener()
c) addMouseMotionListner()
d) eventMouseMotionListener()
8.Which of these methods can be used to determine the type of event?
b) getID()
c) getSource()
d) getEvent()
e) getEventObject
9.Select the missing statement in given code
// Demonstrate the mouse event handlers.
import java.awt.*; import java.applet.*;
/*
<applet code="mouse" width=300 height=100>
</applet>
*/

public class mouse extends Applet


implements MouseListener, MouseMotionListener {
String msg = "";
intmouseX = 0, mouseY = 0; // coordinates of mouse public void
init() {
}
// Handle mouse clicked.
public void mouseClicked(MouseEvent me) {

mouseX = 0; mouseY =
10; msg = "Mouse
clicked.";
repaint();
}
// Handle mouse entered. public void
mouseEntered(MouseEvent me) {

mouseX = 0; mouseY =
10; msg = "Mouse
entered.";
repaint();
}
// Handle mouse exited. public void
mouseExited(MouseEvent me)
{

mouseX = 0; mouseY =
10; msg = "Mouse
exited.";
repaint();
}
// Handle button pressed.

public void mousePressed(MouseEvent me)


{
mouseX =
me.getX();
mouseY =
me.getY(); msg =
"Down"; repaint();
}
// Handle button released.
public void mouseReleased(MouseEvent me) {

mouseX =
me.getX();
mouseY =
me.getY(); msg =
"Up"; repaint(); }
// Handle mouse dragged. public void
mouseDragged(MouseEvent me)
{

mouseX =
me.getX(); mouseY =
me.getY(); msg =
"*";
showStatus("Dragging mouse at " + mouseX + ", " + mouseY); repaint();
}
// Handle mouse moved. public void
mouseMoved(MouseEvent me)
{
showStatus("Moving mouse at " + me.getX() + ", " + me.getY()); }
// Display msg in applet window at current X,Y location.
public void paint(Graphics g)
{
g.drawString(msg, mouseX, mouseY);
}
}

a) addMouseListener(this);

b) addMouseListener(this); addMouseMotionListener(this); import java.awt.event.*;

c) addMouseListener();
d) all of above.

10.Which of these events will be notified if scroll bar is manipulated? b)


ActionEvent
c) ComponentEvent
d) AdjustmentEvent
e) WindowEvent

You might also like