Professional Documents
Culture Documents
7. Which of the following is an advantage of using a 12. Which code is required to display output in table
`ButtonGroup` with `JRadioButton` components? format?
a.Container c1 = getContentPane(); c1.setLayout(new public static void main(String args[]) {
FlowLayout()); MenuDemo m = new MenuDemo();
b.Container c1 = getContentPane(); c1.setLayout(new m.setSize(200,200);
BorderLayout());
m.setTitle("Menu Demo Program");
c.Container c1 = getContentPane(); c1.setLayout(new
GridLayout()); m.setVisible(true); }
d.Container c1 = getContentPane(); c1.setLayout(new public void _______________ { // (4) Fill in the blank
CardLayout());` if (ae.getSource() == new1) {
System.out.println("You Pressed New menu Item");}
13. What error will occur while running given applet? import else if (ae.getSource() == open1)
java.awt.*; import java.awt.event.*; import java.applet.*; {System.out.println("You Pressed Open menu
/* <applet code=ButtonDemo.class width=500
Item");}}}
height=500> </applet>*/ public class ButtonDemo extends
Applet implements ActionListener { Button b1,b2,b3;
String msg; public void init() { msg=""; add(b1); add(b2); a. ActionListener, addActionListener(this)
add(b3); b1=new Button("Yes"); b2=new Button("No"); addActionListener(this), actionPerformed(ActionEvent ae)
b3=new Button("Exit"); b1.addActionListener(this);
b2.addActionListener(this); b3.addActionListener(this); } b. ActionEvent, addActionListener(this)
public void actionPerformed(ActionEvent ae) { addActionListener(this), actionPerformed(ActionListener ae)
if(ae.getSource()==b1) { msg="Yes Button is pressed"; }
if(ae.getSource()==b2) { msg="No Button is pressed"; } C) ActionListener, addActionListener(this)
if(ae.getSource()==b3) { msg="Exit Button is pressed"; } addActionListener(this), actionPerformed(ActionEvent ae)
repaint(); } public void paint(Graphics g ) {
g.drawString(msg,10,250); } } D) ActionEvent, addActionListener(ActionEvent ae)
addActionListener(ActionEvent ae), actionPerformed(this)
a. The order of add(b1); , add(b2); , add(b3); statements is
incorrect. 16. How does a JToggleButton differ from a regular
b. The init() method is missing the super.init(); call. JButton?
c. There paint(); method should be called inside each if block. a. JToggleButton cannot be clicked.
d.The Button objects are not initialized properly. b. JToggleButton cannot have icons.
c. JToggleButton does not support action events.
14. Match The Pair ? 1) Button() a) AdjustmentListener 2) d. JToggleButton can be toggled on and off.
Scrollbar() b) Non Of Above 3) Checkbox() c) ItemListener
4) Label() d) ActionListener 17. How do you add a new tab to a JTabbedPane instance
named tabbedPane?
a. 1-a, 2-b, 3-c, 4-d a. tabbedPane.addTab(String title, Component component)
b. tabbedPane.add(String title, Component component)
b. 1-d, 2-a, 3-c, 4-b
c. tabbedPane.addTab(Component component, String title)
c. 1-d, 2-c, 3-b, 4-a d. tabbedPane.add(Component component, String title)
d. 1-d, 2-a, 3-b, d-c
18. What will be the order of four items added Choice c1 =
15. Fill in the blanks to complete the code and create a new Choice(); c1.add("First"); c1.addItem("Second");
correct sequence: c1.add("Third"); c1.insert("Lastadded",2);
import java.awt.*; import java.awt.event.*; a. First, Second, Third, Lastadded
public class MenuDemo extends Frame implements b. First, Second, Lastadded, Third
_______________ { // (1) Fill in the blank c. First, Lastadded, Second, Third
MenuDemo() { MenuBar mbr = new MenuBar(); d. Second, Lastadded, First, Third
Menu filemenu = new Menu("File");
19. The constructor JCheckBox(true, “YES”) suggests that –
Menu editmenu = new Menu("Edit"); a. Checkbox is initially selected and displays the string
Menu viewmenu = new Menu("View"); "YES" on it.
mbr.add(filemenu); mbr.add(editmenu); b. Checkbox is initially deselected and displays the
MenuItem new1 = new MenuItem("New"); string "YES" on it.
MenuItem open1 = new MenuItem("Open"); c. Checkbox is initially selected and displays a default
filemenu.add(new1); label on it.
filemenu.add(open1); d.Checkbox is initially deselected and displays a default
label on it.
new1._______________; // (2) Fill in the blank
open1.______________; // (3) Fill in the blank
}