JPanel leftPane = new JPanel();
JPanel centerPane = new JPanel();
JPanel toolbar = new JPanel();
como se llama ese tipo de uso de llaves, ¿que finalidad tiene?, ¿en que casos se usan?
Gracias de antemano.
Código:
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));
makeMenuBar();
// 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));
String[] formats = { "all formats", ".wav", ".au", ".aif" };
// Create the combo box.
JComboBox formatList = new JComboBox(formats);
formatList.addActionListener(this);
leftPane.add(formatList, BorderLayout.NORTH);
// Create the scrolled list for file names
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));
JLabel image = new JLabel(new ImageIcon("title.jpg"));
centerPane.add(image, BorderLayout.NORTH);
centerPane.setBackground(Color.BLACK);
infoLabel = new JLabel(" ");
infoLabel.setHorizontalAlignment(SwingConstants.CENTER);
infoLabel.setForeground(new Color(140,171,226));
centerPane.add(infoLabel, BorderLayout.CENTER);
slider = new JSlider(0, 100, 0);
TitledBorder border = new TitledBorder("Seek");
border.setTitleColor(Color.white);
slider.setBorder(new CompoundBorder(new EmptyBorder(6, 10, 10, 10), border));
slider.addChangeListener(this);
slider.setBackground(Color.BLACK);
slider.setMajorTickSpacing(25);
slider.setPaintTicks(true);
centerPane.add(slider, BorderLayout.SOUTH);
}
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);
}