[Resolvido]Problema - JInternalFrame não aparece nunca

1 resposta
Naruffy

Pessoal,

Já procurei no google, jah me baseie em tutoriais da sun(no tutorial funciona mas quando eu uso minha classe não) e não consegui fazer,tenho as seguintes classes:

package com.mapeditor;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class MapDesign extends JInternalFrame {

    private String fileName;
    private boolean modified;
    private File file;
    private int width;
    private int height;

    private static int MAP_CREATION = 0;
    public MapDesign() {
        super("Map" + MAP_CREATION++ + ".map", true, true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        JMenuBar menuBar = new JMenuBar();
        setJMenuBar(menuBar);

        JMenu menu = new JMenu("Arquivo");
        menuBar.add(menu);

        JMenuItem item = new JMenuItem("Salvar");
        menu.add(item);
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                if (file == null) {
                    createFile();
                }
                saveExistingFile();
            }
        });

        item = new JMenuItem("Salvar como");
        menu.add(item);
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                createFile();
                saveExistingFile();
            }
        });

        setSize(700, 500);
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
        setTitle(fileName + (isModified() ? "*" : ""));
    }

    public boolean isModified() {
        return modified;
    }

    public void setModified(boolean modified) {
        this.modified = modified;
        setTitle(fileName + (isModified() ? "*" : ""));
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    private void createFile() {
        
    }

    private void saveExistingFile() {
        
    }
}

e

package com.mapeditor;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

/**
 * Editor de mapas para o jogo
 * 
 * @author Erick Zanardo
 *
 */
public class MapEditor extends JFrame {
    private JDesktopPane desktop;
    public MapEditor () {
        super("Snake - Map Editor");
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        desktop = new JDesktopPane();
        desktop.setLayout(null);
        setContentPane(desktop);

        JMenuBar menuBar = new JMenuBar();
        setJMenuBar(menuBar);

        JMenu menu = new JMenu("Arquivo");
        menuBar.add(menu);

        JMenuItem item = new JMenuItem("Novo");
        menu.add(item);
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                MapDesign map = new MapDesign();
                desktop.add(map);
                map.setVisible(true);
            }
        });

        item = new JMenuItem("Abrir");
        menu.add(item);
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                
            }
        });

        item = new JMenuItem("Sair");
        menu.add(item);
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                System.exit(0);
            }
        });

        menu = new JMenu("Ajuda");
        menuBar.add(menu);

        item = new JMenuItem("Ajuda");
        menu.add(item);
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                System.exit(0);
            }
        });

        item = new JMenuItem("Sobre");
        menu.add(item);
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                
            }
        });

        setSize(800, 600);
        setVisible(true);
    }
}

Onde MapDesing eh meu JInternalFrame e a MapEditor o JFrame, o problema é que quando a ação do JMenuItem é acionada nada acontece, o JIntenalFrame não aparece. não sei mais o que fazer, se algume tiver uma luz eu agradeço muito.

[]s

1 Resposta

Naruffy

O problema estava nas variaveis width e height, elas acabaram sobreescrevendo os método da classe

Criado 7 de novembro de 2009
Ultima resposta 7 de nov. de 2009
Respostas 1
Participantes 1