Swing II - GUI Flashcards
addWindowListener method
register a window listener for a window event
about 7 methods
create empty methods for methods that you dont want to use
window adapter class
- when class doesn’t need most of the methods
- only heading defined
- inherit trivial implementation from windowadapter
can only be done when the JFrame doesnt need to be derived from any other class
Icons
- small picture
ImageIcon dukeIcon = new ImageIcon(“duke_waving.gif”);
images must be in same directory
scroll bars
when using a scroll bar the text is viewes through a view port that shows only part of the text at a time
ScrollPane scrolledText = newJScrollPane(memoDisplay);
the horizontal and vertical scroll bar options/policies
Default - as needed
Never
Always
where on the plane is the (0,0) co-ordinate
top left corner
positive x direction - left to right
positive y direction - top down
adding elements to a frame using co-ord system
- everything is added with a rectangle (add a circle - the circle will be in a rectangle)
- adding a rectangle - location of upper left corner is stated
bounding box
imaginary rectangle that encloses everything that is added to the frame
paint method (only to be used for frames)
The method paint draws the component or container on the screen
public void paint(g){ super.paint(g); g.drawLine(dimension, dimension….,…)
}
the graphics class
The object g of the class Graphics can be used as the calling object for a drawing method–The drawing will then take place inside the area of the screen specified by g
what happens when the paint(g) method is invoked
g is replaced by the graphics object associated with the JFrame - therefore the images are drawn inside the JFrame
draw an oval
g.drawOval(x,y,width,height)
draw an arc
g.drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
draw a rounded rectangle
g.drawRoundRect(x, y, width, height, arcWidth, arcHeight)
what to use to draw figures on a panel
paintComponent