import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

        // Display a floatable JToolBar.
class SwingToolBarFrame extends JFrame {
    public SwingToolBarFrame() {
        final int width = 300, height = 300;
        setSize(width,height);
        Container contents = getContentPane();

        // Create a toolbar.
        JToolBar toolBar = setupToolBar();
        toolBar.setFloatable(true);

        contents.setBackground(Color.white);
        contents.add(toolBar,"North");
        contents.add(new QuitJPanel(),"South");
    }

        // Setup a toolbar to contain four arrow buttons.
    protected JToolBar setupToolBar(){
        // Four buttons for the bar.
        JButton left = new JButton(new ArrowIcon(ArrowIcon.LEFT));
        JButton right = new JButton(new ArrowIcon(ArrowIcon.RIGHT));
        JButton up = new JButton(new ArrowIcon(ArrowIcon.UP));
        JButton down = new JButton(new ArrowIcon(ArrowIcon.DOWN));

        // Add dummy listeners to the buttons.
        left.addActionListener(dummyActionListener("Back"));
        left.setToolTipText("Back");
        right.addActionListener(dummyActionListener("Forward"));
        left.setToolTipText("Forward");
        up.addActionListener(dummyActionListener("Up"));
        left.setToolTipText("Up");
        down.addActionListener(dummyActionListener("Down"));
        left.setToolTipText("Down");

        // Add the buttons to the bar.
        JToolBar bar = new JToolBar(JToolBar.HORIZONTAL);
        bar.add(left);
        bar.add(right);
        bar.addSeparator();
        bar.add(up);
        bar.add(down);
        return bar;
    }

        // Create a dummy ActionListener that just prints the
        // report string when it receives an event.
    protected ActionListener dummyActionListener(final String report){
        return new ActionListener(){
            public void actionPerformed(ActionEvent e){
                System.out.println(report);
            }
        };
    }
}
