com.javaranch.common
Class GUI

java.lang.Object
  |
  +--com.javaranch.common.AWT
        |
        +--com.javaranch.common.GUI

public class GUI
extends AWT

Contains a collection of static methods related to GUI's (AWT and Swing stuff).

- - - - - - - - - - - - - - - - -

Copyright (c) 1998-2004 Paul Wheaton

You are welcome to do whatever you want to with this source file provided that you maintain this comment fragment (between the dashed lines). Modify it, change the package name, change the class name ... personal or business use ... sell it, share it ... add a copyright for the portions you add ...

My goal in giving this away and maintaining the copyright is to hopefully direct developers back to JavaRanch.

The original source can be found at JavaRanch

- - - - - - - - - - - - - - - - -

Author:
Paul Wheaton, Nathan Paris

Field Summary
 
Fields inherited from class com.javaranch.common.AWT
center, right, rightPad
 
Method Summary
static javax.swing.JMenuItem addMenuItem(javax.swing.JComponent m, javax.swing.JMenuItem mi, java.awt.event.ActionListener listener)
          A convenience function that adds an ActionListener to a JMenuItem and adds the item to a JMenu.
static javax.swing.JMenuItem addMenuItem(javax.swing.JComponent m, java.lang.String desc)
          A convenience method that makes a JMenuItem out of some text and adds that to a JMenu.
static javax.swing.JMenuItem addMenuItem(javax.swing.JComponent m, java.lang.String desc, java.awt.event.ActionListener listener)
          A convenience method that makes a JMenuItem out of some text, adds an ActionListener and adds the result to a JMenu.
static void blur(java.awt.image.BufferedImage i)
           
static javax.swing.JButton button(java.lang.String text, int x, int y, java.awt.Font font, java.awt.FontMetrics metrics)
           
static javax.swing.JButton button(java.lang.String text, int x, int y, int width, int height)
           
static javax.swing.JCheckBox checkBox(int x, int y, int width, int height)
           
static java.awt.image.BufferedImage createBeveledImage(int width, int height, java.awt.Color color, java.awt.Color topColor, java.awt.Color rightColor, java.awt.Color bottomColor, java.awt.Color leftColor, int borderThickness)
          Create an image that looks like a beveled rectangle.
static java.awt.image.BufferedImage createBeveledImage(int width, int height, java.awt.Color color, int borderThickness)
           
static java.awt.Color darken(java.awt.Color c, double factor)
           
static void errorDialog(java.awt.Frame f, java.lang.String message)
           
static javax.swing.JLabel label(java.lang.String text, int x, int y, java.awt.Font font, java.awt.FontMetrics metrics)
          Creates a label with the correct size for the provided FontMetric.
static javax.swing.JLabel label(java.lang.String text, int x, int y, int width, int height)
           
static java.awt.Color lighten(java.awt.Color c, double factor)
           
static void messageDialog(java.awt.Frame f, java.lang.String message)
           
static java.awt.Image softBeveledImage(int width, int height, java.awt.Color color, int borderThickness)
           
static javax.swing.JTextField textField(int columns, int x, int y, int width, int height)
           
static void warningDialog(java.awt.Frame f, java.lang.String message)
           
 
Methods inherited from class com.javaranch.common.AWT
ascent, blank, center, drawBeveledRect, drawBeveledRect, drawBeveledRect, FontHeight, gbc, gbc, getFrame, getSize, shrink, tellUser
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createBeveledImage

public static java.awt.image.BufferedImage createBeveledImage(int width,
                                                              int height,
                                                              java.awt.Color color,
                                                              java.awt.Color topColor,
                                                              java.awt.Color rightColor,
                                                              java.awt.Color bottomColor,
                                                              java.awt.Color leftColor,
                                                              int borderThickness)
Create an image that looks like a beveled rectangle.

Good for making panels and buttons.

Parameters:
width - The width of the image.

height - The height of the image.

color - The color of all that stuff in the middle of the image.

topColor - The color to be used on the top edge.

rightColor - The color to be used on the right edge.

bottomColor - The color to be used on the bottom edge.

leftColor - The color to be used on the left edge.

borderThickness - How many lines thick should this beveled rectangle be?

Returns:
The rectangle that fits perfectly within the beveled rectangle.


darken

public static java.awt.Color darken(java.awt.Color c,
                                    double factor)

lighten

public static java.awt.Color lighten(java.awt.Color c,
                                     double factor)

createBeveledImage

public static java.awt.image.BufferedImage createBeveledImage(int width,
                                                              int height,
                                                              java.awt.Color color,
                                                              int borderThickness)

softBeveledImage

public static java.awt.Image softBeveledImage(int width,
                                              int height,
                                              java.awt.Color color,
                                              int borderThickness)

blur

public static void blur(java.awt.image.BufferedImage i)

addMenuItem

public static javax.swing.JMenuItem addMenuItem(javax.swing.JComponent m,
                                                java.lang.String desc)
A convenience method that makes a JMenuItem out of some text and adds that to a JMenu.

Parameters:
m - A JMenu object to add the new JMenuItem to.

desc - The text of the new menu item.

Returns:
The newly created JMenuItem.


addMenuItem

public static javax.swing.JMenuItem addMenuItem(javax.swing.JComponent m,
                                                java.lang.String desc,
                                                java.awt.event.ActionListener listener)
A convenience method that makes a JMenuItem out of some text, adds an ActionListener and adds the result to a JMenu.

Parameters:
m - A JMenu object to add the new JMenuItem to.

desc - The text of the new menu item.

listener - The action listener that will want to be notified when this item is selected.

Returns:
The newly created JMenuItem.


addMenuItem

public static javax.swing.JMenuItem addMenuItem(javax.swing.JComponent m,
                                                javax.swing.JMenuItem mi,
                                                java.awt.event.ActionListener listener)
A convenience function that adds an ActionListener to a JMenuItem and adds the item to a JMenu.

Parameters:
m - A JMenu object to add the JMenuItem to.

mi - The JMenuItem.

listener - The action listener that will want to be notified when this item is selected.

Returns:
The newly created JMenuItem.


label

public static javax.swing.JLabel label(java.lang.String text,
                                       int x,
                                       int y,
                                       int width,
                                       int height)

label

public static javax.swing.JLabel label(java.lang.String text,
                                       int x,
                                       int y,
                                       java.awt.Font font,
                                       java.awt.FontMetrics metrics)
Creates a label with the correct size for the provided FontMetric.


textField

public static javax.swing.JTextField textField(int columns,
                                               int x,
                                               int y,
                                               int width,
                                               int height)

button

public static javax.swing.JButton button(java.lang.String text,
                                         int x,
                                         int y,
                                         int width,
                                         int height)

button

public static javax.swing.JButton button(java.lang.String text,
                                         int x,
                                         int y,
                                         java.awt.Font font,
                                         java.awt.FontMetrics metrics)

checkBox

public static javax.swing.JCheckBox checkBox(int x,
                                             int y,
                                             int width,
                                             int height)

messageDialog

public static void messageDialog(java.awt.Frame f,
                                 java.lang.String message)

warningDialog

public static void warningDialog(java.awt.Frame f,
                                 java.lang.String message)

errorDialog

public static void errorDialog(java.awt.Frame f,
                               java.lang.String message)


Copyright ©2004 Paul Wheaton All Rights Reserved