String

Methods for changing strings

String concat(String str)
String replace(char oldChar, char newChar)
String toLowerCase()
String toUpperCase()
String trim()

Methods for searching

int indexOf(int ch)
int indexOf(int ch, int fromIndex)
int lastIndexOf(int ch)
int lastIndexOf(int ch, int fromIndex)
int indexOf(String str)
int indexOf(String str, int fromIndex)
int lastIndexOf(String str)
int lastIndexOf(String str,int fromIndex)




Methods for testing

boolean startsWith(String prefix, int toffset)
boolean startsWith(String prefix)
boolean endsWith(String suffix)
boolean equalsIgnoreCase(String anotherString)

Methods for accessing

String substring(int beginIndex)
String substring(int beginIndex, int endIndex)
char charAt(int index)
public char[] toCharArray()

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.


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.

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.

PIC20B -- Midterm Table

File

Constructors
Constructors/Methods Description
File(String pathname),
File(String parent, String filename),
File(File directory, String filename)
Creates a new File instance by converting the given pathname string into an abstract pathname. Or creates a new File instance from a parent pathname string (or directory) and a child pathname string.

Test methods
Constructors/Methods Description
exists() Tests whether the file denoted by this abstract pathname exists.
isFile() Tests whether the file denoted by this abstract pathname is a normal file. Returns true if and only if the file denoted by this abstract pathname exists and is a normal file; false otherwise.
isDirectory() Tests whether the file denoted by this abstract pathname is a directory. Returns true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise.

Action Methods
Constructors/Methods Description
boolean mkdir() Creates the directory named by this abstract pathname. Returns true if and only if the directory was created; false otherwise.
boolean mkdirs() Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Returns true if and only if the directory was created, along with all necessary parent directories; false otherwise
boolean delete() Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a directory, then the directory must be empty in order to be deleted. Returns true if and only if the file or directory is successfully deleted; false otherwise
boolean renameTo(File dest) Renames the file denoted by this abstract pathname. Returns true if and only if the renaming succeeded; false otherwise

List Methods
Constructors/Methods Description
String[] list() Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname. If this abstract pathname does not denote a directory, then this method returns null. Otherwise an array of strings is returned, one for each file or directory in the directory.
File[] listFiles() Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname. If this abstract pathname does not denote a directory, then this method returns null. Otherwise an array of File objects is returned, one for each file or directory in the directory.

Other methods
Constructors/Methods Description
long lastModified() Returns the time that the file denoted by this abstract pathname was last modified.
long length() Returns the length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist

IO

FileInputStream

Constructors/Methods Description
FileInputStream(String name) throws FileNotFoundException
FileInputStream(File file) throws FileNotFoundException
Creates a FileInputStream by opening a connection to an actual file.
If the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a FileNotFoundException is thrown.
int read() throws IOException Read and return the next byte of data, or -1 if the end of the file is reached.
int read(byte[] b) throws IOException
int read(byte[] b, int off, int len) throws IOException
Reads up to b.length/len bytes of data from this input stream into an array of bytes.
It returns the total number of bytes read into the buffer, or -1 if there is no more data because the end of the file has been reached.
int available() throws IOException Returns the number of bytes that can be read from this file input stream without blocking
long skip(long n) throws IOException Skips over and discards n bytes of data from the input stream.
void close() throws IOException Closes this file input stream and releases any system resources associated with the stream.

FileOutputStream

Constructors/Methods Description
FileOutputStream(File file) throws FileNotFoundException
FileOutputStream(String name) throws FileNotFoundException
FileOutputStream(String name, boolean append) throws FileNotFoundException
Creates an output file stream to write to the file with the specified file or name.
If append is true, then bytes will be written to the end of the file rather than the beginning.
If the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason then a FileNotFoundException is thrown.
void write(int b)throws IOException
void write(byte[] b) throws IOException
void write(byte[] b, int off, int len) throws IOException
Writes the specified byte(s) to this file output stream.
void close() throws IOException Closes this file output stream and releases any system resources associated with this stream. This file output stream may no longer be used for writing bytes.

BufferedInputStream

Constructors/Methods Description
BufferedInputStream(InputStream in),
BufferedInputStream(InputStream in, int size)
Creates a BufferedInputStream with the specified buffer size, and saves its argument, the input stream in, for later use. An internal buffer array of length size is created and stored in buf.
int available(), void close() , int read(), int read(byte[] b, int off, int len), long skip(long n)
All throws IOException
Meanings of the methods are clear.


BufferedOutputStream

Constructors/Methods Description
BufferedOutputStream(OutputStream out), BufferedOutputStream(OutputStream out, int size). Creates a new buffered output stream to write data to the specified underlying output stream with the specified buffer size. The default is 512.
void write(int b), void write(byte[] b, int off, int len)
all throws IOException
void flush() Flushes this buffered output stream. This forces any buffered output bytes to be written out to the underlying output stream.

PrintStream

PrintStream API
Constructors/Methods Description
PrintStream(OutputStream out),
PrintStream(OutputStream out, boolean autoFlush)
out - The output stream to which values and objects will be printed
autoFlush - A boolean; if true, the output buffer will be flushed whenever a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written.
void print(boolean b), void print(char c), void print(char[] s), void print(double d), void print(float f), void print(int i), void print(long l), void print(Object obj), void print(String s)
void println(boolean b), void println(char c), void println(char[] s), void println(double d), void println(float f), void println(int i), void println(long l), void println(Object obj), void println(String s),
The meanings are clear.
void close() ,void flush(),void write(int b) , void write(byte[] buf, int off, int len) Same as in FileOutputStream.
boolean checkError(),void setError() Flush the stream and check its error state. The internal error state is set to true when the underlying output stream throws an IOException other than InterruptedIOException.