/** * Title: Exercise Solutions * Description: Solutions to the exercises for Introduciton to Java Programming with JBuilder 4 * Copyright: Copyright (c) 2000 * Company: Armstrong Atlantic State University * @author Y. Daniel Liang * @version 1.0 */ /** * Title: Exercise Solutions * Description: Solutions to the exercises for Introduciton to Java Programming with JBuilder 4 * Copyright: Copyright (c) 2000 * Company: Armstrong Atlantic State University * @author Y. Daniel Liang * @version 1.0 */ import javax.swing.*; import java.awt.*; // Define a panel for displaying image and text public class DescriptionPanel extends JPanel { /**Label for displaying an image icon*/ private JLabel jlblImage = new JLabel(); /**Label for displaying a title*/ private JLabel jlblTitle = new JLabel(); /**Text area for displaying text*/ private JTextArea jtaTextDescription; /**Default constructor*/ public DescriptionPanel() { // Group image label and title label in a panel JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add(jlblImage, BorderLayout.CENTER); panel.add(jlblTitle, BorderLayout.SOUTH); // Create a scroll pane to hold text area JScrollPane scrollPane = new JScrollPane (jtaTextDescription = new JTextArea()); // Center the title on the label jlblTitle.setHorizontalAlignment(JLabel.CENTER); // Set the font for the title and text jlblTitle.setFont(new Font("SansSerif", Font.BOLD, 16)); jtaTextDescription.setFont(new Font("Serif", Font.PLAIN, 14)); // Set lineWrap and wrapStyleWord true for text area jtaTextDescription.setLineWrap(true); jtaTextDescription.setWrapStyleWord(true); // Set preferred size for the scroll pane scrollPane.setPreferredSize(new Dimension(200, 100)); // Set BorderLayout for the whole panel, add panel and scrollpane setLayout(new BorderLayout()); add(scrollPane, BorderLayout.CENTER); add(panel, BorderLayout.WEST); } /**Set the title*/ public void setTitle(String title) { jlblTitle.setText(title); } /**Set the image icon*/ public void setImageIcon(ImageIcon icon) { jlblImage.setIcon(icon); Dimension dimension = new Dimension(icon.getIconWidth(), icon.getIconHeight()); jlblImage.setPreferredSize(dimension); } /**Set the text description*/ public void setTextDescription(String text) { jtaTextDescription.setText(text); } }