Sei sulla pagina 1di 2

String strOne= "THE_UNIVERSITY_OF_THE_EAST-MANILA";

String strTwo= "COLLEGE_OF_COMPUTER_STUDIES_AND_SYSTEMS";


System.out.println(strTwo.length());
System.out.println(strOne.charAt(3));
System.out.println(strTwo.equals(strOne));
System.out.println(strOne.substring(17));
System.out.println(strOne.substring(3,10));
System.out.println(strTwo.substring(11,21));
System.out.println(strOne.length());
System.out.println(strOne.substring(4,12));
System.out.println(strTwo.substring(20));
System.out.println(strOne.charAt(124));
System.out.println(strOne.concat(" Warriors 1-6"));
System.out.println(strTwo.replace("COLLEGE","School"));
System.out.println(strTwo.indexOf('C'));
RESULT:
39
_
false
_THE_EAST-MANILA
_UNIVER
COMP
33
UNIVERSI
STUDIES_AND_SYSTEMS
T
THE_UNIVERSITY_OF_THE_EAST-MANILA Warriors 1-6
School_OF_COMPUTER_STUDIES_AND_SYSTEMS
0
Basic Swing Components

JEditorPanes and JPasswordFields - for displaying web pages and inputting confidential
information

Dialogs - for displaying warnings, errors, prompting for input

Check Boxes - for selecting a small set of options

Radio Buttons - for mutually exclusive selection of options

Combo Boxes - for selecting a small set of qualified options

JLists - for selecting from a large set of qualified options

JTables - for table displays

JMenuBar, JMenu, and JMenuItems - for creating menus

File Chooser - for navigating through files and directories, and selecting files and
directories

Tabbed Panels - for allowing different panels to occupy the same screen area

Besides JTextField and JTextArea, Swing offers other textField


components. JEditorPane can display not only text, but html files as well. In fact, there is
a setPage(url) method associated with JEditorPanes that can load a file or html page
given its URL! Another text field is JPasswordField. It is a subclass of JTextField and
performs identically, except that textual input is hidden.
JLabels can display GIF images, and these images can change at application run-time. In
this program, when a checkbox is selected, an image is loaded into a predetermined label.
RuncheckBoxDemo.
The JList component allows users to select from a large list of options and the list of options
themselves is editable at run-time. The listDemo illustrates the editing of two JLists,
allowing selected items from one list to be moved to the second and vice versa.
The JTable component displays the contents of a table. It is very versatile and has
seemingly endless ways of being customized. However, with this generality comes a price -it can be difficult to program. Fortunately, the simple things such as displaying a table,
detecting updates to the table, adding rows, etc. is fairly easy to do.
A menu bar and menus are easy to create. A menu bar is represented by
a JMenuBar object. Individual menus (such as "File" and "Edit" in the figure below)
are JMenu objects that are added to the JMenuBar. Each item of a menu is either a
terminal option (represented by a JMenuItem object) or a JMenu object (which represents
a nested or "walking" menu). The MenuBarobject is added to the JFrame object by calling
the setJMenuBar method.
Selecting any JMenuItem fires an ActionEvent. So registering and reacting to the
selection of a JMenuItem is no different than registering and reacting to a push of
a JButton.
The menuDemo program illustrates the creation and use of menu bars, menus, and their
event handlers. The "File" menu has MenuItems "Open", "Close", and "Exit". The "Edit"
menu has a nested menu "Options", which has MenuItems "Copy" and "Cut".
When menuDemo runs, each JMenuItem selected will be noted in a JTextField.
The JFileChooser component allows users to navigate through a file system and select
files, directories, or both. JFileChooser is highly customizable and supports file filtering and
other features. For details, consult the Swing web page for JFileChooser. The main window
of fileChooserDemo is simple: it consists of two buttons and a log (JTextArea) of user
selections. When either button is pushed, a file chooser dialog window appears, which allows
for navigation and selection. Run fileChooserDemo. Note that a JFileChooser has no GUI,
per se. It does use dialogs to prompt for input.
JTabbedPanels allows different panels to share the same space, where only one panel is
displayed at a time. The TabbedPanels application takes several of the previous Swing
programs and unifies them into a single program with tabbed panels, one panel per
program. Run TabbedPanels and note that state information per panel is retained.

Potrebbero piacerti anche