It is used to provide standard dialog boxes such as message dialog box, confirm dialog box, and input dialog box.
Dialog Boxes
Used to display information or get input from the user.
The JOptionPane class inherits JComponent class.
The JOptionPane class inherits JComponent class.
ShowConfirmDialog
Asks a confirming question, like yes/no/cancel.
ShowInputDialog
Prompt for some input.
ShowMessageDialog
Tell the user about something that has happened.
ShowOptionDialog
Allows you to display buttons containing the text of your choice.
import javax.swing.JOptionPane;
What is the import statement?
Component
The graphical widgets inside a frame, such as buttons or text input fields, are collectively called components.
JComponent Class
Provides the following functionality to its descendants.
Abstract Button
An abstract base class of button and menu objects.
JButtons
Act as push buttons which invoke some action when clicked. These are not buttons that are toggled on and off.
add()
Method of a content pane puts a JButton in the frame.
getContentPane()
Method of a frame is used to get the reference to the content pane.
JText Component Class
Provides a base class for Swing components that handle editable text.
JText Component Class
It provides the functionalities for entering and editing text information-nearly all the features of a text editor.
·TextComponent
JTextField,JTextArea, andJEditorPane.TextComponent has three direct subclasses:
int getColumns()
Returns the number of columns in this TextField
voidsetColumns(int columns)
Sets the number of columns in this TextField, and then invalidate the layout
intgetHorizontalAlignment()
Returns the horizontal alignment of the text
voidsetHorizontalAlignment (int Alignment)
Sets the horizontal alignment of the text
voidsetFont(Font f)
Sets the current font
JTextAreaClass
Displays multiple lines of text in a single font and style and optionally allows the user to edit the text.
JTextArea Class
Uses the rows and columns properties to indicate the preferred size of the viewport when placed inside a JScrollPane to match the functionality provided by java.awt.TextArea.
getText()
Returns the text in the field
setBackground(Color BackgroundColor)
Sets the background color of the TextArea
setEditable(boolean Editable)
Sets the field as being editable or fixed
setFont(Font TextFont)
Sets the font for this component
setLineWrap(boolean LineWrap)
Sets the line-wrapping policy of the text area
setText(String text)
Sets the text for the field
TextFields
A lightweight component that allows the editing of a single line of text.
JLabelClass
An object can display either text or an image, or both. It cannot react to input events but is instead commonly used to provide a label identifier for a nearby object that does.
StringgetText()
Returns the text string that the label displays
voidsetText(String text)
Defines the single line of text this component will display
intgetHorizontalAlignment()
Returns the alignment of the label's contents along the X axis
intgetVerticalAlignment()
Returns the alignment of the label's contents along the Y axis
voidsetVerticalAlignment (int alignment)
Sets the alignment of the label's contents along the Y axis
TextFields
A display area for a short text string or an image or both.
JComboClass
A component that combines display area showing an option, and a list box containing additional options.