finasl Flashcards

(69 cards)

1
Q

JFrame

A

A window used for drawing in Java.

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

JComponent Subclass

A

A class that extends JComponent. This class acts like the canvas where programmatic drawing is done. It is where the paintComponent method is overridden. Requires importing java.awt., java.awt.geom., and javax.swing.*.

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

paintComponent(Graphics g)

A

A protected method of the JComponent class that you override to put your drawing code inside. It is automatically called when the component is added to the frame. A Graphics object is automatically passed to it.

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

Graphics object

A

Responsible for tasks such as setting the colour, drawing lines, and filling shapes.

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

Graphics2D object

A

An enhanced version of the Graphics object, obtained by casting the Graphics object. It allows for features like adding antialiasing to smoothen shape edges. This class is part of the awt package.

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

java.awt.geom

A

A Java package containing classes for creating shapes and paths, including Ellipse2D.Double, Line2D.Double, Path2D.Double, and Rectangle2D.Double.

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

Rectangle2D.Double

A

A class from java.awt.geom used to create rectangles. Its constructor takes four arguments: x and y for the shape’s location coordinates, and w and h for its dimensions (width and height). double values are valid arguments.

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

x and y coordinates

A

Represent the location of a shape. The point x=0 and y=0 is located at the top left corner of the JComponent’s container.

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

setColor(Color c)

A

A method of Graphics2D used to set the colour for subsequent drawing operations. The Color constructor accepts three int arguments (0 to 255) for RGB values. Alternatively, Color constants like Color.BLUE can be used.

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

fill(Shape s)

A

A method of Graphics2D used to fill a shape with the most recently set Color. Used for shapes like rectangles and circles.

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

draw(Shape s)

A

A method of Graphics2D used to draw the outline of a shape. Used for lines.

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

Order of drawing

A

The order in which shapes are drawn determines their layering. Shapes drawn first will appear behind succeeding shapes, which is more apparent if shapes overlap. Each succeeding shape appears higher in the stack.

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

Antialiasing

A

A technique used to smoothen the edges of shapes, especially curves, by blending the colours of the edges with the background. It is added by creating a RenderingHints object and passing it to the Graphics2D object using setRenderingHints(RenderingHints rh). This should be set before drawing the shapes.

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

Decluttering paintComponent

A

The practice of separating drawing elements into different classes, each with a draw method that accepts a Graphics2D object, to reduce the number of lines in the main paintComponent method and make it easier to maintain.

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

Reusability

A

Making drawing classes more flexible so that one class can be used to draw different variations of an object (e.g., clouds of different sizes, colours, and positions). This is achieved by adding instance fields (like x, y, size, colour) and a constructor to initialize them, then using these fields instead of hard coded values in the drawing method.

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

Path2D.Double

A

A class used to create geometric paths.

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

moveTo(x,y)

A

A method of Path2D.Double used to specify the starting point for a path. It moves the “pen” to the given coordinates. Can also be called between calls to lineTo to start a new segment at a different point.

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

lineTo(x,y)

A

A method of Path2D.Double used to create a path segment from the previous point to the specified coordinates. Multiple calls can be made to create more segments. Segments are not visible until fill or draw is called on the Graphics2D object.

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

curveTo(x1, y1, x2, y2, x3, y3)

A

A method used to create curved segments in a path using Bézier control points. It requires six arguments: (x1,y1) and (x2,y2) for the coordinates of the first and second Bézier control points, respectively, and (x3,y3) for the segment’s end point. The starting coordinate is determined by the end point of the previous segment.

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

Bézier control points (x1,y1, x2,y2)

A

Points used to create Bézier handles.

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

Bézier handles

A

Formed by connecting the segment’s starting point to the first Bézier control point and the second Bézier control point to the segment’s ending point. They act like levers that control the direction of the curve.

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

Transformations

A

Functions available in the Graphics2D class to apply changes like translation (adjusting coordinates), scaling, and rotation.

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

