SwingCodeExhibit //************************************************************************************ // The 6 demo classes are lifts from the Magelang Swing Tutorial. They are provided // as examples in a collection you can inspect on your computer. Lift the code to an // editor compile and run //************************************************************************************ import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.text.*; import javax.swing.border.*; //Demo class 1 from Magelang tutorial class RadioButtonPanel extends JPanel { RadioButtonPanel() { // Set the layout to a GridLayout setLayout(new GridLayout(4,1)); // Declare a radio button JRadioButton radioButton; // Instantiate a ButtonGroup for functional // association among radio buttons ButtonGroup rbg = new ButtonGroup(); // Create a label for the group JLabel label = new JLabel("Annual Salary: "); label.setFont(new Font("SansSerif", Font.BOLD, 14)); add(label); // Add a new radio button to the pane radioButton = new JRadioButton("$45,000"); add (radioButton); // set key accelerator radioButton.setMnemonic (KeyEvent.VK_4); // Add the button to the ButtonGroup rbg.add (radioButton); // Set this radio button to be the default radioButton.setSelected(true); // Set up two more radio buttons radioButton = new JRadioButton("$60,000"); radioButton.setMnemonic (KeyEvent.VK_6); add (radioButton); rbg.add (radioButton); radioButton = new JRadioButton("$75,000"); radioButton.setMnemonic (KeyEvent.VK_7); add (radioButton); rbg.add (radioButton); } } //***************************************** // Demo class 2 from swing tutorial class ScrollPanel extends JPanel { public ScrollPanel() { // The .gif here may not be visible setLayout(new BorderLayout()); // or available to your code so go Icon b = new ImageIcon("Ball_ani.gif"); // get one from the OS or the net, JLabel cloudLabel = new JLabel(b); // place it in the directory with JScrollPane scrollPane = new JScrollPane(cloudLabel); // your source code and make it's add(scrollPane, BorderLayout.CENTER); // file name the argument to the } // new ImageIcon( ) constructor } //***************************************** //Demo class 3 class TextPanel extends JPanel { public TextPanel() { // Set the layout to a BorderLayout setLayout(new BorderLayout()); // Create the three basic text components JTextField textField = new JTextField("The JTextField"); JTextArea textArea = new JTextArea("The JTextArea.\n The JTextPane" + "below requires you to add a StyledDocument"); JTextPane textPane = new JTextPane(); //Set the textpane's font properties MutableAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setFontFamily(attr, "Serif"); StyleConstants.setFontSize(attr, 18); StyleConstants.setBold(attr, true); textPane.setCharacterAttributes(attr, false); add(textField, BorderLayout.NORTH); add(new JScrollPane(textArea), BorderLayout.CENTER); add(new JScrollPane(textPane), BorderLayout.SOUTH); } } //*********************************************** //demo class 4 class SliderPanel extends JPanel { public SliderPanel() { setLayout(new BorderLayout()); JSlider slider1 = new JSlider (JSlider.VERTICAL, 0, 100, 50); slider1.setPaintTicks(true); slider1.setMajorTickSpacing(10); slider1.setMinorTickSpacing(2); add(slider1, BorderLayout.EAST); JSlider slider2 = new JSlider (JSlider.VERTICAL, 0, 100, 50); slider2.setPaintTicks(true); slider2.setMinorTickSpacing(5); add(slider2, BorderLayout.WEST); JSlider slider3 =new JSlider (JSlider.HORIZONTAL, 0, 100, 50); slider3.setPaintTicks(true); slider3.setMajorTickSpacing(10); add(slider3, BorderLayout.SOUTH); JSlider slider4 =new JSlider (JSlider.HORIZONTAL, 0, 100, 50); slider4.setBorder(BorderFactory.createLineBorder(Color.blue)); add(slider4, BorderLayout.NORTH); } } //****************************************************** //demo class 5 class ComboPanel extends JPanel { String choices[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus","Neptune", "Pluto"}; public ComboPanel() { JComboBox combo1 = new JComboBox(); combo1.setBorder(new BevelBorder(BevelBorder.RAISED)); //added a border to demo JComboBox combo2 = new JComboBox(); combo2.setBorder(new BevelBorder(BevelBorder.RAISED)); for (int i=0;i