Advanced Java Programming
Advanced Java Programming
Q1. Which of the following methods can be used to remove java.awt. Component object
from display? 1Mark
A. hide()
B. disappear()
C. remove()
D. delete()
Q4. Which object is needed to group Checkboxes to make them exclusive? 1Mark
A. CheckboxGroup
B. Checkbox
C. RadioButton
D. TextField
Q5. What is an event in delegation event model used by Java programming language? 1
Marks
a) An event is an object that describes a state change in a source.
b) An event is an object that describes a state change in processing.
c) An event is an object that describes any change by the user and system.
d) An event is a class used for defining object, to create events.
Q6. Which of these methods are used to register a mouse motion listener? 1Mark
a) addMouse()
b) addMouseListener()
c) addMouseMotionListner()
d) eventMouseMotionListener()
Q.7 Which of these methods can be used to determine the type of event? 1Mark
a) getID()
b) getSource()
c) getEvent()
d) getEventObject
Q8. Which components are needed to get above shown output 2 Marks
A. TextField, Label
B. List, Button
C. Choice, Button
D. Button, TextField
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);
b)addMouseListener(this);
addMouseMotionListener(this);
import java.awt.event.*;
c) addMouseListener();
d) all of above
Q11. Which of these events will be notified if scroll bar is manipulated? 2 Marks
a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent
</applet>*/
a)
b)
c)
d)
b)
import java.awt.*;
import java.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) import java.awt.*;
import java.applet.*;
public class choice11 extends Applet
{
d)
import java.awt.*;
import java.applet.*;
public class choice11 extends Applet
{
a)
b)
c)
d)
Q15. Debug the following program 2 Marks
import java.awt.*;
import javax.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;
JScrollPane jsp = 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
import java.awt.*;
import java.applet.*;
public class LayoutDemo5 extends Applet
{
public void init()
{
int i,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>*/
A. The output is obtained in Frame with two layouts: Frame layout and Flow Layout.
B. The output is obtained in Applet with two layouts: Frame layout and Flow Layout.
C. The output is obtained in Applet with two layouts: Frame layout and Border
Layout.
D. The output is obtained in Applet with two layouts: Border layout and Flow
Layout.
Answer key
1. Answer: C
2. Answer: A
3. Answer : A
4. Answer: A
5. Answer: A
6. Answer: C
7. Answer: A
8. Answer: B
9. Answer: C
10. Answer: B
11. Answer: C
12. Answer: B
13. Answer: A
14. Answer: C
15. Answer :A
16. Answer: D