Professional Documents
Culture Documents
V-Unit (Stream & Swing)
V-Unit (Stream & Swing)
protected void finalize() It is used to clean up the connection with the file output stream.
void write(byte[] ary) It is used to write ary.length bytes from the byte array to the file
output stream.
void write(byte[] ary, int off, int len) It is used to write len bytes from the byte array starting at
offset off to the file output stream.
void write(int b) It is used to write the specified byte to the file output stream.
FileChannel getChannel() It is used to return the file channel object associated with the file
output stream.
FileDescriptor getFD() It is used to return the file descriptor associated with the stream.
1.Java JButton:
JButton class is used to create a labeled button that has platform
independent implementation. The application result in some action when the
button is pushed. It inherits AbstractButton class.
Commonly used Constructors:
JButton(): It creates a button with no text and icon.
JButton(String s): It creates a button with the specified text.
Methods of AbstractButton class:
void setText(String s): It is used to set specified text on button
String getText(): It is used to return the text of the button.
void setEnabled(boolean b): It is used to enable or disable the button.
setBounds(int x-coordinate, int y-coordinate, int width, int height):
2. JLabel
The object of JLabel class is a component for placing text in a container. It is used to
display a single line of read only text.
It is under package javax.swing.JLabel class. It is used for placing text in a box. Only
Single line text is allowed and the text can not be changed directly.
The class JLabel can display either text, an image, or both.
Declaration
public class JLabel extends JComponent implements SwingConstants, Accessible
Methods Description
String getText() t returns the text string that a label
displays.
void setText(String text) It defines the single line of text this
component will display.
void setHorizontalAlignment(int alignment) It sets the alignment of the label's
contents along the X axis.
Icon getIcon() It returns the graphic image that the label
displays.
int getHorizontalAlignment() It returns the alignment of the label's
contents along the X axis.
3.Java JTextField
The object of a JTextField class is a text component that allows the editing of a
single line text. It inherits JTextComponent class.
JTextField is used for taking input of single line of text. It is most widely used text
component.
Constructors:
JTextField(int cols):
JTextField(String str, int cols):
JTextField(String str):
JTextField():
Methods:
void addActionListener(ActionListener l): It is used to add the specified action
listener to receive action events from this textfield.
Action getAction(): It returns the currently set Action for this ActionEvent
source, or null if no Action is set.
void setFont(Font f): It is used to set the current font.
void removeActionListener(ActionListener l): It is used to remove the
specified action listener so that it no longer receives action events from this
textfield.
4.JCheckBox
The JcheckBox class is used to create chekbox in swing framework.
The JCheckBox class is used to create a checkbox. It is used to turn an
option on (true) or off (false).
Constructors:
JCheckBox(): Creates an initially unselected check box button with
no text, no icon.
JChechBox(String s): Creates an initially unselected check box with
text.
JCheckBox(String text, boolean selected): Creates a check box with
text and specifies whether or not it is initially selected.
JCheckBox(Action a): Creates a check box where properties are
taken from the Action supplied.
5.Java JComboBox
JComboBox is a part of Java Swing package. JComboBox inherits
JComponent class .
JComboBox shows a popup menu that shows a list and the user can
select a option from that specified list .
Combo box is a combination of text fields and drop-down list.
Constructor of the JComboBox:
1. JComboBox() : creates a new empty JComboBox .
2. JComboBox(ComboBoxModel M) : creates a new JComboBox with
items from specified ComboBoxModel
3. JComboBox(E [ ] i) : creates a new JComboBox with items from
specified array.
4. JComboBox(Vector items) : creates a new JComboBox with items
from the specified vector.
Methods of JComboBox:
1. addItem(E item) : adds the item to the JComboBox
2. void removeItem(Object anObject): It is used to delete an item to
the item list.
3. void removeAllItems(): It is used to remove all the items from the
list.
4. void addActionListener(ActionListener a): It is used to add the
ActionListener.
5. addItemListener( ItemListener l) : adds a ItemListener to JComboBox
6. getItemAt(int i) : returns the item at index i
7. getItemCount(): returns the number of items from the list
8. getSelectedItem() : returns the item which is selected.
9. removeItemAt(int i) : removes the element at index i
10. removeActionListener(ActionListener l): removes an ActionListener.
6.JRadioButton
Radio button is a group of related button in which only one can be selected. JRadioButton class is
used to create a radio button in Frames.
The JRadioButton class is used to create a radio button. It is used to choose one option from
multiple options. It is widely used in exam systems or quiz.
It should be added in ButtonGroup to select one radio button only.
Constructors:
1. JRadioButton(): Creates an unselected radio button with no text.
2. JRadioButton(String s): Creates an unselected radio button with specified text.
3. JRadioButton(String s, boolean selected): Creates a radio button with the specified text and
selected status.
Methods:
1. void setText(String s): It is used to set specified text on button.
2. String getText(): It is used to return the text of the button.
3. void setEnabled(boolean b): It is used to enable or disable the button.
4. void setIcon(Icon b): It is used to set the specified Icon on the button.
5. void addActionListener(ActionListener a): It is used to add the action listener to this object.
7. JList
The object of JList class represents a list of text items. The list of text
items can be set up so that the user can choose either one item or
multiple items.
JList is part of Java Swing package . JList is a component that displays
a set of Objects and allows the user to select one or more items .
JList inherits JComponent class.
Constructor for JList are :