Graphics

Method or Constructor Purpose
void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) Draws the outline of a circular or elliptical arc covering the specified rectangle.
void drawLine(int x1, int y1, int x2, int y2) Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics.
void drawOval(int x, int y, int width, int height) Draws the outline of an oval.
void drawString(String str, int x, int y) Draws the text given by the specified string, using this graphics context's current font and color.
void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) Fills a circular or elliptical arc covering the specified rectangle.
void fillOval(int x, int y, int width, int height) Fills an oval bounded by the specified rectangle with the current color.
void fillRect(int x, int y, int width, int height) Fills the specified rectangle.
Color getColor(), void setColor(Color) Gets and sets this graphics context's current color.
Font, getFont(),void setFont(Font font) Sets this graphics context's font to the specified font.

Color

Method or Constructor Purpose
Color(float r, float g, float b) , Color(int r, int g, int b) Specific the red, green, blue component.
Color brighter(), Color darker() Creates a new Color that is a brighter (or darker) version of this Color.

Font

Method or Constructor Purpose
Font(String name, int style, int size) Creates a new Font from the specified name, style and point size.
name - the font name. This can be a logical font name or a font face name.
style - the style constant for the Font The style argument is an integer bitmask that may be PLAIN, or a bitwise union of BOLD and/or ITALIC (for example, ITALIC or BOLD|ITALIC).
size - the point size of the Font.

Componenet

Color getForeground(), void setForeground(Color c), Color getBackground(), void setBackground(Color c) Gets and sets the background/foreground color of this component.
void setSize(int width, int height) Resizes this component so that it has width width and height.

Buttons

Setting or Getting the Button's Contents
Method or Constructor Purpose
JButton(String, Icon)
JButton(String)
JButton(Icon)
JButton()
Create a JButton instance, initializing it to have the specified text/image.
void setText(String)
String getText()
Set or get the text displayed by the button.
void setIcon(Icon)
Icon getIcon()
Set or get the image displayed by the button when the button isn't selected or pressed.
void setDisabledIcon(Icon)
Icon getDisabledIcon()
Set or get the image displayed by the button when it's disabled. If you don't specify a disabled image, then the look and feel creates one by manipulating the default image.
void setPressedIcon(Icon)
Icon getPressedIcon()
Set or get the image displayed by the button when it's being pressed.
void setSelectedIcon(Icon)
Icon getSelectedIcon()
void setDisabledSelectedIcon(Icon)
Icon getDisabledSelectedIcon()
Set or get the image displayed by the button when it's selected. If you don't specify a disabled selected image, then the look and feel creates one by manipulating the selected image.
setRolloverEnabled(boolean)
boolean getRolloverEnabled()
void setRolloverIcon(Icon)
Icon getRolloverIcon()
void setRolloverSelectedIcon(Icon)
Icon getRolloverSelectedIcon()
Use setRolloverEnabled(true) and setRolloverIcon(someIcon) to make the button display the specified icon when the cursor passes over it.

Fine Tuning the Button's Appearance
Method or Constructor Purpose
void setHorizontalAlignment(int)
void setVerticalAlignment(int)
int getHorizontalAlignment()
int getVerticalAlignment()
Set or get where in the button its contents should be placed. The AbstractButton class allows any one of the following values for horizontal alignment: LEFT, CENTER (the default), and RIGHT. For vertical alignment: TOP, CENTER (the default), and BOTTOM.
void setHorizontalTextPosition(int)
void setVerticalTextPosition(int)
int getHorizontalTextPosition()
int getVerticalTextPosition()
Set or get where the button's text should be placed, relative to the button's image. The AbstractButton class allows any one of the following values for horizontal position: LEFT, CENTER, and RIGHT (the default). For vertical position: TOP, CENTER (the default), and BOTTOM.

