Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Action on Netbeans
Or you can also click 2x the component that you want to add the event to. For the (JButton)
button, the event that is formed is action er actionPerformed (). The source code section will
appear in the gui as follows. Programming logic can be written in the method.
Method Swing Components
Some swing components have methods that can be used for programming logic
contained in event handlers. Some of the most commonly used are as follows:
Method Komponen Fungsi
setText(“X”) JButton, JTextfield, JLabel Sets the text that appears on
each of them Component
getText() JButton, JTextfield, JLabel Take the String value found in getSelectedIndex() JComboBox Retrieves the selected index from the
each of each component component. Index starts from 0
setToolTipText(“X”) JButton, JTextfield, JLabel Provides tooltip for
components getSelectedItem() JComboBox Retrieves the selected object from the
setEnabled(false) JButton, JTextfield, Enable a component or not component. Can be directly displayed if
JLabel, JComboBox, (can clicked on or not) the selected object String.
JRadioButton,
JCheckBox
setSelected(true) JRadioButton, JCheckBox Make each one component insertItemAt(objek, indek) JComboBox Enter selected items in the form of a
selected or not type object Objects in the index to
isSelected() JRadioButton, JCheckBox Check whether a component index
is selected or not setValueAt(Objek, Sets a table with an Object value of
JTable
setSelectedIndex(4) JComboBox Make an index of a certain baris, kolom) type Object data in rows and columns
number as a component Certain
Selected
getSelectedRow() JTable Retrieves the table row index selected.
Index starts from 0
getSelectedColumn() JTable Retrieves the index of the selected
table column. Index starts from 0
Dialogical use JOptianPane
On the swing component, this component is called JOptionPane. There are 4 options pane
a) showConfirmDialog : To confirm yes / no / cancel
b) showInputDialog : To display pop-ups as input data
c) showMessageDialog : To display status / message with 1 "OK" button.
d) showOptionDialog : A combination of the three components above.
There is a confirmation section, asking for input and displaying status /
message
showConfirmDialog
JOptionPane.showConfirmDialog(null, "Isi Pesan"); Comparative messages consist
of:
o YES_OPTION:
if you choose the button “YES”
o OK_OPTION:
if you choose the button “OK”
o NO_OPTION:
To retrieve the value of each if you choose the button “NO”
key pressed, use the following o CLOSED_OPTION:
code: if you choose the button “CLOSED”
o CANCEL_OPTION:
if you choose the button “CANCEL”
showInputDialog