Translation

A

A transformation that moves the origin point (x:0, y:0) of the coordinate space. It is achieved using the translate(x,y) method of Graphics2D. Subsequent calls concatenate the translation values. To reset, you need to translate by the negative counterparts of the accumulated values.

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

translate(x,y)

A

A method of Graphics2D that moves the origin point of the coordinate space by the specified x and y values. It does not change the coordinates of the drawing object itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
AffineTransform
An object that contains the values representing a transformation's state, such as rotation or translation.
26
getTransform()
A method of Graphics2D used to retrieve the current transformation state as an AffineTransform object. Calling this method before applying any transformations allows you to obtain the default transformation state.
27
setTransform(AffineTransform at)
A method of Graphics2D that sets the current transformation state to the values contained in the provided AffineTransform object. This can be used to reset transformations.
28
Rotation
A transformation applied using the rotate method of Graphics2D. The angle must be provided in radians. You can use Math.toRadians(degrees) to convert degrees to radians. By default, rotation pivots from the coordinate space origin (x:0, y:0), but a pivot point can be specified using the three argument version rotate(angle, x, y). Succeeding calls to rotate will rotate based on the previous rotation unless the transformation is reset.
29
rotate(angle, x, y)
A method of Graphics2D that rotates the coordinate space by the specified angle (in radians) around the pivot point (x,y).
30
Collision detection
The process of determining if two objects overlap or occupy the same space. For the purposes of the source material, collision is true if any of their pixels overlap.
31
Position
The location of a graphical object, typically represented by x and y coordinates. In Java's coordinate system, increasing x moves right, decreasing x moves left, increasing y moves down, and decreasing y moves up.
32
Dimension
Represents the space an object occupies, such as width and height for a rectangle or radius for a circle.
33
Rectangle collision
Can be determined by checking if any of the conditions for non-collision are false. The conditions for non-collision are: the right edge of object 1 is less than or equal to the left edge of object 2; the left edge of object 1 is greater than or equal to the right edge of object 2; the bottom edge of object 1 is less than or equal to the top edge of object 2; or the top edge of object 1 is greater than or equal to the bottom edge of object 2.
34
isColliding(MyRectangle other)
A boolean method that returns true if the current MyRectangle object collides with another MyRectangle object. It is implemented by negating the conditions for non-collision.
35
isNotColliding(MyRectangle other)
An alternative boolean method that returns true if the current MyRectangle object does not collide with another MyRectangle object.
36
Circle collision
Can be determined by considering the distance between the centers of the two circles and comparing it to the sum of their radii. Circles collide if the distance between their centers is less than or equal to the sum of their radii.
37
Threads
Lightweight processes (LWPs) used to execute concurrent tasks. They must be spawned by another process or thread. Threads appear to run concurrently due to rapid processor switching (time slices) on a single processor, but can run simultaneously on multiple processors.
38
Lightweight process (LWP)
Another term for a thread.
39
Heavyweight process (HWP)
A traditional process.
40
Time slice
A certain amount of time the processor dedicates to executing a thread before switching to another.
41
Extending the Thread class
One of two ways to use threads in Java, where a class inherits from the Thread class.
42
Implementing the Runnable interface
The second way to use threads in Java, where a class implements the Runnable interface. This approach is useful if the class needs to extend another class.
43
run() method
The method that contains the task instructions to be executed by a thread. This method must be overridden when extending Thread or implementing Runnable.
44
start() method
Called on a Thread object (created either by extending Thread or wrapping a Runnable) to begin executing the code within the run() method in a new thread. Calling the run() method directly will execute the code but not in a separate thread.
45
Thread.sleep(milliseconds)
A static method of the Thread class that causes the current thread to pause for the specified number of milliseconds. Calls to sleep must be placed inside a try-catch block.
46
Key bindings
A mechanism in Java Swing to associate keyboard keystrokes with specific actions. It relies on ActionMap and InputMap, accessed from a JComponent.
47
ActionMap
Responsible for mapping an action (represented by an AbstractAction object) to a programmer-defined name. Accessed from a JComponent's content pane (often cast to a JPanel).
48
InputMap
Responsible for mapping a specific key on the keyboard (KeyStroke) to an action name defined in the ActionMap. Accessed from a JComponent's content pane (often cast to a JPanel).
49
AbstractAction
A class used to define the code that should be executed when a key binding is triggered. You override its actionPerformed(ActionEvent ae) method to specify the instructions.
50
KeyStroke.getKeyStroke(key code, modifier, on release)
A method used to create a KeyStroke object, which represents a specific key event. Arguments include the key code (e.g., KeyEvent.VK_UP), optional modifier keys (e.g., SHIFT), and a boolean indicating whether the binding is triggered on key press (false) or key release (true).
51
Client
Server Computing- A network communication model where a client requests services or resources from a server.
52
Client
A device on a network that initiates a connection and requests services or resources from a server.
53
Server
A system on a network that provides or serves requested services or resources to clients. A server waits for and accepts client connections, and then responds to their requests.
54
TCP/IP
A protocol suite used for communication over networks. It simplifies complex network operations and enables interoperability across different networks.
55
TCP (Transmission Control Protocol)
The part of TCP/IP responsible for establishing reliable connections and managing aspects like packet ordering and retransmissions.
56
IP (Internet Protocol)
The part of TCP/IP responsible for addressing and routing data packets between devices on a network.
57
Host
Any machine connected to a network, identifiable by a hostname or IP address.
58
Hostname
A string name used to identify a host on a network (e.g., "ateneo.edu").
59
IP address
A numerical address (a set of 4 bytes, e.g., "10.2.3.21") used to uniquely identify a host on a network.
60
Port
A number that identifies a specific service or application running on a host. Examples include port 80 for HTTP and port 25 for SMTP. A server can listen on multiple ports, and a single port can handle multiple clients.
61
Socket
An object that represents and encapsulates the process of communicating over a network connection. In a client program, a Socket is created to connect to a server's IP address and port. In a server program, a Socket object is returned by the ServerSocket.accept() method when a client connects. Socket objects provide input and output streams for sending and receiving data.
62
ServerSocket
A class used in server programs, primarily to wait for and accept incoming client connections. It is constructed with a port number to bind to. Its accept() method is used to listen for connections.
63
accept()
A method of ServerSocket that pauses the current thread until a client successfully connects. Once a connection is made, it returns a Socket object connected to that client.
64
InputStream / OutputStream
Streams obtained from a Socket object using getInputStream() and getOutputStream() methods, respectively. The InputStream is used for reading incoming data, and the OutputStream is used for writing outgoing data.
65
DataInputStream / DataOutputStream
Classes that can wrap standard InputStream and OutputStream objects to provide methods for easily reading and writing primitive data types (like strings using readUTF() and writeUTF(), or integers using readInt() and writeInt()).
66
localhost / 127.0.0.1
Special hostnames/IP addresses used to refer to the machine the code is running on, useful for testing client and server programs on a single computer.
67
Aligning Reads and Writes
When two hosts communicate over sockets, their reading and writing operations must be synchronised. If one host performs a write operation, the other host must perform a corresponding read operation to receive the data. They cannot both read or both write at the same time; the sequence of reads on one end must match the sequence of writes on the other.
68
Handling Multiple Connections
In a server program designed to handle multiple clients simultaneously, it is common to use threads. The main server thread can continuously listen for new connections using ServerSocket.accept(), and when a client connects, a new, separate "connection thread" is created and started to handle communication with that specific client.
69
Mixing Network and GUI Code
It is not recommended to place network code and GUI update code within the same thread because blocking network operations (like waiting to read data) can freeze the thread, preventing the GUI from updating. Network code should typically be executed in a separate thread to keep the GUI responsive.