Implementing the Button's Functionality
Method or Constructor Purpose
void setActionCommand(String)
String getActionCommand(void)
Set or get the name of the action performed by the button.
void addActionListener(ActionListener)
ActionListener removeActionListener()
Add or remove an object that listens for action events fired by the button.
void setSelected(boolean)
boolean isSelected()
Set or get whether the button is selected. Makes sense only for buttons that have on/off state, such as check boxes.

Check Box Constructors
Constructor Purpose
JCheckBox(String)
JCheckBox(String, boolean)
JCheckBox(Icon)
JCheckBox(Icon, boolean)
JCheckBox(String, Icon)
JCheckBox(String, Icon, boolean)
JCheckBox()
Create a JCheckBox instance. The string argument specifies the text, if any, that the check box should display. Similarly, the Icon argument specifies the image that should be used instead of the look and feel's default check box image. Specifying the boolean argument as true initializes the check box to be selected. If the boolean argument is absent or false, then the check box is initially unselected.

Radio Button Constructors
Constructor Purpose
JRadioButton(String)
JRadioButton(String, boolean)
JRadioButton(Icon)
JRadioButton(Icon, boolean)
JRadioButton(String, Icon)
JRadioButton(String, Icon, boolean)
JRadioButton()
Creates a JRadioButton instance. The string argument specifies the text, if any, that the radio button should display. Similarly, the Icon argument specifies the image that should be used instead of the look and feel's default radio button image. Specifying the boolean argument as true initializes the radio button to be selected, subject to the approval of the ButtonGroup object. If the boolean argument is absent or false, then the radio button is initially unselected.

Commonly Used ButtonGroup Constructors/Methods
Constructor or Method Purpose
ButtonGroup() Creates a ButtonGroup instance.
void add(AbstractButton)
void remove(AbstractButton)
Adds a button to the group, or removes a button from the group.

JLabel

Setting or Getting the Label's Contents
Method or Constructor Purpose
JLabel(Icon)
JLabel(Icon, int)
JLabel(String)
JLabel(String, Icon, int)
JLabel(String, int)
JLabel()
Create a JLabel instance, initializing it to have the specified text/image/alignment. The int argument specifies the horizontal alignment of the label's contents within its drawing area. The horizontal alignment must be one of the following constants defined in the SwingConstants(in the API reference documentation) interface (which JLabel implements): LEFT, CENTER, RIGHT, LEADING, or TRAILING.
void setText(String)
String getText()
Set or get the text displayed by the label.
void setIcon(Icon)
Icon getIcon()
Set or get the image displayed by the label.

Fine Tuning the Label's Appearance
Method Purpose
void setHorizontalAlignment(int)
void setVerticalAlignment(int)
int getHorizontalAlignment()
int getVerticalAlignment()
Set or get where in the label its contents should be placed. The SwingConstants(in the API reference documentation) interface defines five possible values for horizontal alignment: LEFT (the default for text-only labels), CENTER (the default for image-only labels), RIGHT, LEADING, and TRAILING. For vertical alignment: TOP, CENTER (the default), and BOTTOM.
void setHorizontalTextPosition(int)
void setVerticalTextPosition(int)
int getHorizontalTextPosition()
int getVerticalTextPosition()
Set or get where the button's text should be placed, relative to the button's image. The SwingConstants(in the API reference documentation) interface defines three possible values for horizontal position: LEFT, CENTER, and RIGHT (the default). For vertical position: TOP, CENTER (the default), and BOTTOM.

JPanel

Creating a JPanel
Constructor Purpose
JPanel()
JPanel(LayoutManager)
Create a panel. The LayoutManager parameter provides a layout manager for the new panel. By default, a panel uses a FlowLayout to lay out its components.

Managing a Container's Components
Method Purpose
void add(Component)
void add(Component, int)
void add(Component, Object)
void add(Component, Object, int)
void add(String, Component)
Add the specified component to the panel. When present, the int parameter is the index of the component within the container. By default, the first component added is at index 0, the second is at index 1, and so on. The Object parameter is layout manager dependent and typically provides information to the layout manager regarding positioning and other layout constraints for the added component. The String parameter is similar to the Object parameter.
int getComponentCount() Get the number of components in this panel.
Component getComponent(int)
Component getComponentAt(int, int)
Component getComponentAt(Point)
Component[] getComponents()
Get the specified component or components. You can get a component based on its index or x, y position.
void remove(Component)
void remove(int)
void removeAll()
Remove the specified component(s).

