I want to create a video player in which I have only one button. When I click that button the JFilechooser appears. So I want to play the selected video.
package minimal.video.player;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MinimalVideoPlayer extends JFrame implements ActionListener{
public JPanel contentPane;
public JButton open;
public MinimalVideoPlayer(){
super("Minimal Video Player");
setLayout(null);
setBounds(350, 150, 700, 400);
setBackground(Color.WHITE);
contentPane = new JPanel();
contentPane.setLayout(null);
contentPane.setBounds(350, 150, 700, 400);
contentPane.setBackground(Color.WHITE);
setContentPane(contentPane);
ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("minimal/video/player/icon/open.png"));
Image i2 = i1.getImage().getScaledInstance(100, 100, Image.SCALE_SMOOTH);
ImageIcon i3 = new ImageIcon(i2);
open = new JButton(i3);
open.setBounds(300, 120, 100, 100);
open.setBackground(Color.WHITE);
open.setBorder(null);
open.addActionListener(this);
contentPane.add(open);
}
public static void main(String[] args) {
new MinimalVideoPlayer().setVisible(true);
}
@Override
public void actionPerformed(ActionEvent ae) {
JFileChooser chooser = new JFileChooser();
int action = chooser.showOpenDialog(this);
if (action != JFileChooser.APPROVE_OPTION) {
return;
}
// What code do I need to insert here?
}
}
I want to create a video player in which I have only one button. When I click that button the JFilechooser appears. So I want to play the selected video.