You are on page 1of 6

Final Java2

Q1) which of the following statements is for terminating the program when
closing the frame?
A) frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
B) frame.setDefaultCloseOperation(null);
c) frame.setDefaultCloseOperation(JFrame.Stop_ON_CLOSE);
D) frame.setDefaultCloseOperation(JFrame.TERMINATE_ON_CLOSE);

Q2) What layout manager should you use so that every component
occupies the same size in the container?
A) A FlowLayout
B) A GridLayout
C) A borderLayout
D) All of the above
Q3) The method ________ sets the background color to yellow in JFrame f
A) f.setBackGroundColor(Color. YELLOW);
B) f.setBackGround(Color. YELLOW);
C) f.setBackColor(Color. YELLOW);
D) f.setBack(Color.YELLOW);

Q4) Given a JLabel label and a JPanel panel with border layout,which of the
following statements would you use to place the label at the top of the
panel?
A) The statement label.add(Panel.NORTH);
B) The statement Panel.add(label.BorderLayout.TOP);
C) The statement label.add(label.NORTH);
D) The statement label.add(label.TOP);
E) The statement Panel.add(label.BorderLayout.NORTH);
Q5) the GridLayout manager arranges components?
A) In the manner the user specifies
B) Left to right,row by row
C) Top to bottom,column by column
D) Depending on the layout manager used inside

Q6) which of the following is true about the code below?


Public class Test{
Public static void main (String[] args){
JFrame frame=new JFrame(“My Frame”)
frame.setLayout(new FlowLayout());
frame.add(new JButton(“OK”);
frame.add(new JButton(“Cancel”);
frame.setSize(200,200);
frame.setVisible(true);}}
A) Only button OK is displayed
B) Only button cancel is displayed
C) Both button OK and button Cancel are displayed and button OK is
displayed on the left side of button cancel
D) Both button OK and button Cancel are displayed and button OK is
displayed on the right side of button cancel

Q7) the method _________ sets the font(Helvetic,20-point bold) in


component C
A) C.setFont(new Font(“Helvetic”,Font.bold,20));
B) C.setFont(new Font(“Helvetic”,BOLD,20));
C) C.setFont(Font(“Helvetic”,Font.BOLD,20));
D) C.setFont(new Font(“Helvetic”,Font.BOLD,20));

Q8) to create a JPanel of the BorderLayout , use __________


A) JPanel p=new JPanel();
B) JPanel p=new JPanel(BorderLayout());
C) JPanel p=new JPanel( new BorderLayout());
D) JPanel p=new JPanel().setLayout(new BorderLayout());

Q9) Pressing a button generates a(n) _______ event


A) ItemEvent
B) MouseEvent
C) MouseMotionEvent
D) ActionEvent

Q10) a JLabel can be attached to a JFrame using method:


A) Attach
B) Contain
C) Append
D) Add
Q11) when the user presses enter in a JButton , the GUI component
generate an __________ which is processed by an object that implements
the interface_______
A) ActionEvent ,ActionListener
B) ActionEvent , ActionEventListener
C) TextEvent, TextListener
D) TextEvent, TextEventListener
Q12) forgetting to register an event-handler object for a particular GUI
components event type causes events of that type to be ignored
A) True
B) False

Q13) which of the following statement registers the listener refernce for a
button jbt?
A) addActionListener(p);
B) jbt. addActionListener(p);
C) jbt. addActionEventListener(p);
D) jbt.addEventListener(p);

Q14) an inner class is a class defined within the scope of another class
A) true
B) false

Q15) which of the method can be used to determine the source of event?
A) getEventObject();
B) getEvent();
C) getSource();
D) getID();
Q16) the ImageIcon object can be used with?
A) JButton
B) JTextField
C) JPanel
D) All of the above
Q17) which of the following statement correctly adds an action listener to
button btn1?
Public class Quiz extends JFrame implement ActionListener{
JButton btn1;
Quiz(){
btn1=new JButton(text :”ok”);
Add(btn1);
}
Public void actionPerformed(ActionEvent e){
System.out.Println(“hi”);
A) btn1.addActionListener(this);
B) btn1.addActionListener(new ActionListener());
C) btn1.getActionPerformed();
D) btn1.addListener(this);

Q18) which of these methods are used to register a mouse listener?


A) addMouse();
B) addMouseMotionListener();
C) eventMouseMotionListener();
D) addMouseListener();

Q19) which of the following in NOT a legal color in Java?


A) Color.red;
B) Color c=new Color(0,0,0);
C) Color c=new Color(255,255,255);
D) Color c=new Color(100,200,300);

Q20) In the GridLayout ,if the number of rows and columns are not
determined ,the default number of rows and columns will be?
A) 0,0
B) 1,0
C) 1,1
D) Compilation Error

Q21) if the region is not specified in the BorderLayout, the components will
by default be placed in the :*?
A) South
B) East
C) West
D) North
E) Center

Q1= A Q9= D Q17= B


Q2= B Q10= D Q18= D
Q3= B Q11= A Q19= D
Q4= E Q12= A Q20= C
Q5= B Q13= B Q21= E
Q6= C Q14= A
Q7= D Q15= C
Q8= C Q16= A

You might also like