0
package display;

import java.awt.EventQueue;
import javax.swing.JFileChooser;

import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.JTextField;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class PlayerGUI {

    private JFrame frame;
    private JTextField pathField;
    private File songFile;


    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());    

                    PlayerGUI window = new PlayerGUI();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }


    public PlayerGUI() {
        initialize();
    }


    private void initialize() {
        frame = new JFrame();
        frame.setForeground(Color.BLACK);
        frame.setTitle("GeN.G MP3");
        frame.setBounds(100, 100, 290, 148);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.getContentPane().setLayout(null);

        JButton startBtn = new JButton(">");
        startBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                //play audio
            }
        });
        startBtn.setFont(new Font("Tahoma", Font.PLAIN, 16));
        startBtn.setBounds(10, 42, 254, 56);
        frame.getContentPane().add(startBtn);

        pathField = new JTextField();
        pathField.setForeground(Color.GRAY);
        pathField.setEditable(false);
        pathField.setText("\u041F\u0443\u0442\u044C \u043A \u043F\u0435\u0441\u043D\u0435");
        pathField.setBounds(10, 11, 188, 20);
        frame.getContentPane().add(pathField);
        pathField.setColumns(10);

        JButton openBtn = new JButton("\u041D\u0430\u0439\u0442\u0438");
        openBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    JFileChooser chooser = new JFileChooser();
                    chooser.setDialogTitle("Выбери песню для проигрывания...");
                    chooser.showOpenDialog(null);
                    songFile = chooser.getSelectedFile();
                    System.out.println("Файл "+songFile.getName ()+", выбран!");

                }catch(Exception e1) {
                    e1.printStackTrace();
                }
            }
        });
        openBtn.setBounds(201, 10, 63, 23);
        frame.getContentPane().add(openBtn);
    }
}

Подчеркивается File в private File songFile;, songFile в songFile = chooser.getSelectedFile(); и songFile в System.out.println("Файл "+songFile.getName ()+", выбран!");.

При этом ошибка:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

    at display.PlayerGUI.main(PlayerGUI.java:22)

Заранее спасибо за ответ!

1 ответ 1

0

Добавить импорт import java.io.File;

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.