📄 videoplayer1.java
字号:
package Longin;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import javax.media.*;
import javax.media.Player;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JToolBar;
public class VideoPlayer1 extends Frame implements ControllerListener
{
private Player player;
private Panel panel;
Component visual, control;
private JToolBar jToolBar1 = new JToolBar();
private JButton jButton2 = new JButton();
private JButton jButton3 = new JButton();
private JButton jButton4 = new JButton();
public static void main(String[] args)
{
VideoPlayer1 Medialist = new VideoPlayer1();
Medialist.nextMedia();
}
public VideoPlayer1()
{
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
if (player!=null) player.close();
System.exit(0);
}});
setTitle("Player");
panel=new Panel();
panel.setLayout(new BorderLayout());
add( panel,"Center");
setVisible(true);
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
public void nextMedia()
{
try
{
FileDialog fd =
new FileDialog(this, "Select File", FileDialog.LOAD);
fd.show();
String filename = fd.getDirectory() + fd.getFile();
player = Manager.createPlayer
(new MediaLocator("file:///" + filename));
player.addControllerListener(this);
setTitle(filename);
}
catch(Exception x) { x.printStackTrace(); }
}
public void controllerUpdate(ControllerEvent ce)
{
if (ce instanceof RealizeCompleteEvent)
{
panel.removeAll();
//int videoWidth=320, videoHeight=200, controlHeight=30;
if ((visual=player.getVisualComponent())!=null)
{
Dimension size=visual.getPreferredSize();
//videoWidth=size.width;
//videoHeight=size.height;
panel.add( "Center", visual);
}
else
{
panel.setVisible(false);
}
if ((control=player.getControlPanelComponent())!=null)
{
//controlHeight=control.getPreferredSize().height;
panel.add("South", control);
}
setSize(1024,745);
//this.setSize(new Dimension(1024, 800));
validate();
}
else if(ce instanceof EndOfMediaEvent)
nextMedia();
}
private void jbInit() throws Exception {
this.setSize(new Dimension(1024, 800));
// this.getContentPane().setLayout( null );
jButton2.setText("打开");
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jButton3.setText("播放");
jButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton3_actionPerformed(e);
}
});
jButton4.setText("退出");
jButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton4_actionPerformed(e);
}
});
jToolBar1.add(jButton2, null);
jToolBar1.add(jButton3, null);
jToolBar1.add(jButton4, null);
this.add(jToolBar1, BorderLayout.NORTH);
}
private void jButton2_actionPerformed(ActionEvent e) {
this.nextMedia();
}
private void jButton4_actionPerformed(ActionEvent e) {
this.dispose();
// player.
}
private void jButton3_actionPerformed(ActionEvent e) {
player.start();
}
}
//}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -