AJP
AJP
A ____ is a passive AWT control that does not generate any event.
a) Button
b) Choice
c) Panel
d) Label
Answer: d) Label
Which package contains the Java Swing classes?
a) java.lang
b) java.io
c) java.util
d) javax.swing
Answer: d) javax.swing
Which AWT component is used to create a text control that can display multiple lines of text?
a) TextArea
b) TextPane
c) TextField
d) MultiLineText
Answer: a) TextAreaWhich class is used as the base class for all Swing components?
a) Component
b) Container
c) JPanel
d) JFrame
Answer: a) Component
java
Copy code
import java.awt.*;
import java.applet.*;
public class Ellipses extends Applet {
{
g.drawOval(10, 10, 50, 50);
g.fillOval(100, 10, 75, 50);
g.drawOval(190, 10, 90, 30);
g.fillOval(70, 90, 140, 100);
}
}
a) public void init()
b) public void paint(Graphics g)
c) public static void main(String args[])
d) public void paint(String s)
Answer: b) public void paint(Graphics g)
For the below code, how is a JTable object created?
java
Copy code
String[] colHeads = { "Name", "Extension", "ID#" };
Object[][] data = {{"Gail", "4567", "865"},{"Ken", "7566", "555"}};
a) Table jt = new JTable(colHeads);
b) Table jt = new JTable(data);
c) Table jt = new JTable(data, colHeads);
d) All of the above
Answer: c) Table jt = new JTable(data, colHeads)
java
Copy code
DefaultMutableTreeNode style = new DefaultMutableTreeNode("Style");
DefaultMutableTreeNode color = new DefaultMutableTreeNode("color");
style.add(color);
DefaultMutableTreeNode red = new DefaultMutableTreeNode("red");
DefaultMutableTreeNode blue = new DefaultMutableTreeNode("blue");
DefaultMutableTreeNode black = new DefaultMutableTreeNode("black");
DefaultMutableTreeNode green = new DefaultMutableTreeNode("green");
color.add(red);
color.add(black);
color.add(green);
JTree jt = new JTree(style);
a) color.add(red);
b) color.add(blue);
c) color.add(black);
d) color.add(green);
Answer: b) color.add(blue)
Fill up the correct listener name and event name in the code:
java
Copy code
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/* <applet code="SimpleKeyDemo" width=300 height=100> </applet> */
public class SimpleKeyDemo extends Applet implements _____________ {
String msg = "";
int X = 10, Y = 20;
public void init() {
addKeyListener(this);
requestFocus();
}
public void keyPressed( _________ ke) {
showStatus("Key Down");
}
public void keyReleased( _________ ke) {
showStatus("Key Up");
}
public void keyTyped( ____________ ke) {
msg += ke.getKeyChar();
repaint();
}
public void paint(Graphics g) {
g.drawString(msg, X, Y);
}
}
a) KeyListener, KeyEvent
b) MouseListener, MouseEvent
c) ActionListener, ActionEvent
d) TextListener, TextEvent
Answer: a) KeyListener, KeyEvent
True or False: The Container class can contain other components like buttons, text fields, and
panels.
a) TRUE
b) FALSE
Answer: a) TRUE
Which method in Java Swing can be used to set the text color of a component?
a) setBackground(Color clr)
b) setForeground(Color clr)
c) setColor(Color clr)
d) setTextColor(Color clr)
Answer: b) setForeground(Color clr)
True or False: The java.awt package contains only the core classes required for event handling.
a) TRUE
b) FALSE
Answer: b) FALSE
Which of the following methods can be used to add a MouseMotionListener to a component?
a) addMouseListener()
b) addMouseMotionListener()
c) addMouseMoveListener()
d) addMouseDragListener()
Answer: b) addMouseMotionListener()