Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Hi to all and gui problem !

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hi to all and gui problem !

    Hi to all ! I'm Yuri6037, french Java developper. I'm developping from the age of 11 years old !
    Today i'm making games using LWJGL - OpenGL !

    I'm good in aproximatly all domains exept one : Javax Swing and Java AWT !


    For my game, BrickBroken (a break-brick game), i have created a file format : .lvlpack (based on Zip compression algorythm), to make levels, users now need a level editor software. The problem is that i could not use LWJGL in the level editor due to file out of jar problem... So i took Javax Swing to make an interface for creating levels !

    The panel for editing levels is ok, tree is ok, but sometimes the software is crashing (only when opening file chooser dialog) with a strange exception : Access Violation !
    In plus, you need sometimes to reduce and reopen the window because the panels are disapearing randomly ! Another problem is that the BrickBroken Data File Editor is not showing properly in the window !

    So i'm coming here to get a solution to these problems...


    I know, if i don't give you code you will say "I can't help !" No problem, i give you the code :
    EditorFrame (main programm class, creates the interface)
    package fr.brickbroken.levelEdit;
     
    import fr.brickbroken.format.BrickBrokenDataFile;
    import fr.brickbroken.format.project.BrickBrokenLevelFile;
    import fr.brickbroken.format.project.LevelPackProjectFile;
    import fr.brickbroken.levelEdit.dialog.EditLevelPack;
    import fr.brickbroken.levelEdit.dialog.LevelPackFileFilter;
    import fr.brickbroken.levelEdit.dialog.NewLevelDialog;
    import fr.brickbroken.levelEdit.os.EnumOS2;
    import fr.brickbroken.levelEdit.os.EnumOSMappingHelper;
    import fr.brickbroken.levelEdit.panel.*;
    import fr.brickbroken.levelEdit.tree.EnumSupportedFileTypes;
    import fr.brickbroken.levelEdit.tree.TreeManager;
     
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.io.IOException;
    import java.util.Hashtable;
     
    import javax.swing.*;
    import javax.swing.event.TreeSelectionEvent;
    import javax.swing.event.TreeSelectionListener;
     
    public class EditorFrame extends JFrame implements TreeSelectionListener {
     
        /**
         * UNUSED
         */
        private static final long serialVersionUID = 1L;
        private EditorPanel panel;
        private ButtonsPanel buttons;
     
        public int levelID;
        public String levelName;
     
        public String[] groups = {"levels", "backgrounds", "scripts"};
        public String[][] users = {{}, {}, {}};
        public TreeManager treeManager;
        public LevelPackProjectFile currentProject;
     
        //The main menu bar
        private JMenuBar menu;
     
        private ToolBar toolBar;
     
        public JTree tree;
     
        public EditorFrame() {
            super("BrickBroken - Level Creator/Editor");
            setSize(1550, 700);
            setResizable(false);
            setLocation((getScreenWidth() / 2) - (1550 / 2), (getScreenHeight() / 2) - (700 / 2));
            setLayout(null);
            levelName = "New Project";
            levelID = 255;
            setTitle("BrickBroken - Level Creator/Editor [" + levelName + "]");
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
     
            buttons = new ButtonsPanel();
     
            toolBar = new ToolBar(this);
     
            tree = new JTree();
            tree.setBounds(1030, 32, getWidth() - 256, 700);
            tree.addTreeSelectionListener(this);
            treeManager = new TreeManager(this);
     
            add(buttons);
            add(toolBar);
            add(tree);
            initMenu();
     
            loadTreeData(groups, users, null);
            currentProject = new LevelPackProjectFile(null, this);
        }
     
        public void loadTreeData(String[] groups, String[][] users, String[] files){
            Hashtable root = new Hashtable();
            Hashtable hash = new Hashtable();
            for (int i = 0; i < groups.length; i++) {
                hash.put(groups[i], users[i]);
            }
     
            root.put("ROOT : LEVELS", hash);
            if (files != null){
                root.put("ROOT : FILES", files);
            }
     
            remove(tree);
            tree = new JTree(root);
            tree.setBounds(1030, 32, getWidth() - 256, 700);
            tree.addTreeSelectionListener(this);
            add(tree);
            repaint();
        }
     
        public int getScreenWidth(){
            Toolkit toolKit = this.getToolkit();
            return toolKit.getScreenSize().width;
        }
     
        public int getScreenHeight(){
            Toolkit toolKit = this.getToolkit();
            return toolKit.getScreenSize().height;
        }
     
        /**
         * Function used to create the user menu bar
         */
        private void initMenu(){
            menu = new JMenuBar();
     
            // The three menus (file, level and ?)
            JMenu file = new JMenu(" --> File <-- ");
            JMenu level = new JMenu(" --> Project <-- ");
            JMenu help = new JMenu(" --> ? <-- ");
     
            // The items of these menus
            JMenuItem saveProject = new JMenuItem("Save Project");
            JMenuItem generateLevel = new JMenuItem("Generate Level");
            JMenuItem openProject = new JMenuItem("Open Project");
            JMenuItem newLevel = new JMenuItem("New");
            JMenuItem newLevelFile = new JMenuItem("New Level");
            JMenuItem levelModify = new JMenuItem("Project Settings");
            JMenuItem helpItem = new JMenuItem("Help");
            JMenuItem conveniently = new JMenuItem("Conveniently");
            JMenuItem registerKey = new JMenuItem("Unlock BrickBroken Level Editor");
            JMenuItem closeMenuItem = new JMenuItem("Close");
     
            // Adding items for file menu
            file.add(newLevel);
            file.add(saveProject);
            file.add(openProject);
            file.add(generateLevel);
            file.add(closeMenuItem);
     
            // Adding items for level menu
            level.add(levelModify);
            level.add(newLevelFile);
     
            //Adding items for ? menu
            help.add(helpItem);
            help.add(conveniently);
            help.add(registerKey);
     
            // The Actions Listeners for all menu items
            ActionListener close = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    remove(panel);
                    panel.repaint();
                    repaint();
                }
            };
            closeMenuItem.addActionListener(close);
     
            ActionListener newLF = new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    new NewLevelDialog(EditorFrame.this);
                }
            };
            newLevelFile.addActionListener(newLF);
     
            ActionListener newProject = new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    if (panel != null){
                        remove(panel);
                        panel = null;
                    }
                    loadTreeData(groups, users, null);
                }
            };
            newLevel.addActionListener(newProject);
     
            ActionListener generate = new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    JFileChooser chooser = new JFileChooser(".");
                    LevelPackFileFilter lvlProject = new LevelPackFileFilter(
                            "Brick Broken Level File (.lvl)", ".lvl");
                    chooser.addChoosableFileFilter(lvlProject);
                    chooser.setAcceptAllFileFilterUsed(false);
                    chooser.setDialogTitle("Save this level project");
                    // chooser.setResizable(false);
                    chooser.setCurrentDirectory(new File("/"));
                    chooser.changeToParentDirectory();
                    int returnVal = chooser.showSaveDialog(EditorFrame.this);
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        System.out.println("You chose to open this file : " + chooser.getSelectedFile().getPath());
                        //new LevelCreatorSystem(levelName, levelID, panel.getBrickEntrys(), chooser.getSelectedFile().getPath() + ".lvl");
                        javax.swing.JOptionPane.showMessageDialog(EditorFrame.this,"Level Generated !", "BrickBroken Level Editor", JOptionPane.INFORMATION_MESSAGE);
                    }
     
                }
            };
            generateLevel.addActionListener(generate);
     
            ActionListener save = new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    JFileChooser chooser = new JFileChooser(".");
                    LevelPackFileFilter lvlProject = new LevelPackFileFilter(
                            "BrickBroken Project File (.bbp)", ".bbp");
                    chooser.addChoosableFileFilter(lvlProject);
                    chooser.setAcceptAllFileFilterUsed(false);
                    chooser.setDialogTitle("Save this level project");
                    // chooser.setResizable(false);
                    chooser.setCurrentDirectory(new File("/"));
                    chooser.changeToParentDirectory();
                    int returnVal = chooser.showSaveDialog(EditorFrame.this);
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        System.out.println("You chose to open this file : " + chooser.getSelectedFile().getPath());
                        if (chooser.getSelectedFile().getName().endsWith(".bbp")) {
                            currentProject.saveProject(new File(chooser.getSelectedFile().getPath()));
                            currentProject.projectFile = new File(chooser.getSelectedFile().getPath());
                            javax.swing.JOptionPane.showMessageDialog(EditorFrame.this,"Project Saved !", "BrickBroken Level Editor", JOptionPane.INFORMATION_MESSAGE);
                        } else {
                            currentProject.saveProject(new File(chooser.getSelectedFile().getPath() + ".bbp"));
                            currentProject.projectFile = new File(chooser.getSelectedFile().getPath() + ".bbp");
                            javax.swing.JOptionPane.showMessageDialog(EditorFrame.this,"Project Saved !", "BrickBroken Level Editor", JOptionPane.INFORMATION_MESSAGE);
                        }
                    }
                }
            };
            saveProject.addActionListener(save);
     
            ActionListener open = new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    JFileChooser chooser = new JFileChooser(".");
                    LevelPackFileFilter lvlProject = new LevelPackFileFilter(
                            "BrickBroken Project File (.bbp)", ".bbp");
                    chooser.addChoosableFileFilter(lvlProject);
                    chooser.setAcceptAllFileFilterUsed(false);
                    chooser.setDialogTitle("Open a level project");
                    // chooser.setResizable(false);
                    chooser.setCurrentDirectory(new File("/"));
                    chooser.changeToParentDirectory();
                    int returnVal = chooser.showOpenDialog(EditorFrame.this);
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        if (chooser.getSelectedFile().getName().endsWith(".bbp")){
                            System.out.println("You chose to open this file: " + chooser.getSelectedFile().getPath());
                            currentProject = new LevelPackProjectFile(new File(chooser.getSelectedFile().getAbsolutePath()), EditorFrame.this);
                            levelName = currentProject.name;
                            currentProject.loadProject();
                            //levelID = file.getCurrentLevelId();
                            if (panel != null){
                                remove(panel);
                                panel = null;
                            }
                            //panel = new EditorPanel(file, buttons, toolBar, EditorFrame.this);
                            //add(panel);
                            //panel.repaint();
                            setTitle("BrickBroken - Level Creator/Editor [" + levelName + "]");
                        } else {
                            try {
                                JOptionPane.showMessageDialog(EditorFrame.this, "Not a valid BrickBroken - LevelEditor Project File", "LevelEditor", JOptionPane.ERROR_MESSAGE);
                                throw new IOException("Invalid File");
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            };
            openProject.addActionListener(open);
     
            ActionListener modify = new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    new EditLevelPack(EditorFrame.this).setVisible(true);
                }
            };
            levelModify.addActionListener(modify);
     
            ActionListener conv = new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    javax.swing.JOptionPane.showMessageDialog(EditorFrame.this,"BrickBroken Level Editor Official Software.\nCopyright \u00A92013, All Rights Reserved.", "BrickBroken Level Editor", JOptionPane.INFORMATION_MESSAGE);
                }
            };
            conveniently.addActionListener(conv);
     
            // Adding menus to the main user menu bar
            menu.add(file);
            menu.add(level);
            menu.add(help);
     
            // Adding the main menu bar to the current frame
            setJMenuBar(menu);
        }
     
        public static File getGameDir() {
            return getAppDir("brickBroken");
        }
     
        public static File getAppDir(String par0Str) {
            String s = System.getProperty("user.home", ".");
            File file;
     
            switch (EnumOSMappingHelper.enumOSMappingArray[getOS().ordinal()]) {
                case 1:
                case 2:
                    file = new File(s, (new StringBuilder()).append('.')
                            .append(par0Str).append('/').toString());
                    break;
     
                case 3:
                    String s1 = System.getenv("APPDATA");
     
                    if (s1 != null) {
                        file = new File(s1, (new StringBuilder()).append(".")
                                .append(par0Str).append('/').toString());
                    } else {
                        file = new File(s, (new StringBuilder()).append('.')
                                .append(par0Str).append('/').toString());
                    }
     
                    break;
     
                case 4:
                    file = new File(s, (new StringBuilder())
                            .append("Library/Application Support/").append(par0Str)
                            .toString());
                    break;
     
                default:
                    file = new File(s, (new StringBuilder()).append(par0Str)
                            .append('/').toString());
                    break;
            }
     
            if (!file.exists() && !file.mkdirs()) {
                throw new RuntimeException((new StringBuilder())
                        .append("The working directory could not be created: ")
                        .append(file).toString());
            } else {
                return file;
            }
        }
     
        public static EnumOS2 getOS() {
            String s = System.getProperty("os.name").toLowerCase();
     
            if (s.contains("win")) {
                return EnumOS2.windows;
            }
     
            if (s.contains("mac")) {
                return EnumOS2.macos;
            }
     
            if (s.contains("solaris")) {
                return EnumOS2.solaris;
            }
     
            if (s.contains("sunos")) {
                return EnumOS2.solaris;
            }
     
            if (s.contains("linux")) {
                return EnumOS2.linux;
            }
     
            if (s.contains("unix")) {
                return EnumOS2.linux;
            } else {
                return EnumOS2.unknown;
            }
        }
     
        public static void main(String[] args) {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (Exception ignored) {
            }
            new EditorFrame().setVisible(true);
        }
     
        private String previousFile;
     
        private void savePreviousFile(){
            boolean save = false;
            switch(EnumSupportedFileTypes.getEnumFromExtention(previousFile)){
                case DATA_FILE:
                    save = false;
                    break;
                case LEVEL_FILE:
                    save = true;
                    break;
                case PNG_FILE:
                    save = false;
                    break;
                case UNKNOWN:
                    save = false;
                    break;
     
            }
     
            if (save){
                File f = new File(currentProject.projectFile.getParent() + File.separator + "content" + File.separator);
                if (!f.exists()){
                    f.mkdirs();
                }
                if (previousFile != null && panel != null){
                    panel.onClosingFile(previousFile, currentProject);
                }
            }
        }
     
        private void openPanel(EditorPanel panel, Object file){
            if (this.panel != null){
                remove(this.panel);
                this.panel = null;
            }
            //BrickBrokenLevelFile var = new BrickBrokenLevelFile(currentProject.projectFile.getParent() + File.separator + "content" + File.separator + file);
            //panel = new LevelEditor(buttons, toolBar, this);
            this.panel = panel;
            panel.loadFile(file);
            add(panel);
            repaint();
        }
     
        public void valueChanged(TreeSelectionEvent e) {
            Object[] ss = e.getPath().getPath();
            System.out.println("--TREE_SELECTED_DIRECTORY_CHANGE--");
            String file = ss[ss.length - 1].toString();
            switch(EnumSupportedFileTypes.getEnumFromExtention(file)){
                case DATA_FILE:
                    savePreviousFile();
                    previousFile = file;
                    openPanel(new DataEditor(buttons, toolBar, this), new BrickBrokenDataFile(new File(currentProject.projectFile.getParent() + File.separator + "content" + File.separator + file), true));
                    break;
                case LEVEL_FILE:
                    savePreviousFile();
                    previousFile = file;
                    openPanel(new LevelEditor(buttons, toolBar, this), new BrickBrokenLevelFile(currentProject.projectFile.getParent() + File.separator + "content" + File.separator + file));
                    break;
                case PNG_FILE:
                    savePreviousFile();
                    previousFile = file;
                    break;
                case SCRIPT_FILE:
                    savePreviousFile();
                    previousFile = file;
                    break;
                case UNKNOWN:
                    savePreviousFile();
                    if (panel != null){
                        remove(panel);
                        panel = null;
                        repaint();
                    }
                   break;
            }
            for (Object s : ss){
                System.out.println(s);
            }
            System.out.println("--END--");
            repaint();
        }
     
        /**
        public void paint(Graphics g) {
            validate();
            buttons.repaint();
            panel.repaint();
            menu.repaint();
            toolBar.repaint();
            tree.repaint();
        }
         */
    }

    EditorPanel (this class represents an editing panel, currently there are level editor panel and data editor panel)
    package fr.brickbroken.levelEdit.panel;
     
    import fr.brickbroken.format.project.LevelPackProjectFile;
    import fr.brickbroken.levelEdit.EditorFrame;
     
    import java.awt.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
     
    import javax.swing.JPanel;
     
    public abstract class EditorPanel extends JPanel implements MouseListener,
            MouseMotionListener {
     
        public EditorPanel(ButtonsPanel ctrl, ToolBar bar, EditorFrame frame) {
            setBounds(0, 0, 1030, 700);
            setBackground(Color.CYAN);
            addMouseListener(this);
            addMouseMotionListener(this);
        }
     
        public void onUserLeftClick(int x, int y){
     
        }
     
        public void onUserRightClick(int x, int y){
     
        }
     
        public void renderEditor(Graphics g){
     
        }
     
        public void mouseMoved(int x, int y){
     
        }
     
        public Dimension getMaximumSize() {
            return new Dimension(1030, 700);
        }
     
        public Dimension getMinimumSize() {
            return new Dimension(1030, 700);
        }
     
        public Dimension getPreferredSize(){
            return new Dimension(1030, 700);
        }
     
        public void paintComponent(Graphics g) {
            renderEditor(g);
        }
     
        public void mouseClicked(MouseEvent arg0) {
            if (arg0.getButton() == MouseEvent.BUTTON1) {
                onUserLeftClick(arg0.getX(), arg0.getY());
            } else if (arg0.getButton() == MouseEvent.BUTTON2){
                onUserRightClick(arg0.getX(), arg0.getY());
            }
        }
     
        public void onClosingFile(String previousFile, LevelPackProjectFile currentProject){
        }
     
        public void loadFile(Object file){
        }
     
        public void mouseEntered(MouseEvent arg0) {}
     
        public void mouseExited(MouseEvent arg0) {}
     
        public void mousePressed(MouseEvent arg0) {}
     
        public void mouseReleased(MouseEvent arg0) {}
     
        public void mouseDragged(MouseEvent arg0) {}
     
        public void mouseMoved(MouseEvent arg0) {
            mouseMoved(arg0.getX(), arg0.getY());
        }
    }

    LevelEditor (The level editing panel)
    package fr.brickbroken.levelEdit.panel;
     
    import fr.brickbroken.format.project.BrickBrokenLevelFile;
    import fr.brickbroken.format.project.LevelCreatorSystem;
    import fr.brickbroken.format.project.LevelPackProjectFile;
    import fr.brickbroken.levelEdit.*;
    import fr.brickbroken.levelEdit.dialog.PresisionDialog;
    import fr.brickbroken.levelEdit.entry.Brick;
    import fr.brickbroken.levelEdit.entry.BrickEntry;
    import fr.brickbroken.levelEdit.entry.PrecisionLineEntry;
     
    import javax.imageio.ImageIO;
    import java.awt.*;
    import java.io.File;
    import java.io.IOException;
     
    public class LevelEditor extends EditorPanel {
     
        private BrickEntry[] bricksMap;
        private PrecisionLineEntry[] precisionLinesMap;
        private int brickSize = 0;
        private int brickWidth = 100;
        private int brickHeight = 50;
        private ButtonsPanel control;
     
        private EditorFrame editorFrame;
     
        public ToolBar softwareToolBar;
        public boolean hasPresisionTool = false;
        public boolean hasRemoverTool = false;
        public boolean hasPlacerTool = false;
        public boolean hasMoverTool = false;
     
        private int mouseX;
        private int mouseY;
     
        public LevelEditor(ButtonsPanel ctrl, ToolBar bar, EditorFrame frame) {
            super(ctrl, bar, frame);
            bricksMap = new BrickEntry[100];
            precisionLinesMap = new PrecisionLineEntry[8];
            control = ctrl;
            softwareToolBar = bar;
            bar.setEditorPanel(this);
            editorFrame = frame;
        }
     
        public void loadFile(Object file){
            BrickBrokenLevelFile data = (BrickBrokenLevelFile) file;
            importFromExistantProject(data);
        }
     
        public void onUserLeftClick(int x, int y){
            if (hasPresisionTool){
                for (int i = bricksMap.length - 1; i >= 0; i--) {
                    if (bricksMap[i] != null) {
                        int width;
                        int height;
                        if (bricksMap[i].getRenderType() == 0) {
                            width = brickWidth;
                            height = brickHeight;
                        } else {
                            width = 50;
                            height = 100;
                        }
                        if ((x >= bricksMap[i].getCoordX())
                                && ((x <= (bricksMap[i].getCoordX() + width)))) {
                            if ((y >= bricksMap[i].getCoordY())
                                    && (y <= (bricksMap[i].getCoordY() + height))) {
                                if ((y > bricksMap[i].getCoordY())
                                        && (y < (bricksMap[i].getCoordY() + height))) {
                                    new PresisionDialog(this, i, editorFrame).setVisible(true);
                                    repaint();
                                    hasPresisionTool = false;
                                    softwareToolBar.setStatus("Ready");
                                    return;
                                } else {
                                    new PresisionDialog(this, i, editorFrame).setVisible(true);
                                    repaint();
                                    hasPresisionTool = false;
                                    softwareToolBar.setStatus("Ready");
                                    return;
                                }
                            }
                        }
                    }
                }
            }
     
            if (hasPlacerTool){
                if (brickSize == 99) {
                    return;
                }
                bricksMap[brickSize + 1] = new BrickEntry(x, y, control.choosedBrick, control.choosedRender);
                System.out.println("Added Brick at coords : x=" + x + ", y=" + y);
                brickSize++;
                repaint();
            }
     
            if (hasRemoverTool){
                for (int i = bricksMap.length - 1; i >= 0; i--) {
                    if (bricksMap[i] != null) {
                        int width;
                        int height;
                        if (bricksMap[i].getRenderType() == 0) {
                            width = brickWidth;
                            height = brickHeight;
                        } else {
                            width = 50;
                            height = 100;
                        }
                        if ((x >= bricksMap[i].getCoordX())
                                && ((x <= (bricksMap[i].getCoordX() + width)))) {
                            if ((y >= bricksMap[i].getCoordY())
                                    && (y <= (bricksMap[i].getCoordY() + height))) {
                                if ((y > bricksMap[i].getCoordY())
                                        && (y < (bricksMap[i].getCoordY() + height))) {
                                    bricksMap[i] = null;
                                    brickSize--;
                                    repaint();
                                } else {
                                    bricksMap[i] = null;
                                    brickSize--;
                                    repaint();
                                }
                            }
                        }
                    }
                }
            }
     
            if (hasMoverTool){
                if (softwareToolBar.status0.getText().contains("Click on another place to move brick")){
                    if (brickSize == 99) {
                        return;
                    }
                    bricksMap[brickSize + 1] = new BrickEntry(x, y, control.choosedBrick, control.choosedRender);
                    System.out.println("Brick Moved");
                    brickSize++;
                    repaint();
                    softwareToolBar.setStatus("Ready");
                    hasMoverTool = false;
                    return;
                }
                for (int i = bricksMap.length - 1; i >= 0; i--) {
                    if (bricksMap[i] != null) {
                        int width;
                        int height;
                        if (bricksMap[i].getRenderType() == 0) {
                            width = brickWidth;
                            height = brickHeight;
                        } else {
                            width = 50;
                            height = 100;
                        }
                        if ((x >= bricksMap[i].getCoordX()) && ((x <= (bricksMap[i].getCoordX() + width)))) {
                            if ((y >= bricksMap[i].getCoordY()) && (y <= (bricksMap[i].getCoordY() + height))) {
                                if ((y > bricksMap[i].getCoordY()) && (y < (bricksMap[i].getCoordY() + height))) {
                                    bricksMap[i] = null;
                                    brickSize--;
                                    repaint();
                                    softwareToolBar.setStatus("Using Mover Tool : Click on another place to move brick");
                                } else {
                                    bricksMap[i] = null;
                                    brickSize--;
                                    repaint();
                                    softwareToolBar.setStatus("Using Mover Tool : Click on another place to move brick");
                                }
                            }
                        }
                    }
                }
            }
        }
     
        public BrickEntry[] getBrickEntrys() {
            return bricksMap;
        }
     
        public void onUserRightClick(int x, int y){
     
        }
     
        public void renderEditor(Graphics g){
            g.setColor(new Color(188, 188, 188));
            g.fillRect(0, 0, getWidth(), getHeight());
            g.setColor(Color.BLACK);
            for (int y = 0; y <= getHeight(); y += 30) {
                for (int x = 0; x <= getWidth(); x += 30) {
                    g.fillRect(x, y, 5, 5);
                }
            }
            for (BrickEntry aBricksMap : bricksMap) {
                if (aBricksMap != null) {
                    Brick brick = Brick.ById[aBricksMap.getId()];
                    if (brick.hasTexture) {
                        try {
                            if (aBricksMap.getRenderType() == 0){
                                g.drawImage(ImageIO.read(new File(brick.texturePath)), aBricksMap.getCoordX(), aBricksMap.getCoordY(), brickWidth, brickHeight, null);
                            } else {
                                g.drawImage(ImageIO.read(new File(brick.texturePath)), aBricksMap.getCoordX(), aBricksMap.getCoordY(), brickHeight, brickWidth, null);
                            }
                            continue;
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                    g.setColor(brick.brickColor);
                    if (aBricksMap.getRenderType() == 0){
                        g.fillRect(aBricksMap.getCoordX(), aBricksMap.getCoordY(), brickWidth, brickHeight);
                    } else {
                        g.fillRect(aBricksMap.getCoordX(), aBricksMap.getCoordY(), brickHeight, brickWidth);
                    }
                }
            }
            for (PrecisionLineEntry entry : precisionLinesMap){
                if (entry != null){
                    if (entry.getOrientation() == 0){
                        g.drawLine(0, entry.getCoordY(), getWidth(), 4);
                    } else if (entry.getOrientation() == 1){
                        g.drawLine(entry.getCoordY(), 0, 4, getHeight());
                    }
                }
            }
            if (hasPlacerTool){
                if (control.choosedRender == 0){
                    g.setColor(new Color(0, 130, 181, 91));
                    g.fillRect(mouseX, mouseY, 100, 50);
                } else {
                    g.setColor(new Color(0, 130, 181, 91));
                    g.fillRect(mouseX, mouseY, 50, 100);
                }
            }
            repaint();
        }
     
        public void onClosingFile(String previousFile, LevelPackProjectFile currentProject){
            new LevelCreatorSystem(previousFile.split(".lvl")[0], 255, getBrickEntrys(), currentProject.projectFile.getParent() + File.separator + "content" + File.separator + previousFile);
        }
     
        private void importFromExistantProject(BrickBrokenLevelFile level) {
            if (level.getCurrentLevelBricksId() == null){
                return;
            }
            for (int i = 0; i < level.getCurrentLevelBricksId().size(); i++) {
                bricksMap[i] = new BrickEntry(level.getCurrentLevelBricksAxisX()
                        .get(i), level.getCurrentLevelBricksAxisY().get(i), level
                        .getCurrentLevelBricksId().get(i), level.getBricksRenderMap().get(i));
                brickSize++;
            }
        }
     
        public void mouseMoved(int x, int y){
            mouseX = x;
            mouseY = y;
        }
    }

    And at least the data editor (DataEditor) panel (wich is not showing until you reduce reopen window)
    package fr.brickbroken.levelEdit.panel;
     
    import fr.brickbroken.format.BrickBrokenDataFile;
    import fr.brickbroken.format.project.LevelPackProjectFile;
    import fr.brickbroken.levelEdit.EditorFrame;
     
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Map;
     
    public class DataEditor extends EditorPanel {
     
        private BrickBrokenDataFile dataFile;
        private Map<String, String> fileContent;
     
        private EditorFrame frame;
     
        private JPanel panel;
     
        private List<JTextField> keys;
        private List<JTextField> values;
     
        public DataEditor(ButtonsPanel ctrl, ToolBar bar, EditorFrame frame) {
            super(ctrl, bar, frame);
            setLayout(null);
            panel = new JPanel();
            panel.setLayout(new FlowLayout(FlowLayout.CENTER, 8, 16));
            panel.setBounds(0, 0, getWidth(), getHeight());
            this.frame = frame;
        }
     
        public void onUserLeftClick(int x, int y){
        }
     
        public void onUserRightClick(int x, int y){
        }
     
        public void mouseMoved(int x, int y){
        }
     
        public void loadFile(Object file){
            dataFile = (BrickBrokenDataFile) file;
            if (dataFile.isReady){
                fileContent = dataFile.getData();
            }
            initPanel();
            panel.repaint();
            add(panel);
            frame.validate();
        }
     
        private void initPanel(){
            if (fileContent != null){
                keys = new ArrayList<JTextField>();
                values = new ArrayList<JTextField>();
                for (Map.Entry<String, String> entry : fileContent.entrySet()){
                    JTextField k = new JTextField(entry.getKey());
                    JTextField v = new JTextField(entry.getValue());
                    keys.add(k);
                    values.add(v);
                    JPanel layout = new JPanel();
                    layout.add(k);
                    layout.add(v);
                    panel.add(layout);
                    frame.validate();
                }
            }
     
            JButton add = new JButton("Add Key to file");
     
            ActionListener addEvent = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    JTextField k = new JTextField();
                    JTextField v = new JTextField();
                    keys.add(k);
                    values.add(v);
                    JPanel layout = new JPanel();
                    layout.add(k);
                    layout.add(v);
                    panel.add(layout);
                    frame.validate();
                }
            };
            add.addActionListener(addEvent);
     
            panel.add(add);
        }
     
        public void onClosingFile(String previousFile, LevelPackProjectFile currentProject){
            BrickBrokenDataFile dataFile = new BrickBrokenDataFile(new File(currentProject.projectFile.getParent() + File.separator + "content" + File.separator + previousFile), false);
            if (keys != null){
                for (int i = 0 ; i < keys.size() ; i++){
                    String key = keys.get(i).getText();
                    String value = values.get(i).getText();
                    dataFile.addKeyValue(key, value);
                    remove(keys.get(i));
                    remove(values.get(i));
                }
                keys.clear();
                values.clear();
            }
            dataFile.isReady = true;
            dataFile.saveData();
        }
    }

    Hope you can help me ! Befor i let you go, i have something to add : when i was searching for the problem solution, i found that it's possibly linked to the setLayout(null) line of code that i'm using !
    For answer why i can't change layout, it's because an EditorPanel has a completely fixed size, if the panel is more larger, it will exceed the game format reader matrices ! So EditorPanels must have the fixed size of 1030 x 700, and no layouts are conservating original sizes !


    Now i can let you think about all that code,

    Thanks by advance,
    Yuri6037


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Hi to all and gui problem !

    The AccessViolation error is not that uncommon when trying to access system areas from a Java program. It could be simply due to the fact that the process or user doesn't have access to that resource. Or, it could be JVM error that might be more complicated. It would be helpful if you'd post the whole error so that we can get more info from it.

    As for the odd GUI behaviors you've experienced, I don't believe those are caused by using a null layout. However, your reason for using null layout don't make sense and could likely be resolved some other way. I think the odd behavior is being caused by something being done in Swing incorrectly. Components that do not appear correctly or only update after resizing/opening/closing their containers suggest the application doesn't do custom painting correctly, including which components are being painted on, proper use of the paintComponent() and repaint() methods, etc.

    Sorry to be vague, but since I can't run or currently see all of the code and how it works together, it's hard to say. Again, if you are getting any error messages when the odd behavior occurs, post them in their entirety.

    Nice to meet you and good luck!

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hi to all and gui problem !

    About Access Violation problem, when i use any software that is newer, it returns same when trying access to the hard disk G:. It's normal because it's a very very old hard disk who is installed in a very very recent hardware ! This old hard disk is containing all the developpement sources and multimedia games ressources ; it's a 32 IDE hard disk ; so it's normal !

    About the code, what code do you want ? Only code that i will not give you are BrickBrokenData File code and other file format code, but i can give you all you want about Gui !
    So tell me what you need...
    And at least can you explain how i can implement the EditorPanel with a non setLayout(null) ? Because my Mappor (person who creates maps) feel better in Full window apps...

  4. #4
    Junior Member
    Join Date
    Jan 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hi to all and gui problem !

    Nobody can help ? Ask me what you need about the code... I can give you all gui code if needed...

    Please tell me what class you need...

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Hi to all and gui problem !

    Remind us of the question. You said the Access Violation was a known issue (so why did you mention it?) Not sure what you need help with, so please clarify.

  6. #6
    Junior Member
    Join Date
    Jan 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hi to all and gui problem !

    Like I said I need solutions for the components not showing correctly...

    I mentioned the access violation because I just wanted to know if some of you has a solution about that...
    I wanna add too that FRAPS, JetBrains IntelliJ and Microsoft Office are the only programm who can access successfully to the hard disk.

    But before access violation problem, I really need to solve panel not displaying components that are in FlowLayout and Why flow layouts components are not displayed one under one ?

  7. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Hi to all and gui problem !

    Please point to the code that adds components that are not showing as you'd like them to. Describe what's happening in that container with those components and then describe what you'd like to have happen instead.

Similar Threads

  1. GUI Problem
    By ineedahero in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 29th, 2013, 09:30 PM
  2. GUI problem
    By Techstudent in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 24th, 2013, 07:17 AM
  3. GUI problem
    By Fantasy in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 21st, 2011, 09:09 PM
  4. GUI problem
    By Reem in forum AWT / Java Swing
    Replies: 6
    Last Post: November 15th, 2010, 09:45 AM
  5. GUI Problem
    By bulldog in forum AWT / Java Swing
    Replies: 1
    Last Post: December 11th, 2009, 01:47 PM