AJP - QB Solved
AJP - QB Solved
AJP - QB Solved
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
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
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);
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
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
{
d)
import java.awt.*; import
java.applet.*;
public class choice11 extends Applet
{
Chapter 2
•
•
•
•
•
8.Which components will be needed to get following output?
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
A. Javac combodemo11.java
B. java combodemo11
C. appletviewer combodemo11.java
D. All of above
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.
</applet>*
/ a)
b)
c)
d)
Chapter 3
3.Which of these methods is used to obtain the object that generated a WindowEvent?
A. getMethod()
B. getWindow()
C. getWindowEvent()
D. getWindowObject()
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.
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)
;
}
A. actionPerformed(ActionEvent ae)
B. itemStateChanged(ActionEvent ie)
C. itemStateChanged(ItemEvent ie)
D. adjustmentPerformed(AdjustmentEvent ae)
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.
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);
c) addMouseListener();
d) all of above.