public class Canvas
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_HEIGHT |
static int |
DEFAULT_WIDTH |
Constructor and Description |
---|
Canvas()
Constructs and shows a canvas with size 800 x 600.
|
Canvas(boolean isVisible)
Constructs a canvas with size 800 x 600 with an option to set it visible
or not.
|
Canvas(int width,
int height)
Constructs and shows a canvas with specific width and height.
|
Canvas(int width,
int height,
boolean isVisible)
Constructs and shows a canvas with specific width and height.
|
Modifier and Type | Method and Description |
---|---|
void |
add(CanvasObject canvasObject)
Adds a CanvasObject instance to the canvas.
|
void |
add(CanvasObject canvasObject,
int x,
int y)
Adds a CanvasObject instance to the canvas at position (x, y).
|
void |
addMouseListener(java.awt.event.MouseListener listener)
Registers a java.awt.event.MouseListener instance to the canvas.
|
void |
addMouseMotionListener(java.awt.event.MouseMotionListener listener)
Registers a java.awt.event.MouseMotionListener instance to the canvas.
|
int |
getCanvasHeight()
Returns the height of the canvas.
|
int |
getCanvasWidth()
Returns the width of the canvas.
|
javax.swing.JFrame |
getJFrame()
Gets the JFrame of the Canvas.
|
javax.swing.JPanel |
getJPanel()
Gets the JPanel of the canvas.
|
void |
remove(CanvasObject canvasObject)
Removes a specific CanvasObject instance that is added to the canvas.
|
void |
removeAll()
Removes all CanvasObject instances on the canvas.
|
void |
repaint()
Calls the repaint method of the inner panel.
|
void |
saveCanvasImage()
Save a snapshot of the canvas to an image with save file dialog.
|
void |
saveCanvasImage(java.lang.String filename)
Save a snapshot of the canvas to an image with filename specified.
|
void |
setComponentAtBottom(javax.swing.JComponent component)
Adds a JComponent at the bottom of the canvas.
|
void |
setComponentAtTop(javax.swing.JComponent component)
Adds a JComponent at the top of the canvas.
|
void |
setResizable(boolean isResizable)
Sets if the canvas is resizable.
|
void |
setVisible(boolean isVisible)
Sets if the canvas is visible.
|
public static final int DEFAULT_WIDTH
public static final int DEFAULT_HEIGHT
public Canvas()
public Canvas(boolean isVisible)
isVisible
- Whether the canvas is visible or not.public Canvas(int width, int height)
width
- The width of the canvas to be constructed.height
- The height of the canvas to be constructed.public Canvas(int width, int height, boolean isVisible)
width
- The width of the canvas to be constructed.height
- The height of the canvas to be constructed.isVisible
- Set if the canvas is visible by default.public int getCanvasWidth()
public int getCanvasHeight()
public void setResizable(boolean isResizable)
isResizable
- Flag indicating whether the canvas is resizable.public void setVisible(boolean isVisible)
isVisible
- Flag indicating whether the canvas is visible.public void add(CanvasObject canvasObject)
canvasObject
- The CanvasObject instance to be added (e.g. barcode, colorimage, text)public void add(CanvasObject canvasObject, int x, int y)
canvasObject
- The CanvasObject instance to be added (e.g. barcode, colorimage,
text).x
- The x position on the canvas for adding the CanvasObject instance.y
- The y position on the canvas for adding the CanvasObject instance.public void setComponentAtTop(javax.swing.JComponent component)
component
- The JComponent to be added.public void setComponentAtBottom(javax.swing.JComponent component)
component
- The JComponent to be added.public void removeAll()
public void remove(CanvasObject canvasObject)
canvasObject
- The CanvasObject instance to be removed from the canvas.public void addMouseMotionListener(java.awt.event.MouseMotionListener listener)
listener
- the MouseMotionListener instance to be registered.public void addMouseListener(java.awt.event.MouseListener listener)
listener
- the MouseListener instance to be registered.public javax.swing.JPanel getJPanel()
public javax.swing.JFrame getJFrame()
public void repaint()
public void saveCanvasImage()
public void saveCanvasImage(java.lang.String filename)