Due by 11:59pm Wednesday, March 6
Finish the exercises from Lab 6 and submit the following class definitions:
Write a program called FontBrowser with the graphical user interface shown below, that allows the user to interactively browse through all of the fonts available on the system:
The user selects the desired font from the pull-down menu. Bold and/or italic style can be specified by checking the appropriate boxes. The slider bar controls the size of the font. A text sample in the currently selected font is shown below the font controls. Choosing a new font from the menu, checking or unchecking a style box, or adjusting the font size slider bar should immediately update the text sample (and font size label) to reflect the new settings.
You can use this code as your starting point. Here are some further hints and guidelines:
The GUI window should consist of two panels: a control panel to
hold the font controls, and a text panel to display the sample text in
the selected font. For the font controls, you should use a JComboBox
To make the font controls work, you will need to attach listener objects to them. The menu and checkboxes require an ActionListener, whereas the slider bar requires a ChangeListener. Whenever the menu or checkboxes get updated, the ActionListener's actionPerformed(ActionEvent event) method will be called automatically. Whenever the slider bar is moved, the ChangeListener's stateChanged(ChangeEvent event) method will be called. You can define a single listener class that implements both interfaces simultaneously, or if you prefer, you can define two separate inner listener classes: one that implements the ActionListener interface, and another that implements the ChangeListener interface.
Define a helper method called updateSampleText() to update the text displayed in the text panel based on the currently selected font. By making this a separate method, you can avoid having to duplicate code in your listener classes.
The code below will create an array of Strings containing the names of all of the available fonts on the system:
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fontNames = env.getAvailableFontFamilyNames();
Here are some other useful methods to be aware of:
Files to submit:
Submit the above files using the Homework Upload Site. Please include your name and the assignment number in a comment at the top of each Java source code file. You DO NOT need to submit your compiled .class files or any other files.
If you have questions about anything, just ask!