Player em Java

6 respostas
reck

"java.lang.Error: Do not use javax.swing.JFrame.add() use javax.swing.JFrame.getContentPane().add() instead

at javax.swing.JFrame.createRootPaneException(JFrame.java:465)

at javax.swing.JFrame.addImpl(JFrame.java:491)

at java.awt.Container.add(Container.java:307)

at projeto_integrador.MediaTest.main(MediaTest.java:39)"

da esse erro no nosso player, ele toca e td soh q a parte gráfica q ele devia carrega ñ abre…
na verdade essa parte gráfica é o JMF…

alguem pode dar uma ajudinha ai???

vlw

6 Respostas

Wolf_X

parece q vc ta tentando inserir algo diretamente no JFrame , nao se faz assim vc deve pegar o Pane do JFrame atraves do metodo getContentPane e entao add oq vc deseja

xan

[color=red]java.lang.Error: Do not use javax.swing.JFrame.add() use javax.swing.JFrame.getContentPane().add()[/color]

{
    Container c = this.getContentPane();
    JFrame frame = new JFrame();
    frame.add(seu componente);
    c.add(frame);
    //...resto do codigo
}
_Renatu

no proprio erro ta escrito o que voce tem que fazer…

é novo com Swing??

no AWT, a gente usa frame.add(), mas no Swing, a gente usa jframe.getContentPane().add().

reck

{ Container c = this.getContentPane(); JFrame frame = new JFrame(); frame.add(seu componente); c.add(frame); //...resto do codigo }

mas esse codigo eu boto no frame que chama o outro??? ou no proprio frame chamado???

essa é minha unica duvida… se alguem me fala em qual é eu boto o codigo pra vcs saberem como é…

vlw

Marky.Vasconcelos

Ao invés de colocar

frame.add(Component);

use:

frame.getContentPane().add(Component);
reck
public class Frame3 extends JFrame {
    public Frame3() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        JBescolha.setBounds(new Rectangle(6, 84, 105, 43));
        JBescolha.setFont(new java.awt.Font("Informal Roman", Font.BOLD, 18));
        JBescolha.setText("Escolha");
        JBescolha.addActionListener(new Frame3_JBescolha_actionAdapter(this));
        JLescolha.setFont(new java.awt.Font("Lucida Calligraphy", Font.BOLD, 15));
        JLescolha.setForeground(SystemColor.window);
        JLescolha.setText("Escolha a música ou vídeo que quer ver!");
        JLescolha.setBounds(new Rectangle(6, 39, 370, 34));
        this.getContentPane().setBackground(SystemColor.menuText);
        this.getContentPane().add(JBescolha);
        this.getContentPane().add(JLescolha);
    }

    JButton JBescolha = new JButton();
    JLabel JLescolha = new JLabel();


    public void JBescolha_actionPerformed(ActionEvent e) {
        JFileChooser fileChooser = new JFileChooser();
      int result = fileChooser.showOpenDialog(null);
      if (result == JFileChooser.APPROVE_OPTION) {
          URL mediaURL = null;

          try {

              mediaURL = fileChooser.getSelectedFile().toURL();
          } catch (MalformedURLException malformedURLException) {
              System.err.println("Could not creat URL for the file");
          }
          if (mediaURL != null) {
              JFrame mediaTest = new JFrame("Media Tester");
              mediaTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              MediaPanel mediaPanel = new MediaPanel( mediaURL );
              mediaTest.add(mediaPanel);

              mediaTest.setSize(300, 300);
              mediaTest.setVisible(true);
              
              

          }
      }
  }


    }



class Frame3_JBescolha_actionAdapter implements ActionListener {
    private Frame3 adaptee;
    Frame3_JBescolha_actionAdapter(Frame3 adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.JBescolha_actionPerformed(e);
    }
}

esse frame chama o frame q possui o JMF pra toca...
soh q ñ aparece nada da janela chamada, mas toca a musica ou video normal

Criado 30 de novembro de 2007
Ultima resposta 4 de dez. de 2007
Respostas 6
Participantes 5