CustomFrame is a Java Swing class extending JFrame, providing additional functionalities and customization for creating GUI windows. It allows for easy customization of window size, title, and background image.
// Default size and title and resizable
CustomFrame frame = new CustomFrame("My Frame", true);
// Custom size and title and resizable
CustomFrame customSizeFrame = new CustomFrame(1.5, 1, 1.5, 1, "Custom Size Frame", true);
// Custom size based on the golden ratio and resizable
CustomFrame goldenRatioFrame = new CustomFrame(CustomFrame.PHI_HEIGHT, 1, 1, "Golden Ratio Frame", true);CustomFrame frameWithBackground = new CustomFrame("Frame with Background", true);
frameWithBackground.setBackgroundImage(frameWithBackground.loadImage("background.jpg"));// Get scaled dimension
Dimension scaledDimension = frame.getScaledDimension(2, 2);
// Get scaled dimension with custom multipliers and scales
Dimension customScaledDimension = frame.getScaledDimension(1.5, 2, 1.5, 2);CustomFrame(String title, boolean resizable)Constructs a CustomFrame with default size and title.
CustomFrame(double widthMultiplier, double widthScale,
double heightMultiplier, double heightScale, String title, boolean resizable)Constructs a CustomFrame with a custom size and title.
CustomFrame(int phi, double multiplier, double scale, String title, boolean resizable)Constructs a CustomFrame with a custom size based on the golden ratio.
getScaledDimension(double widthScale, double heightScale)Calculates the scaled dimension based on width and height scales.
- Params:
widthScale: Scale factor for width.heightScale: Scale factor for height.
- Returns:
Dimension
getScaledDimension(double widthMultiplier, double widthScale, double heightMultiplier, double heightScale)Calculates the scaled dimension based on width and height multipliers and scales.
- Params:
widthMultiplier: Multiplier for the original width.widthScale: Scale factor for width.heightMultiplier: Multiplier for the original height.heightScale: Scale factor for height.
- Returns:
Dimension
setBackgroundImage(String path)Sets the background image of the frame.
- Params:
path: Path to the background image file.
setBackgroundImage(Image image)Sets the background image of the frame.
- Params:
image: Image to set as the background.
loadImage(String filename)Returns the loaded image.
- Params:
filename: Name of the image file.
- Returns:
Image
loadImage(String filename, String path)Returns the loaded image.
- Params:
filename: Name of the image file.path: Path to the image file.
- Returns:
Image
scaleImageIcon(ImageIcon imageIcon, int width, int height)Scales an image.
- Params:
imageIcon: The ImageIcon to scale.width: The desired width of the scaled icon.height: The desired height of the scaled icon.
- Returns: The scaled ImageIcon.
scaleImageIcon(ImageIcon imageIcon, double scaleWidth, double scaleHeight)Scales an image.
- Params:
imageIcon: The ImageIcon to scale.scaleWidth: The scale width of the scaled icon (original width * scaleWidth).scaleHeight: The scale height of the scaled icon (original height * scaleHeight).
- Returns: The scaled ImageIcon.
scaleImage(Image img, int width, int height)Scales an image.
- Params:
img: The Image to scale.width: The desired width of the scaled icon.height: The desired height of the scaled icon.
- Returns: The scaled Image.
scaleImage(Image img, double scaleWidth, double scaleHeight)Scales an image.
- Params:
img: The Image to scale.scaleWidth: The scale width of the scaled icon (original width * scaleWidth).scaleHeight: The scale height of the scaled icon (original height * scaleHeight).
- Returns: The scaled Image.
getImageIconWidth(ImageIcon imageIcon)Retrieves the width of an image represented by the provided ImageIcon object.
- Params:
imageIcon: The ImageIcon containing the image to query.
- Returns: The width of the image in pixels.
getImageIconHeight(ImageIcon imageIcon)Retrieves the height of an image represented by the provided ImageIcon object.
- Params:
imageIcon: The ImageIcon containing the image to query.
- Returns: The height of the image in pixels.
getImageIconDimension(ImageIcon imageIcon)Retrieves the dimensions of an image represented by the provided ImageIcon object as a Dimension object.
- Params:
imageIcon: The ImageIcon containing the image to query.
- Returns: A Dimension object containing the width and height of the image.
getImageWidth(Image image)Retrieves the width of an image represented by the provided Image object.
- Params:
image: The Image containing the image to query.
- Returns: The width of the image in pixels.
getImageHeight(Image image)Retrieves the height of an image represented by the provided Image object.
- Params:
image: The Image containing the image to query.
- Returns: The height of the image in pixels.
getImageDimension(Image image)Retrieves the dimensions of an image represented by the provided Image object as a Dimension object.
- Params:
image: The ImageIcon containing the image to query.
- Returns: A Dimension object containing the width and height of the image.
This project is licensed under the MIT License - see the LICENSE file for details.