0% found this document useful (0 votes)
18 views11 pages

02 Swing

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views11 pages

02 Swing

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Sr. 7.

A JFrame supports three operations when the


No.
QUESTION
user closes the window. Which of the choices
1. __________ is a Swing class that allows the below is not one of the three:
user to enter a single line of text. A. DISPOSE_ON_CLOSE
A. TextField B. DO_NOTHING_ON_CLOSE
B. JTextField C. LOWER_ON_CLOSE
C. EditTextField D. HIDE_ON_CLOSE
D. TextArea Answer: C
Answer: B
8. A ______ is component that presents a
2. __________ method is used to add items in rectangular area in which a component may
Combobox. be viewed
A. add() A. Tabbed Pane
B. addElement() B. Scroll Pane
C. insert() C. Glass Pane
D. addItem() D. All of above
Answer: D Answer: B

3. ___________________ is not a Swing 9. All swing component classes are placed in


Component A. java.awt
A. ButtonGroup B. javax.awt
B. Jlabel C. java.swing
C. Jbutton D. javax.swing
D. CheckboxGroup Answer: D
Answer: D
10. Default layout of JPanel is
4. _______ follows Model view contoller A. BorderLayout
architecture B. FlowLayout
A. AWT C. GridLayout
B. Swing D. None of the above.
C. Both i & ii Answer: B
D. None of the above
Answer: B 11. getContentPane() is method of which class
A. Container
5. ………………….. control is used to choose one B. JApplet
option from multiple options. C. javax.swing
A. JCheckBox D. JFrame
B. JTabbedPane Answer: A
C. JRadioButton
D. JButton 12. In MVC architecture, MVC stands for?
Answer: C A. Model Visiblity Control
B. Module Visiblity Contol
6. A component that combines a button or C. Menu View Component
editable field and a drop-down list. D. Model View Controller
A. JComboBox Answer: D
B. JButton
C. JTextField 13. In Swing ____________is a component that
D. JLabel displays rows and columns of data.
Answer: A A. card
B. tree
C. table
D. tabbed Pane
Answer: C D. None
Answer: C
14. In Swing Buttons are the subclasses of which
class? 21. The setToolTipText() method is used
A. AbstractButton __________
B. Jbutton A. To set up a tool tip for any JComponent
C. Button B. To set up a label for any Jcomponent
D. JRadioButton C. To set up a tool button for any JComponent
Answer: A D. To set up a tool bar
Answer: A
15. In swing MVC architecture use in that M stand
for 22. The Swing component classes that are used in
A. Modless encapsulate a mutually exclusive set of
B. Model buttons are
C. Master A. AbstractButton
D. Meta B. ButtonGroup
Answer: B C. Jbutton
D. ImageIcon
16. Swing contols are ___________________ Answer: B
A. Platform Dependant
B. Platform Independent 23. To use swing components ____ package is
C. Both(I & II) imported
D. None of above A. java.swing
Answer: B B. javax.swing
C. javaj.swing
17. Swing has following features D. javas.swing
A. Platform Independent Answer: B
B. Pluggable look and feel
C. Lightweight components 24. What class provides methods for creating and
D. All of these displaying basic dialog boxes?
Answer: D A. Jwindow
B. Jframe
18. Swing is not a part of JFC (Java Foundation C. Jcomponent
Classes) that is used to create GUI application? D. JOptionPane
A. True Answer: D
B. False
Answer: B 25. What is the purpose of following code?
JTextField jtf=new JTextField(15)
19. The component for storing and handling data, A. Defining Textfield
known as _________, contains the actual B. Adding textfeld
contents of the component C. Layout managing
A. a model D. content pane creation
B. a view Answer: A
C. a controller
D. all of the mentioned 26. What letter precedes Swing component
Answer: A names that have a corresponding AWT
component?
20. The default layout out of a contentPane in a A. A
JFrame is ______________ B. S
A. FlowLayout C. C
B. GridLayout D. J
C. BorderLayout Answer: D
C. JPanel p = new JPanel(new BorderLayout());
27. Which are the following components act as a D. JPanel p = new JPanel().setLayout(new
button in a swing. BorderLayout();
A. JButton ANSWER: C
B. JCheckbox
34. To add a component c to a JPanel p, use ____.
C. JToggleButton,JRadioButton
A. p.add(c).
D. All of these B. p.getContentPane(c)
Answer: D C. p.insert()
D. p.append(c)
28. Which componant canot be added to a ANSWER: A
container?
A. JPanel 35. The method _____ sets the foreground color to
B. JButton yellow in JFrame f.
C. JComponent A. setForeground(Color.yellow)
D. JFrame B. f.setForeground(Color.YELLOW)
C. f.setForeground(Color.yellow);
Answer: D
D. setForeground(Color.YELLOW)
ANSWER: C
29. Which is swing Components?
A. ImageIcon,Japplet,CheckBoxGroup
B. ImageIcon,JChoiceBox,Jbutton
C. JApplet,JButton,JTabbedPane
D. Japplet,Jbutton,JTabbedPane,JTreePane
Answer: C

30. Which is true about swing?


A. Swing components are platform
independent.
B. Swing is also called as JFC(Java Foundation
Class)
C. Swing components are light weight.
D. All the above
Answer: D

31. Suppose a JFrame uses the GridLayout(2, 2). If you


add six buttons to the frame, how many columns
are displayed?
A. 1
B. 2
C. 3
D. 4
ANSWER: C

32. The default layout out of a contentPane in a


JFrame is
A. FlowLayout
B. GridLayout
C. BorderLayout
D. None
ANSWER: A

33. To create a JPanel of BorderLayout, use _____.


A. JPanel p = new JPanel()
B. JPanel p = new JPanel(BorderLayout());
Sr.
QUESTION
No.
36. What components will be needed to get following output?

A. JApplet, JComboBox, JCheckBox, JButton


B. JApplet, JComboBox, JRadioButton, JButton
C. JFrame, JComboBox, JRadioButton, JButton
D. JFrame, JComboBox, JCheckBox, JButton

Answer: C

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

A. JApplet, JCheckBox, JComboBox, Jbutton


B. JApplet, JRadioButton, JList, Jbutton
C. JFrame, JCheckBox, JChoice, Jbutton
D. JFrame, JRadioButton, JList, Jbutton

Answer: A

38. Which components are used in the following output-

A. JFrame, JLabel, JRadioButton, JButton


B. JApplet, JLabel, JTextField, JButton
C. JFrame, JLabel, JCheckbox, JButton
D. JDialog, JLabel,JRadioButton,JButtonGroup

Answer: A
39. Which Components need to be used to produce this output

A. JTextArea
B. JTabbedPane and TextArea
C. JTabbedPane and icon
D. JtabbedPane,JLabel and ImageIcon
Answer: D

40. State the missing statement in the following code


import java.awt.*;
import java.applet.*;
import javax.swing.*;
/*<applet code="Exp4.class" width=400 height=300></applet>*/
public class Exp4 extends JApplet
{
public void init()
{
Container co=getContentPane();
co.setLayout(new FlowLayout());
JComboBox jc =new JComboBox();
jc.addItem("Cricket");
jc.addItem("Football");
jc.addItem("Hockey");
jc.addItem("tennis");
} }
A. co.addItem(jc);
B. import java.awt.event.*;
C. co.add(jc);
D. all of above
Answer: C

41. Debug the given program so as to get the following output


import java.awt.*;
import javax.swing.*;
/*<applet code="test" width=200 height=200> </applet>*/
public class test extends JApplet
{
public void init()
{
Container c=getContentPane();
JTabbedPane jp=new JTabbedPane();
JButton b1=new JButton("COMP.TECH"); p1.add(b1);
JButton b2=new JButton("INFO.TECH"); p1.add(b2);
JButton b3=new JButton("ELEC.ENGG"); p1.add(b3);
JButton b4=new JButton("FIRST"); p2.add(b4);
JButton b5=new JButton("SECOND"); p2.add(b5);
JButton b6=new JButton("THIRD"); p2.add(b6);
jp.addTab("Branch",p1);
jp.addTab("Year",p2);
c.add(jp);
}
}
A. JPanel p2=new JPanel(); JButton b3=new JButton("ELEC.ENGG");
B. JPanel p2=new JPanel(); JPanel p1=new JPanel();
C. /*<applet code="test" width=200 height=200> </applet>*/
D. jp.addTab("Branch"); jp.addTab("Year");
Answer: B

42. Identify the code for the output given below.

A. B.
import java.awt.*; import java.awt.*;
import javax.swing.*; import javax.swing.*;
public class Demo extends JApplet { public class Demo extends JApplet {
JButton b1,b2; JButton b1,b2;
JCheckBox cb1,cb2; JCheckBox cb1,cb2;
public void init() { public void init() {
Container c=getContentPane(); Container c=getContentPane();
c.setLayout(new FlowLayout()); c.setLayout(new FlowLayout());
cb1=new JCheckBox("Red"); cb1=new JCheckBox("Red",true);
cb2=new JCheckBox("Blue"); cb2=new JCheckBox("Green",false);
b1=new JButton("Submit"); b1=new JButton("Submit");
b2=new JButton("Reset"); b2=new JButton("Reset");
c.add(cb1); c.add(cb2); c.add(b1); c.add(b2); c.add(b1); c.add(b2); c.add(cb1); c.add(cb2);
} } } }

C. D. None of these
import java.awt.*;
import javax.swing.*;
public class Demo extends JApplet {
JButton b1,b2;
JCheckBox cb1,cb2;
public void init() {
Container c=getContentPane();
c.setLayout(new FlowLayout());
cb1=new JCheckBox("Red", true);
cb2=new JCheckBox("Blue", false);
b1=new JButton("Submit");
b2=new JButton("Reset");
c.add(cb1); c.add(cb2); c.add(b1); c.add(b2);
} }
Answer: C

43. Find the error in the following code.


import java.awt*;
import java.awt.event.*;
import java.applet.*;
public class RadioDemo extends JApplet
{
public void init()
{
Container c=getContentPane();
JRadioButton b1=new JRadioButton("Red");
JRadioButton b2=new JRadioButton("Blue");
c.add(b1);
c.add(b2);
} }
A. The radiobuttons should be added to ButtonGroup object.
B. package is missing
C. A and B
D. the class used for creating radiobuttons should not be JRadioButton
Answer: C

44. Identify the missing statement in the following program:


import java.awt.*;
import java.awt.event.*;
public class JTxtFld extends JApplet
{
public void init()
{
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
JTextField tf;
JTextArea ta=new JTextArea();
tf = new JTextField("TYPE HERE");
contentPane.add(tf);
} }
A. import javax.swing.*;
B. contentPane.add(ta);
C. import javax.swing.*;
contentPane.add(tf);
D. none of these

Answer: A

45. Select the correct code for display the given output

A. B.
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
public class ShowLayout extends JFrame public class ShowLayout extends JFrame
{ {
public ShowLayout (String s) public ShowLayout (String s)
{ {
Container c = f.getContentPane(); Container c = f.getContentPane();
c.setLayout (new FlowLayout()); c.setLayout (new FlowLayout());
c.add (new Button("NO"); for (int i = 0; i < 5; i++)
c.add (new Button("Batter"); {
c.add(new Label("Swing")); c.add (new Button("NO");
} }
public static void main (String args[]) c.add (new Button("Batter");
{ c.add(new Label("Swing"));
JFrame f = new }
ShowLayout("JFrameExample"); public static void main (String args[])
f.setVisible(true); {
} } JFrame f = new
ShowLayout("JFrameExample");
f.setVisible(true);
} }

C. D.
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
public class ShowLayout extends JFrame public class ShowLayout extends JFrame
{ {
public ShowLayout (String s) public ShowLayout (String s)
{ {
Container c = f.getContentPane(); Container c = f.getContentPane();
c.setLayout (new FlowLayout()); c.setLayout (new FlowLayout());
for (int i = 0; i < 5; i++) for (int i = 0; i < 4; i++)
{ {
c.add (new Button("NO"); c.add (new Button("NO");
c.add (new Button("Batter"); c.add (new Button("Batter");
} }
c.add(new Label("Swing")); c.add(new Label("Swing"));
} }
public static void main (String args[]) public static void main (String args[])
{ {
JFrame f = new JFrame f = new
ShowLayout("JFrameExample"); ShowLayout("JFrameExample");
f.setVisible(true); f.setVisible(true);
} } } }

Answer: C

46. Select the missing statement in given code


import java.awt.*;
import javax.swing.*;
/*<applet code="toggle" width=400 height=400> </applet>*/
public class toggle extends JApplet
{
JToggleButton t=new JToggleButton(new ImageIcon("Desert.jpg"));
public void init()
{
t.setPressedIcon(new ImageIcon("Tulips.jpg"));
} }
A. Container c=getContentPane();
B. c.add(t);
C. both a&b
D. nothing is missing
Answer: C

47. Select the missing statement in the following code


import java.awt.FlowLayout;
public class HelloWorldSwing1 extends JFrame {
public static void main(String[] args) {
JFrame frame = new JFrame("HelloWorldSwing");
JLabel label = new JLabel("Hello World");
JButton b1=new JButton("submit");
JTextField t1=new JTextField(10);
frame.getContentPane().add(label);
frame.getContentPane().add(t1);
frame.getContentPane().add(b1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
frame.getContentPane().setLayout(new FlowLayout());
} }
A. import javax.swing.*;
B. import javax.Swing.io.*;
C. import javax.Swing.awt.*;
D .import java.Swing.*;
Answer: A

48. Select the missing statement in the program to get the following output
import java.awt.*;
import javax.swing.*;
/* <applet code="JComboBoxdemo" width=300 height=200> */
public class JComboBoxdemo extends JApplet
{
public void init()
{
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
JComboBox jc = new JComboBox();
jc.addItem("France");
jc.addItem("Germany");
jc.addItem("Italy");
jc.addItem("Japan");
contentPane.add(jc);
}}
A. </applet>
B. import java.awt.event.*;
C. }
D. {
Answer: A

49. 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
Answer: C

50. To get output as shown in fig. complete following code?


import java.awt.*;
import javax.swing.*;
public class MyFlowLayout{
JFrame f;
MyFlowLayout(){
JButton b1=new JButton("1");
JButton b2=new JButton("2");
JButton b3=new JButton("3");
JButton b4=new JButton("4");
JButton b5=new JButton("5");
f.add(b1);f.add(b2);f.add(b3);f.add(b4);f.add(b5);
f.setSize(300,300);
f.setVisible(true);
}
public static void main(String[] args) {
new MyFlowLayout();
} }

A. f=new JFrame();
f.setLayout(new FlowLayout(FlowLayout.RIGHT));
B. f.setLayout(new FlowLayout(FlowLayout.RIGHT));
C. f=new JFrame();
D new JFrame();
setLayout(new FlowLayout(FlowLayout.RIGHT));
Answer: A

You might also like