Setting/Getting the Layout Manager
Method Purpose
void setLayout(LayoutManager)
LayoutManager getLayout()
Set or get the layout manager for this panel. The layout manager is responsible for positioning the panel's components within the panel's bounds according to some philosophy.

JTextField and JPasswordField

Setting or Getting the Field's Contents
Method or Constructor Purpose
JTextField()
JTextField(String)
JTextField(String, int)
JTextField(int)
Create a text field. When present, the int argument specifies the desired width in columns. The String argument contains the field's initial text.
JPasswordField()
JPasswordField(String)
JPasswordField(String, int)
JPasswordField(int)
Create a password field. When present, the int argument specifies the desired width in columns. The String argument contains the field's initial text.
void setText(String)
String getText()
Set or get the text displayed by the text field. Note that getText does not work for password fields.
char[] getPassword()
(in JPasswordField)
Set or get the text displayed by the text field.

Fine Tuning the Field's Appearance
Method or Constructor Purpose
void setEditable(boolean)
boolean isEditable()
Set or get whether the user can edit the text in the text field.
void setColumns(int);
int getColumns()
Set or get the number of columns displayed by the text field. This is really just a hint for computing the field's preferred width.
Font getFont();
void setFont(Font)
Set or get font displayed by the text area.
void setHorizontalAlignment(int);
int getHorizontalAlignment()
Set or get how the text is aligned horizontally within its area. You can use JTextField.LEFT, JTextField.CENTER, and JTextField.RIGHT for arguments.
void setEchoChar(char)
char getEchoChar()

(in JPasswordField)
Set or get the echo character -- the character displayed instead of the actual characters typed by the user.

Implementing the Field's Functionality
Method or Constructor Purpose
void addActionListener(ActionListener)
void removeActionListener(ActionListener)
Add or remove an action listener.

JTextArea

Setting or Getting the JTextArea's Contents
Method or Constructor Purpose
JTextArea()
JTextArea(String)
JTextArea(int rows, int columns)
JTextArea(String text, int rows, int columns)
Create a text are. The String argument contains the field's initial text. rows,columns are the number of rows and columns
void setText(String)
String getText()
Set or get the text displayed by the text area.

Fine Tuning the Field's Appearance
Method or Constructor Purpose
boolean getLineWrap(),
void setLineWrap(boolean)
Gets or sets the line-wrapping policy of the text area. If set to true the lines will be wrapped if they are too long to fit within the allocated width. If set to false, the lines will always be unwrapped. By default this property is false.
void setWrapStyleWord(boolean),
boolean getWrapStyleWord()
Set the style of wrapping used if the text area is wrapping lines. If set to true the lines will be wrapped at word boundaries (whitespace) if they are too long to fit within the allocated width. If set to false, the lines will be wrapped at character boundaries. By default this property is false.
void setEditable(boolean)
boolean isEditable()
Set or get whether the user can edit the text in the text field.
void setColumns(int);
int getColumns()
int getRows()
setRows(int rows)
Set or get the number of columns, rows displayed by the text area.
Font getFont();
void setFont(Font)
Set or get font displayed by the text area.


FlowLayout

Method or Constructor Purpose
public FlowLayout(), public FlowLayout(int alignment), public FlowLayout(int alignment, int horizontalGap, int verticalGap) The alignment argument must have the value FlowLayout.LEFT, FlowLayout.CENTER, or FlowLayout.RIGHT. The horizontalGap and verticalGap arguments specify the number of pixels to put between components. If you don't specify a gap value, FlowLayout uses 5 for the default gap value.

BorderLayout

Method or Constructor Purpose
BorderLayout(), BorderLayout(int horizontalGap, int verticalGap) Constructs a border layout with the specified gaps between components. The default is 0.

