Term
In order to draw things on a component what do you need to do? |
|
Definition
Define a class that extends JPanel and overrides its paintComponent method. |
|
|
Term
How do you override a paintComponent method? |
|
Definition
|
|
Term
What are the first 3 lines in drawing a polygon? |
|
Definition
Polygon polygon = new Polygon(); polygon.addPoint(x, y); g.drawPolygon(polygon) |
|
|
Term
|
Definition
drawArc(int x, int y, int h, int angle1, int angle2); |
|
|
Term
What kind of class is FontMetrics? |
|
Definition
|
|
Term
How do you get a fontMetrics object for a specific font? |
|
Definition
getFontMetrics methods defined in the graphics class. |
|
|
Term
How do you create an image icon and display it in a label? |
|
Definition
ImageIcon icon = new ImageIcon("image/us.gif");
Jlabel jlblImage = new JLabel(icon); |
|
|
Term
To make an image a flexible size what class do you use? |
|
Definition
|
|
Term
What is the difference between displaying images in a JLabel and in a JPanel? |
|
Definition
An image displayed on a label is not flexible, but an image displayed on a panel is stretchable. |
|
|
Term
Draw a thick line from (10,10) to (70, 30). You can draw several lines next to each other to create the effect of one thick line. |
|
Definition
for (int i = 0; i < 10, i++) g.drawLine(10, 10 + i, 70, 30 +i) |
|
|
Term
Can you draw things on any Swing GUI component? Why should you use a panel as a canvas for drawings rather than a label or a button? |
|
Definition
Yes, you should declare a canvas by subclassing JPanel because it is made to display things. where as labels are more for buttons. |
|
|
Term
What is an event defined as? |
|
Definition
a signal sent to a program saying that something has happened. |
|
|
Term
|
Definition
Mouse movements, mouse clicks, keystrokes, or by the operating system, such as a timer. |
|
|
Term
How do you identify the source object of the event? |
|
Definition
getSource() instance method in the EventObject class. |
|
|
Term
What are examples of subclasses of EventObject? |
|
Definition
button actions, window events, component events, mouse movements, keystrokes. |
|
|
Term
What does a listener class do? |
|
Definition
Create a listener object for a GUI component (eg., a button). |
|
|
Term
Where do you define the listener class? |
|
Definition
inside of the frame class |
|
|
Term
Can a listener class be shared by other applications? |
|
Definition
|
|
Term
What are 2 advantages of using an inner class? |
|
Definition
It can reference data and methods defined in the outer class.
It can make programs more simple. |
|
|
Term
An inner class is a ________ of another class. |
|
Definition
|
|
Term
An inner class is compiled into a class named. |
|
Definition
OuterClassName$InnerClassName.class
example: OuterClass$InnerClass.class |
|
|
Term
Can an inner class can be defined as static. True or false? |
|
Definition
|
|
Term
How do you access a static inner class? |
|
Definition
Through the outside class. |
|
|
Term
Can a static class access non-static members of the outer class? |
|
Definition
|
|
Term
Inner class listeners cant be shortened using anonymous inner classes? True or false |
|
Definition
|
|
Term
What is an anonymous inner class? |
|
Definition
an inner class without a name. |
|
|
Term
What does an anonymous inner class do? |
|
Definition
It combines declaring an inner class and creating an instance of a class in one step. |
|
|
Term
how do you register a listener object? |
|
Definition
you invoke the source objects's addXListener's method.
example: button.AddActionListener(this). |
|
|
Term
How do you implement a listener interface? |
|
Definition
you add implements XListener and implement all the handlers in the listener's object. |
|
|
Term
Can a source have multiple listeners? |
|
Definition
|
|
Term
Can a listener listen on multiple sources? |
|
Definition
|
|
Term
Can a source be a listener for itself? |
|
Definition
|
|
Term
Can an inner class be used in a class other than the class in which it nests? |
|
Definition
|
|
Term
When does the 'mouse entered' event happen? |
|
Definition
when the mouse pointer is moved onto a component. |
|
|