0% found this document useful (0 votes)
38 views

AJP MCQ File3

The document contains 15 multiple choice questions related to Java GUI programming concepts. The questions cover topics like layout managers, events, components, and event handling.

Uploaded by

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

AJP MCQ File3

The document contains 15 multiple choice questions related to Java GUI programming concepts. The questions cover topics like layout managers, events, components, and event handling.

Uploaded by

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

Q1. How do you change the current layout manager for a container?

(CO-1) 1M
a) Use the setLayout() method b) Once created you cannot change the current layout manager
c) Use the setLayoutManager() method d) Use the updateLayout() method
Q2. The method gets the contents of the text field jtf. (CO-1) 1M
a) jtf.getText(s) b) jtf.getString()
c) jtf.getText( ) d) jtf.findString()
Q3. which of these are valid adapter classes (CO-1) 1M
a) ActionAdapter( ) b) AdjustmentAdapter()
c) TextAdapter d) KeyAdapter
Q4.Which Color is the darkest. (CO-1) 1M
a)new Color(0,0,0) b)new Color(10,0,0)
c)new Color(20,0,0) d)new Color(30,0,0)
Q5. Which class can be used to represent a checkbox with a textual label that can appear in a menu? Select
the one correct answer. (CO-1) 1M
a) MenuBar b)MenuItem
c) CheckboxMenuItem d)Menu
Q6. creates a dropdown list of textual entries (CO-1) 1M
a) Choice b) Checkbox
c) Textbox d) TextComponent
Q7. Event is generated when button is pressed, a list item is double clicked, or a menu item is
selected. (CO-3) 1M
a)ItemEvent b)AdjustmentEvent
c)ActionEvent d)MouseEvent
Q8. Suppose a JFrame uses the GridLayout(0,2). If you add six buttons to the frame, how many
columns are displayed? (CO-2) 1M
a) 1 b) 2
c) 3 d) 4
Q9. What is an event in the delegation event model used by the Java programming language? (CO-3) 1M
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.
Q10.Which checkbox will be selected in the following code ( Assume with main and added to a Frame)
(CO-1) 2M
Frame myFrame = new Frame("Test");
CheckboxGroup cbg = new CheckboxGroup();
Checkbox cb1 = new Checkbox("First",true,cbg);
Checkbox cb2 = new Checkbox("Second",true,cbg);
Checkbox cb3 = new Checkbox("Third",false,cbg);
cbg.setSelectedCheckbox(cb3);
myFrame.add(cb1);
myFrame.add(cb2);
myFrame.add(cb3);
a)cb1 b)cb2,cb1
c)cb1,cb2,cb3 d)cb3
Q11. select the missing statement in the program for the following output (CO-3) 2M
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code=ColorChange width=250 height=300> </applet>*/
public class ColorChange extends Applet implements ActionListener {
Button red;
public void init() {
red=new Button("RED");
add(red); }
public void actionPerformed(ActionEvent e)
{ setBackground(Color.red);
repaint(); }
}
a) addActionListener(this); b) addActionListener();
c) red.addActionListener(); d) red.addActionListener(this)
Q12. Select the missing statement in the program to get the following output (CO-3) 2M
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/* <applet code="ChoiceDemo" width=300 height=180> </applet> */
public class ChoiceDemo extends Applet implements ItemListener {
Choice city;
public void init() {
city.add("Nagpur");
city.add("Mumbai");
city.add("Pune");
city.add("Nashik");
add(city);
city.addItemListener(this); }
public void itemStateChanged(ItemEvent ie)
{ repaint(); }
public void paint(Graphics g) {
String msg = "Select city: ";
msg += city.getSelectedItem();
g.drawString(msg, 6, 120); }
}
a) new Choice(); b) city = new Choice();
c) city = Choice(); d) c= new choice( )

Q13. Select proper code for given output (CO-2) 2M


