-
Notifications
You must be signed in to change notification settings - Fork 0
GraphWin
The GraphWin class is part of the graphics package and provides a graphical window where graphical objects can be drawn and interacted with. It supports various graphical objects like shapes, text, and images and allows mouse and keyboard interactions. The class is primarily used to create graphical windows in interactive applications.
-
public static final Color[] STANDARD_COLORS
A set of standard colors used in graphical objects. -
private int width
The width of the window. -
private int height
The height of the window. -
private int preferedX
Preferred width of the window (calculated during initialization). -
private int preferedY
Preferred height of the window (calculated during initialization). -
public Panel panel
The panel within the window that handles rendering graphical objects. -
private ArrayList<GraphicsObject> items
A list of graphical objects in the window. -
public boolean autoflush
Indicates whether the window should automatically flush and repaint after every change. -
private CountDownLatch latch
A latch for synchronizing mouse click events. -
private Point mousePosition
The current position of the mouse in the window. -
private double deltaTime
The time difference between the last update and the current update. -
private long lastTime
The timestamp of the last update. -
private int lastKey
The last key pressed by the user. -
public boolean redraw
Indicates whether the window needs to be redrawn. -
private final ArrayList<Integer> keysPressed
A list of keys that are currently pressed.
Creates a graphical window with the specified width, height, title, and autoflush setting.
Parameters:
-
Name- The title of the window. -
w- The width of the window. -
h- The height of the window. -
Autoflush- Whether the window should automatically flush and repaint.
Creates a graphical window with the specified width, height, and title. The autoflush setting is set to false by default.
Parameters:
-
Name- The title of the window. -
w- The width of the window. -
h- The height of the window.
Removes a graphical object from the window.
Parameters:
-
object- The graphical object to remove.
Adds a graphical object to the window.
Parameters:
-
object- The graphical object to add.
Updates the window by calculating delta time and forcing a repaint.
Returns the time difference (delta time) between the last update and the current update.
Returns:
-
double- The delta time in seconds.
Retrieves the color at the specified point in the window.
Parameters:
-
x- The x-coordinate of the point. -
y- The y-coordinate of the point.
Returns:
-
Color- The color at the point, ornullif no component exists at the point.
This method blocks until the mouse is clicked then returns True.
Returns:
-
boolean- true.
Returns the current position of the mouse as a Point.
Returns:
-
Point- Current mouse position relative to the window.
Waits for a key press and returns the key that was pressed. This method blocks until a key is pressed.
Returns:
-
int- The key that was pressed.
Checks and returns the current position of the mouse without waiting for a click.
Returns:
-
Point- The current mouse position.
Returns the current width of the GraphWin object.
Returns:
-
int- The current width.
Returns the current height of the GraphWin object.
Returns:
-
int- The current height.
Sets the background color of the window.
Parameters:
-
clr- The color to set the background.
Sets the preferred size of the panel inside the window.
Parameters:
-
d- The preferred size of the panel.
Returns a list of the keys that are currently pressed.
Returns:
-
ArrayList<Integer>- A list of pressed keys.
An inner class that represents the panel within the window that handles rendering graphical objects. It overrides the paintComponent method to draw the graphical objects onto the panel.