-1

下面的代码看起来是否正确,是否有任何错误?我必须创建一个音乐流派的下拉框。

我的代码:

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

public class ComboBoxWindow extends JFrame
{
    private JPanel musicPanel;
    private Jpanel selectMusicPanel;
    private JComboBox MusicBox;
    private JLabel label;
    private JTextField selectedMusic;


    private String[] music = {"Rock","Metal","Electro","Pop","Country","Jazz","Indie"};

    public ComboBoxWindow()
    {
        super("Combo Box Demo");

        setDefultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setLayout(new BorderLayout());

        buildMusicPanel();
        buildSelectedMusicPanel;

        add(musicPanel,BorderLayout.CENTER);
        add(selectedMusicPanel, BorderLayout.SOUTH);

        pack();
        setVisible(true);
    }

    private void buildMusicPanel()
    {
        musicPanel = new JPanel();

        musicBox = new JComboBox(music);

        musicBox.addActionListener(new ComboBoxListener());
        musicPanel.add(MusicBox);
    }

    private void buildSelectedCoffeePanel()
    {
        selectedMusicPanel = new JPanel();

        label = new JLabel("You selected: ");

        selectedMusic = new JTextField(10);
        selectedMusic.setEditable(flase);

        selectedMusicPanel.add(label);
        selectedMusicPanel.add(selectedMusic);
    }

    private class ComboBoxListener implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            String selection = (String) MusicBox.getSelectedItem();
            selectedMusic.setText(selection);

            public static void main(String[] args)
            {
                new ComboBoxWindow();
            }
        }
4

1 回答 1

6

尝试ideone.com来解释它。

于 2012-05-05T03:33:23.957 回答