Swing II - GUI Flashcards

1
Q

addWindowListener method

A

register a window listener for a window event
about 7 methods
create empty methods for methods that you dont want to use

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

window adapter class

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Icons

A
  • small picture
    ImageIcon dukeIcon = new ImageIcon(“duke_waving.gif”);
    images must be in same directory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

scroll bars

A

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);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

the horizontal and vertical scroll bar options/policies

A

Default - as needed
Never
Always

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

where on the plane is the (0,0) co-ordinate

A

top left corner

positive x direction - left to right
positive y direction - top down

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

adding elements to a frame using co-ord system

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

bounding box

A

imaginary rectangle that encloses everything that is added to the frame

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

paint method (only to be used for frames)

A

The method paint draws the component or container on the screen

public void paint(g){ super.paint(g); g.drawLine(dimension, dimension….,…)
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

the graphics class

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what happens when the paint(g) method is invoked

A

g is replaced by the graphics object associated with the JFrame - therefore the images are drawn inside the JFrame

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

draw an oval

A

g.drawOval(x,y,width,height)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

draw an arc

A

g.drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

draw a rounded rectangle

A

g.drawRoundRect(x, y, width, height, arcWidth, arcHeight)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what to use to draw figures on a panel

A

paintComponent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

jfram, jpanel and component vs jcomponent

A

A JPanelis a JComponent, but a JFrameis a Component, not a JComponent

17
Q

repaint method

A

The repaint method should be invoked when the graphics content of a window is changed

18
Q

how does repaint work

A
  • The repaintmethod takes care of some overhead, and then invokes the method paint, which redraws the screen
    –Although the repaintmethod must be explicitly invoked, it is already defined
    –The paintmethod, in contrast, must often be defined, but is not explicitly invoked
19
Q

the validate method - google an explanation

A

causes a container to lay out its components again

It is a kind of “update” method that makes changes in the components shown on the screen–Every container class has the validatemethod, which has no arguments

20
Q

g.setColor(Color.BLUE)

A

changes the colour of the pen

21
Q

custom colours

A

Color brown = new Color(200, 150, 0);

only type int or type float (dont forget to use a type cast)

22
Q

the drawString

A

g.drawString(theText, X_START, Y_Start);

23
Q

fonts

A

the constructor for the Font class creaere a font in the given style and size

Font fontObject = new Font(“SansSerif”, Font.PLAIN, POINT_SIZE);

24
Q

hoe to set the font for the drawString() within the paint()

A

g.setFont(fontObject);