java jmf 的 控制条问题 急急急
我的控制条有问题,不知道为什么,一出现的时候控制条是这样的:
然后稍微对边框的大小进行修改一下,控制条就成了这样:
怎么修改一下,希望可以使控制条一直是下面的状况呢?拜托了!!
这是代码
package Appliction;
import javax.swing.JFrame ;
import javax.swing.JPanel ;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player ;
import javax.media.PrefetchCompleteEvent;
import javax.media.RealizeCompleteEvent;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component ;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.URL;
public class My_MP3Player
{
private JFrame JF1 ;
// private JPanel JP1 ;
private Player player ;
private Component com_contrl ;
private ControllerListener conLis ;
private Dimension dim ;
//初始化播放器private void ini_player(URL url) throws IOException
{
try
{
player = Manager.createPlayer(url) ;
}
catch(NoPlayerException noE)
{
System.out.println("没有发现播放器存在");
noE.printStackTrace() ;
}
}
//初始化参数
private void ini_Field()
{
JF1 = new JFrame("播放器") ;
// JP1 = new JPanel() ;
dim = new Dimension() ;
}
//注册controllerListenerprivate void register()
{
conLis = new ControllerListener()
{
@Override
public void controllerUpdate(ControllerEvent ce)
{
if(ce instanceof RealizeCompleteEvent)
{
player.prefetch() ;
}
if(ce instanceof PrefetchCompleteEvent)
{
if(com_contrl != null)
{
return ;
}
else if( (com_contrl = player.getControlPanelComponent())!= null )
{
// JP1.add(com_contrl , BorderLayout.EAST) ;
JF1.add(com_contrl , BorderLayout.SOUTH) ;
dim = com_contrl.getPreferredSize();
}
else
{
System.out.println("添加组件失败");
}
}
}
} ;
player.addControllerListener(conLis) ;
}
//播放设置private void player(URL url) throws IOException
{
ini_Field() ;
ini_player(url) ;
JF1.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
if(player != null)
{
player.close();
}
System.exit(0);
}
});
register() ;
// JP1.setPreferredSize(new Dimension(300+dim.width, 50+dim.height)) ;
// JP1.setBackground(Color.BLUE) ;
JF1.setSize(300 + dim.width , 320+dim.height) ;
// JF1.add(JP1 , BorderLayout.SOUTH) ;
JF1.validate() ;
JF1.setVisible(true) ;
player.realize() ;
player.start() ;
}
//构造函数public My_MP3Player(URL url) throws IOException
{
player(url) ;
}
//main函数
public static void main(String[] args)
{
try
{
URL url = new URL("file:///E:\\音乐\\Ours.mp3") ;
if(url.getFile() == null)
{
throw new IOException("未找到文件") ;
}
else
{
new My_MP3Player(url) ;
}
}
catch(IOException ioe)
{
ioe.printStackTrace() ;
}
}
}
以上是 java jmf 的 控制条问题 急急急 的全部内容, 来源链接: utcz.com/p/173611.html