Example #1
0
  private void makeFrame(String[] audioFiles) {
    // the following makes sure that our application exits when
    // the user closes its window
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JPanel contentPane = (JPanel) getContentPane();
    contentPane.setBorder(new EmptyBorder(6, 10, 10, 10));

    // Specify the layout manager with nice spacing
    contentPane.setLayout(new BorderLayout(8, 8));

    // Create the left side with combobox and scroll list
    JPanel leftPane = new JPanel();
    {
      leftPane.setLayout(new BorderLayout(8, 8));

      fileList = new JList(audioFiles);
      fileList.setForeground(new Color(140, 171, 226));
      fileList.setBackground(new Color(0, 0, 0));
      fileList.setSelectionBackground(new Color(87, 49, 134));
      fileList.setSelectionForeground(new Color(140, 171, 226));
      JScrollPane scrollPane = new JScrollPane(fileList);
      scrollPane.setColumnHeaderView(new JLabel("Audio files"));
      leftPane.add(scrollPane, BorderLayout.CENTER);
    }
    contentPane.add(leftPane, BorderLayout.CENTER);

    // Create the center with image, text label, and slider
    JPanel centerPane = new JPanel();
    {
      centerPane.setLayout(new BorderLayout(8, 8));

      infoLabel = new JLabel("  ");
      infoLabel.setHorizontalAlignment(SwingConstants.CENTER);
      infoLabel.setForeground(new Color(140, 171, 226));
      centerPane.add(infoLabel, BorderLayout.CENTER);
    }
    contentPane.add(centerPane, BorderLayout.EAST);

    // Create the toolbar with the buttons
    JPanel toolbar = new JPanel();
    {
      toolbar.setLayout(new GridLayout(1, 0));

      JButton button = new JButton("Play");
      button.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              play();
            }
          });
      toolbar.add(button);

      button = new JButton("Stop");
      button.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              stop();
            }
          });
      toolbar.add(button);

      button = new JButton("Pause");
      button.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              pause();
            }
          });
      toolbar.add(button);

      button = new JButton("Resume");
      button.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              resume();
            }
          });
      toolbar.add(button);
    }

    contentPane.add(toolbar, BorderLayout.NORTH);

    // building is done - arrange the components
    pack();

    // place this frame at the center of the screen and show
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation(d.width / 2 - getWidth() / 2, d.height / 2 - getHeight() / 2);
    setVisible(true);
  }