a) public class FlowTest extends Applet c) public class FlowTest extends
{ public void init() { Applet { public void init() {
setLayout(new FlowLayout()); // setLayout(new FlowLayout()); Default
for(int i=1; i<6; i++) { for(int i=1; i<6; i++) {
add(new Button("Button " + i)); } } } add(new Button("Button " + i)); } } }

b) public class FlowTest extends Applet d) public class FlowTest extends


Applet { public void init() {
{ public void init() {
setLayout(new
setLayout(new GridLayout(2,4));
BoxLayout()); for(int i=1;
for(int i=1; i<6; i++) { i<6; i++) {
add(new Button("Button " + i)); } } } add(new Button("Button " + i)); } }}
Q14. Select proper code for given output (CO-2) 2M

a) import javax.swing.*; import b) import


java.awt.*; public class javax.swing.*;
ShowLayout{ import
public static void main (String args[]) { JFrame f = java.awt.*;
new JFrame ("JFrame Example"); Container c = public class
f.getContentPane(); c.setLayout (new ShowLayout{
FlowLayout()); public static void main (String args[])
for (int i = 0; i < 5; i++) { c.add (new { JFrame f = new JFrame ("JFrame
JButton ("No")); Example"); Container c =
c.add (new JButton ("Batter")); } f.getContentPane(); c.setLayout
c.add (new JLabel ("Swing")); (new FlowLayout());
f.setSize (300, 200); f.show(); } } for (int i = 0; i <10; i+
+) { c.add (new
JButton ("No"));
c.add (new JButton ("Batter")); }
c.add (new JLabel
("Swing")); f.setSize
(300, 200);
f.show(); } }
c) import javax.swing.*; import d) import
java.awt.*; public class javax.swing.*;
ShowLayout{ import
public static void main (String args[]) { JFrame f = java.awt.*;
new JFrame ("JFrame Example"); Container c = public class
f.getContentPane(); c.setLayout (new ShowLayout{
FlowLayout()); public static void main (String args[])
for (int i = 0; i < 5; i++) { c.add (new { JFrame f = new JFrame ("JFrame
JButton ("No")); Example"); Container c =
c.add (new JButton ("Batter")); } f.setSize (300, f.getContentPane(); c.setLayout
200); (new FlowLayout());
f.show(); } } for (int i = 0; i <10; i++) {
c.add (new JButton
("Batter")); c.add (new
JButton ("No"));
c.add (new JLabel
("Swing")); f.setSize
(300, 200);
f.show(); } }

Q15. Consider the following program. Identify which are the event needs to get the correct output. (CO-3) 2M
import java.awt.*;
import java.awt.event.*;
class AEvent extends Frame implements {
TextField tf;
AEvent(){
tf=new TextField();
tf.setBounds(60,50,170,20);
Button b=new Button("click me");
b.setBounds(100,120,80,30);
b. (this);
add(b);add(tf);
setSize(300,300);
setLayout(null);
setVisible(true); }
public void ( e) {
tf.setText("Welcome"); }
public static void main(String args[]) {
new AEvent(); } }

a) ActionListener, addActionListener,actionPerformed, ActionEvent


b) TextListener, addTextListener,textValueChanged, TextEvent
c) ActionListener, addActionListener, textValueChanged, TextEvent
d) TextListener, addTextListener,actionPerformed, ActionEvent

Q16. creates a ImageIcon for the file c:\image\us.jpeg (CO-2) 1M


a) new ImageIcon(“c:\image\us.jpeg”);
b) new Icon(“c:\image\us.jpeg”);
c) new ImageIcon(“c:\\us.jpeg”);
d) new Icon(“c:\\us.jpeg”);
Q17.The method sets the background color to yellow in Frame f. (CO-2) 1M
a)setBackground(Color.yellow);
b)f.setBackground(Color.YELLOW);
c)f.setBackground(Color.yellow);
d) setBackground(Color.YELLOW);

You might also like