Javadoc: Menu Class
- java.lang.Object
-
- Menu
-
public class Menu extends java.lang.Object
This Menu class controls the user's interaction with the menu bar and the appearance of the menu bar.
Submitted to AP Computer Science 12: 2015-01-27
Last modified: 2015-04-04
Author: Samantha Yu
-
-
Field Summary
Fields Modifier and Type Field and Description (package private) java.awt.Rectangle
brushRect
Menu buttons are not physically seen but are the "click-able" items.(package private) java.awt.Font
btnFont
Font used for the title of the buttons.(package private) java.awt.Rectangle
colorRect
Menu buttons are not physically seen but are the "click-able" items.(package private) java.awt.Rectangle
delRect
Menu buttons are not physically seen but are the "click-able" items.(package private) java.awt.Color
fontColor
These variables are used for the appearance of the menu.(package private) java.awt.Graphics2D
g2Menu
g2Menu will paint graphics onto the menuImage to update the menu when necessary.(package private) java.awt.Color
layerBtnColor
These variables are used for the appearance of the menu.(package private) Layers
layersArray
A Layers object that controls the creation and deletion of layers, and what happens when the user wants to move to a different layer.(package private) java.awt.Color
menuColor
These variables are used for the appearance of the menu.(package private) java.awt.image.BufferedImage
menuImage
To prevent the menu bar being erased when the window is no longer active, menuImage will store the current image.(package private) java.awt.Rectangle
menuRect
Menu buttons are not physically seen but are the "click-able" items.(package private) java.awt.Rectangle
newRect
Menu buttons are not physically seen but are the "click-able" items.(package private) java.awt.Rectangle
nextRect
Menu buttons are not physically seen but are the "click-able" items.private int
numTool
These variables are passed on to the Tools methods to control how the user paints onto the canvas.(package private) java.awt.Color
paintColor
These variables are used for the appearance of the menu.(package private) PaintApp
paintLab
A PaintApp object has only one instance and allows this class to access its non-static methods and fields.(package private) java.awt.Rectangle
pencilRect
Menu buttons are not physically seen but are the "click-able" items.(package private) java.awt.Rectangle
prevRect
Menu buttons are not physically seen but are the "click-able" items.(package private) java.awt.Color
selectColor
These variables are used for the appearance of the menu.(package private) java.awt.Color
sizeColor
These variables are used for the appearance of the menu.(package private) java.awt.Rectangle
sizeRect
Menu buttons are not physically seen but are the "click-able" items.(package private) java.awt.Rectangle
sprayRect
Menu buttons are not physically seen but are the "click-able" items.(package private) java.lang.String
stringStroke
This variable is used when getting the color from the dialog boxes of the JColorChooser.private int
strokeSize
These variables are passed on to the Tools methods to control how the user paints onto the canvas.(package private) java.awt.Color
toolColor
These variables are used for the appearance of the menu.
-
Constructor Summary
Constructors Constructor and Description Menu(PaintApp pLab, Layers lArray)
When the Menu object is constructed, the invisible but "click-able" buttons are also constructed.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description private void
changeColorMenu()
After the user has selected their new color, the menu's color button is updated with the newly selected color.void
changeLayerMenu()
When the user has created or deleted a layer or moved to a different layer, the layers status is updated.private void
changeSizeMenu()
After the user has selected the size button, the size status is updated with the user's input.void
changeToolMenu()
After the user has selected a tool button, the borders around the tool buttons are updated to show which button is now selected.void
createMenu()
createMenu() creates the physical appearance of the menu by first creating menuImage, a blank BufferedImage.int
getNumTool()
Returns the private numTool field that decides what tool is usedint
getStrokeSize()
Returns the current stroke size of the toolprivate void
makeBackgroundMenu()
This method paints the menu's background by filling a rectangle that is as wide as the application and as tall as the menu.private void
makeColorButton()
This method paints the color button as a border around a rectangle.private void
makeLayerButtons()
This method paints the new, previous, next, and delete layer buttons and the layer status bar.private void
makeSizeButton()
This method paints the size button with the current tool's size status on top.private void
makeToolButtons()
This method paints the pencil, elastic, and paint bucket buttons with their names on top.void
select(int x, int y)
Depending on what buttons the user clicks, certain methods are called to update either the color, tool, size, or layer.private void
selectColor()
When the user selects on the color button, only the RGB tab of the JColorChooser appears.private void
selectSize()
When the user selects the size button, a dialog box requests the user to input how many pixels wide they want their tools to be.
-
-
-
Field Detail
-
menuRect
java.awt.Rectangle menuRect
Menu buttons are not physically seen but are the "click-able" items.
-
colorRect
java.awt.Rectangle colorRect
Menu buttons are not physically seen but are the "click-able" items.
-
sizeRect
java.awt.Rectangle sizeRect
Menu buttons are not physically seen but are the "click-able" items.
-
pencilRect
java.awt.Rectangle pencilRect
Menu buttons are not physically seen but are the "click-able" items.
-
brushRect
java.awt.Rectangle brushRect
Menu buttons are not physically seen but are the "click-able" items.
-
sprayRect
java.awt.Rectangle sprayRect
Menu buttons are not physically seen but are the "click-able" items.
-
newRect
java.awt.Rectangle newRect
Menu buttons are not physically seen but are the "click-able" items.
-
prevRect
java.awt.Rectangle prevRect
Menu buttons are not physically seen but are the "click-able" items.
-
nextRect
java.awt.Rectangle nextRect
Menu buttons are not physically seen but are the "click-able" items.
-
delRect
java.awt.Rectangle delRect
Menu buttons are not physically seen but are the "click-able" items.
-
menuColor
java.awt.Color menuColor
These variables are used for the appearance of the menu.
-
paintColor
java.awt.Color paintColor
These variables are used for the appearance of the menu.
-
toolColor
java.awt.Color toolColor
These variables are used for the appearance of the menu.
-
sizeColor
java.awt.Color sizeColor
These variables are used for the appearance of the menu.
-
fontColor
java.awt.Color fontColor
These variables are used for the appearance of the menu.
-
layerBtnColor
java.awt.Color layerBtnColor
These variables are used for the appearance of the menu.
-
selectColor
java.awt.Color selectColor
These variables are used for the appearance of the menu.
-
btnFont
java.awt.Font btnFont
Font used for the title of the buttons.
-
numTool
private int numTool
These variables are passed on to the Tools methods to control how the user paints onto the canvas.
-
strokeSize
private int strokeSize
These variables are passed on to the Tools methods to control how the user paints onto the canvas.
-
stringStroke
java.lang.String stringStroke
This variable is used when getting the color from the dialog boxes of the JColorChooser.
-
menuImage
java.awt.image.BufferedImage menuImage
To prevent the menu bar from being erased when the window is no longer active, menuImage will store the current image.
-
g2Menu
java.awt.Graphics2D g2Menu
g2Menu will paint graphics onto the menuImage to update the menu when necessary.
-
paintLab
PaintApp paintLab
A PaintApp object has only one instance and allows this class to access its non-static methods and fields. I did not make PaintApp's fields static, because those fields refer to the one and same object, the paint program. I did not want to place the Menu's methods into PaintApp, because those methods belong in its own separate category. So, this Menu class must be able to access and change the graphical output of PaintApp such as as the get methods like getAppWidth().
-
layersArray
Layers layersArray
A Layers object that controls the creation and deletion of layers, and what happens when the user wants to move to a different layer.
-
-
Constructor Detail
-
Menu
public Menu(PaintApp pLab, Layers lArray)
When the Menu object is constructed, the invisible but "click-able" buttons are also constructed.- Parameters:
pLab
- The driver class, PaintApp, passes itself to the Menu() constructor to ensure that its Menu object has sufficient access to its methods and variables.lArray
- The Layers class passes itself to the Tools() constructor to ensure that its Tools object has sufficient access to its methods and variables.
-
-
Method Detail
-
createMenu
public void createMenu()
createMenu() creates the physical appearance of the menu by first creating menuImage, a blank BufferedImage. Next, other methods such as makeBackgroundMenu() are called to paint onto the menuImage.
-
makeBackgroundMenu
private void makeBackgroundMenu()
This method paints the menu's background by filling a rectangle that is as wide as the application and as tall as the menu.
-
makeColorButton
private void makeColorButton()
This method paints the color button as a border around a rectangle.
-
makeToolButtons
private void makeToolButtons()
This method paints the pencil, elastic, and paint bucket buttons with their names on top. A border is drawn around the first selected tool, the pencil, and draws an "invisible" border (same color as the menu) on the other tools.
-
makeSizeButton
private void makeSizeButton()
This method paints the size button with the current tool's size status on top.
-
makeLayerButtons
private void makeLayerButtons()
This method paints the new, previous, next, and delete layer buttons and the layer status bar.
-
select
public void select(int x, int y)
Depending on what buttons the user clicks, certain methods are called to update either the color, tool, size, or layer.- Parameters:
x
- The x-coordinate of where the user clickedy
- The y-coordinate of where the user clicked
-
selectColor
private void selectColor()
When the user selects on the color button, only the RGB tab of the JColorChooser appears. Since transparent lines are compounded on top of each other when draw in succession causing the transparent lines to appear opaque, I converted the RGBA values into RGB. Now, the color of the menu's color button matches the color drawn on the canvas.
-
selectSize
private void selectSize()
When the user selects the size button, a dialog box requests the user to input how many pixels wide they want their tools to be.
-
changeColorMenu
private void changeColorMenu()
After the user has selected their new color, the menu's color button is updated with the newly selected color.
-
changeToolMenu
public void changeToolMenu()
After the user has selected a tool button, the borders around the tool buttons are updated to show which button is now selected.
-
changeSizeMenu
private void changeSizeMenu()
After the user has selected the size button, the size status is updated with the user's input.
-
changeLayerMenu
public void changeLayerMenu()
When the user has created or deleted a layer or moved to a different layer, the layers status is updated.
-
getNumTool
public int getNumTool()
Returns the private numTool field that decides what tool is used- Returns:
- numTool
-
getStrokeSize
public int getStrokeSize()
Returns the current stroke size of the tool- Returns:
- strokeSize
-
-