GridLayout

Method or Constructor Purpose
public GridLayout(int rows, int columns) public GridLayout(int rows, int columns, int horizontalGap, int verticalGap) At least one of the rows and columns arguments must be nonzero. The horizontalGap and verticalGap arguments to the second constructor allow you to specify the number of pixels between cells. If you don't specify gaps, their values default to zero.

ActionEvent

Method or Constructor Purpose
Object getSource() The object on which the Event initially occurred.
String getActionCommand() Returns the command string associated with this action.

MouseEvent

Method or Constructor Purpose
Object getSource() The object on which the Event initially occurred.
Component getComponent() Returns the command string associated with this action.
int getX(),int getY(), Point getPoint() Returns the x,y position of the event relative to the source component.
int getClickCount() Return the number of mouse clicks associated with this event.

Thread

Methods/Constructors Description
Thread(),Thread(Runnable target), Thread(Runnable target, String name),Thread(String name) name is the name of the thread. Runnable is an interface with run method.
static int MAX_PRIORITY , static int MIN_PRIORITY , static int NORM_PRIORITY The maximum/minimun/default priority that a thread can have.
void destroy() Destroys this thread, without any cleanup.
String getName() Returns this thread's name.
int getPriority() Returns this thread's priority.
void run() If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
void setPriority(int newPriority) Changes the priority of this thread.
static void sleep(long millis) throws InterruptedException Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
void start() Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.

Double

We will take class Double as an example.
It extends Number class which has the following methods
Member Description
byte byteValue(), short shortValue(), int intValue(), long longValue(), float floatValue(), double doubleValue() Convert the value of this number object to the primitive date types of byte, short, int, long, float and double

Other useful methods

Constructors or members Description
static double MAX_VALUE,
static double MIN_VALUE
max/min value
static double NaN Not a number
static double NEGATIVE_INFINITY,
static double POSITIVE_INFINITY
.
public Double(double value),
public Double(String s) throws NumberFormatException
meaning is clear
String toString(),
static String toString(double d)
Returns a String representation.
static double parseDouble(String s) throws NumberFormatException,
static Double valueOf(String s) throws NumberFormatException
Returns a new double(or Double) initialized to the value represented by the specified String.
boolean equals(Object) determine if the object is equal to the Double
int compareTo(Double anotherDouble) Compares two Doubles numerically. The value is bigger then 0 if the Double is bigger than anotherDouble etc.

Vector and LinkedList

Methods from the interface List

Methods Description
void add(int index, Object element) Inserts the specified element at the specified position in this list.
boolean add(Object o) Appends the specified element to the end of this list
void clear() Removes all of the elements from this list.
boolean contains(Object o) Returns true if this list contains the specified element.
Object get(int index) Returns the element at the specified position in this list.
int indexOf(Object o) Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.
boolean isEmpty() Returns true if this list contains no elements.
int lastIndexOf(Object o) Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.
Object remove(int index) Removes the element at the specified position in this list.
boolean remove(Object o) Removes the first occurrence in this list of the specified element .
Object set(int index, Object element) Replaces the element at the specified position in this list with the specified element.
int size() Returns the number of elements in this list.
Object[] toArray() Returns an array containing all of the elements in this list in proper sequence.

More methods for Vector classes

Constructor/Methods Description
Vector(),Vector(int initialCapacity) Constructs an empty vector with the specified initial capacity, the default is 10.
Object firstElement() Returns the first component (the item at index 0) of this vector.
Object lastElement() Returns the last component of the vector.

More methods for LinkedList classes

Methods Description
LinkedList() Constructs an empty list.
void addFirst(Object o) Inserts the given element at the beginning of this list.
void addLast(Object o) Appends the given element to the end of this list.
Object getFirst() Returns the first element in this list.
Object getLast() Returns the last element in this list.
Object removeFirst() Removes and returns the first element from this list.
Object removeLast() Removes and returns the last element from this list.