Allora..dopo qualche giorno di lavoro ho capito grazie al tuo codice come far funzionare il tutto. Adesso se io al posto del, o dei, bottoni ci metto dei pannelli da me creati con dei disegni non mi mostra più nulla. Solo il canvas che contiene il media player.
CLASSE MEDIAPLAYER
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.Border;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.player.embedded.windows.Win32FullScreenStrategy;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
public class MediaPlayer extends JFrame {
Canvas c;
MediaPlayerFactory mpf;
EmbeddedMediaPlayer emp;
private JPanel mainPanel;
private JPanel controlPanel;
private DisposeShapes faccia0;//JButton playButton0;
private DisposeShapes faccia1;//JButton playButton1;
private DisposeShapes faccia2;//JButton playButton2;
private Mouse mouse;
private String nameFile[]={"0.mp4","1.mp4","2.mp4"};
public MediaPlayer(){
mouse= new Mouse();
mainPanel = new JPanel(new BorderLayout(100,100));
mainPanel.setBorder(BorderFactory.createEmptyBorder(10,200,400,200));
controlPanel = new JPanel();
controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.LINE_AXIS));
c = new Canvas();
c.setBackground(Color.BLACK);
c.setPreferredSize(new Dimension(400, 300));
faccia0= new DisposeShapes();
faccia1= new DisposeShapes();
faccia2= new DisposeShapes();
faccia0.addMouseListener(mouse);
faccia1.addMouseListener(mouse);
faccia2.addMouseListener(mouse);
controlPanel.add(faccia0, BorderLayout.EAST);
controlPanel.add(faccia1, BorderLayout.CENTER);
controlPanel.add(faccia2, BorderLayout.WEST);
mainPanel.add(c, BorderLayout.CENTER);
mainPanel.add(controlPanel, BorderLayout.SOUTH);
setContentPane(mainPanel);
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),"lib");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
mpf= new MediaPlayerFactory();
emp= mpf.newEmbeddedMediaPlayer();
this.setBounds(200, 500, 1000, 1000);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void play(String src){
emp.setVideoSurface(mpf.newVideoSurface(c));
emp.setEnableMouseInputHandling(false);
emp.setEnableKeyInputHandling(false);
emp.prepareMedia(src);
emp.play();
}
/*@Override
public void actionPerformed(ActionEvent e) {
Object src= e.getSource();
if(src==playButton0){
play(nameFile[0]);
}
if(src==playButton1){
play(nameFile[1]);
}
if(src==playButton2){
play(nameFile[2]);
}
}
*/
private class Mouse implements MouseListener{
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
Object src= e.getSource();
if(src==faccia0){
play(nameFile[0]);
}
if(src==faccia1){
play(nameFile[1]);
}
if(src==faccia2){
play(nameFile[2]);
}
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
}
}
CLASSE TESTMEDIAPLAYER
import javax.swing.JFrame;
public class TestProvePlayer {
public static void main(String[] args) {
MediaPlayer mp= new MediaPlayer();
}
}
CLASSE DISPOSESHAPE
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import javax.swing.JPanel;
public class DisposeShapes extends JPanel
{
public void paintComponent(Graphics g)
{
//Graphics2D necessario!
Graphics2D g2d = (Graphics2D) g;
//disegnamo la testa
Ellipse2D.Double head = new Ellipse2D.Double(5, 10, 100, 150);
g2d.draw(head);
//disegnamo gli occhi
g2d.setColor(Color.GREEN);
Rectangle eye = new Rectangle(25, 70, 15, 15);
g2d.fill(eye);
eye.translate(50, 0);
g2d.fill(eye);
//disegnamo la bocca
Line2D.Double mouth = new Line2D.Double(30, 110, 80, 110);
g2d.setColor(Color.RED);
g2d.draw(mouth);
//Disegno il saluto
g2d.setColor(Color.BLUE);
g2d.drawString("Hello, World", 5, 175);
/*
* ESERCIZIO: riuscite a disegnarne due di facce?
*/
}
}