Tenho um JDesktopPane e nele um JInternalFrame que é um menu e ele deve chamar um outro JInternalPane que está em outro método. Como faço para adicionar no meu JDesktopPane?
Aqui está o meu código:
package testejogo1;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseMotionListener;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import javax.swing.plaf.basic.BasicInternalFrameUI;
public class interface2 {
public static void telaInicio(){
//janela
JFrame janela = new JFrame();//criar uma nova janela
JDesktopPane desk = new JDesktopPane();
janela.setBounds(500,100,300,528);//define a posiçao e as dimenções da janela
janela.getContentPane().setBackground(Color.MAGENTA);//define a cor de fundo da janela
janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
janela.setResizable(false);//bloqueia redimencionar janela
JInternalFrame tela = new JInternalFrame("",false,false,false,false);
((BasicInternalFrameUI)tela.getUI()).setNorthPane(null); //retirar o painel superior
tela.setBorder(null);//retirar bordas
tela.setBounds(0, 0, 300,500);//dimenções
tela.getContentPane().setBackground(Color.MAGENTA);//define a cor de fundo da janel
tela.setLayout(null);
tela.setResizable(false); //bloqueia redimencionar tela
tela.getDesktopIcon().removeMouseMotionListener(tela.getDesktopIcon().getMouseMotionListeners()[0]);
//imagem da janela
Icon imagem = new ImageIcon("C:\\A829B0819.PNG");
JLabel icon = new JLabel(imagem);
icon.setBounds(0,10,295,300);
tela.add(icon);
//botãp 1 - jogar
JButton botao= new JButton("JOGAR");
botao.setBounds(45,350,200,30);
botao.setForeground(Color.BLUE);
botao.setToolTipText("inicia o jogo");
tela.add(botao);
//botão 2 - sobre
JButton botao2= new JButton("SOBRE");
botao2.setBounds(45,400,200,30);
botao2.setForeground(Color.BLUE);
botao2.setToolTipText("informações sobre o jogo");
tela.add(botao2);
Action1 action = new Action1();
Interface3 a3 = new Interface3();
//açao atribuida ao botão 1
botao.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
tela.hide();
//tela2();
tela.setVisible(true);
}
}
);
//açao atribuida ao boão 2
botao2.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
}
}
);
janela.setVisible(true);
janela.add(desk);
desk.setVisible(true);
desk.add(tela);
tela.setVisible(true);
icon.setVisible(true);
}
public static void tela2(){
JInternalFrame tela = new JInternalFrame("",false,false,false,false);
((BasicInternalFrameUI)tela.getUI()).setNorthPane(null); //retirar o painel superior
tela.setLayout(null);
tela.setBorder(null);//retirar bordas
tela.setBounds(0, 0, 300,500);//dimenções
tela.getContentPane().setBackground(Color.blue);//define a cor de fundo da janel
tela.setResizable(false); //bloqueia redimencionar tela
//botãp 1 - jogar
JButton botao= new JButton("VOLTAR");
botao.setBounds(45,350,200,30);
botao.setBackground(Color.GREEN);
botao.setForeground(Color.BLUE);
botao.setToolTipText("volta");
tela.add(botao);
Action1 action = new Action1();
Interface3 a3 = new Interface3();
//açao atribuida ao botão 1
botao.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
telaInicio();
}
}
);
tela.setVisible(true);
}
}