Java Reference
In-Depth Information
There are a number of other ways to accomplish the same thing. Here are two of
a number of valid alternatives:
JButton magicButton =
new
JButton("Magic Button");
magicButton.setIcon(
new
ImageIcon("wizard.gif"));
ImageIcon wizardIcon =
new
ImageIcon("wizard.gif");
JButton magicButton =
new
JButton("Magic Button", wizardIcon);
6.
ImageIcon wizardIcon =
new
ImageIcon("wizard.gif");
JLabel wizardPicture =
new
JLabel(wizardIcon);
picturePanel.add(wizardPicture);
There are a number of other ways to accomplish the same thing. Here is one valid
alternative:
picturePanel.add(
new
JLabel(
new
ImageIcon("wizard.gif")));
7.
ImageIcon wizardIcon =
new
ImageIcon("wizard.gif");
JButton magicButton =
new
JButton(wizardIcon);
magicButton.setActionCommand("Kazam");
There are a number of other ways to accomplish the same thing. Here is one valid
alternative:
JButton magicButton =
new
JButton(
new
ImageIcon("wizard.gif"));
magicButton.setActionCommand("Kazam");
8. No. You can invoke none, one, or both methods.
9. No. The class
JTextArea
is a descendent class of the class
Component
. So, every
JTextArea
is also a
Component
.
10.
g.drawLine(30, 40, 100, 60);
11.
g.drawLine(30, 40, 130, 40);
12.
graphicsObject.drawLine(30, 40, 30, 140);
13.
graphicsObject.fillRect(20, 30, 100, 50);
14.
g.fillRect(200, 300, 100, 50);
15.
g.drawOval(250, 350, 100, 100);
16.
g.drawOval(200, 300, 200, 200);
17. Insert
g.setColor(Color.GREEN)
as indicated next:
//
Draw Eyes:
g.setColor(Color.BLUE);
g.fillOval(X_RIGHT_EYE, Y_RIGHT_EYE, EYE_WIDTH, EYE_HEIGHT);
g.setColor(Color.GREEN);
g.fillOval(X_LEFT_EYE, Y_LEFT_EYE, EYE_WIDTH, EYE_HEIGHT);