I'm trying to make a level that can be edited in game for a pong-like game.
So far, this is what I have:

import java.awt.*;
import java.applet.*;

public class LevelEditor extends Board
{
public static final String row1  = "::::gggggggggggggggggg";
public static       String row2  = "::::g::::::::::::::::g";
public static       String row3  = "::::::::::::::::::::::";
public static       String row4  = "::::::::::::::::::::::";
public static       String row5  = "::::::::::::::::::::::";
public static       String row6  = "::::::::::::::::::::::";
public static       String row7  = "::::::::::::::::::::::";
public static       String row8  = "::::::::::::::::::::::";
public static       String row9  = "::::g::::::::::::::::g";
public static final String row10 = "::::gggggggggggggggggg";
String name = "YOUR LEVEL";
String[] definitions = {row1, row2, row3, row4, row5, row6, row7, row8, row9, row10};
    public LevelEditor(Component parent, Applet applet)
    {
        super(parent, applet);
        super.initializeBoard(definitions);
        super.setDefinitions(definitions);
        super.setName(name);
    }
    public void resetLevel(String [] definitions)
    {
        super.initializeBoard(definitions);
        super.setDefinitions(definitions);
        super.setName(name);
    }
}

And in the Board class, the parts you might need to know:

import java.applet.*;
import java.awt.*;

public abstract class Board
{
private Elements elementArray [][];
private Component parent;
private Applet applet;
private String[] definitions;
private String name;
    public Board(Component parent, Applet applet)
    {
        this.parent = parent;
        this.applet = applet;
    }
    public void setDefinitions(String [] definitions)
    {
        this.definitions = definitions;
    }
    public void setName(String name)
    {
        this.name = name;
    }
    public void initializeBoard(String [] definitions)
    {
        elementArray = new Elements[StaticPong.NUMBEROFLINES][StaticPong.NUMBEROFCOLUMNS];
        for (int j=0; j<StaticPong.NUMBEROFLINES; j++) {
            char [] elements = definitions[j].toCharArray();
            for (int i=0; i<StaticPong.NUMBEROFCOLUMNS; i++) {
                if (elements[i] == ':') {
                    elementArray[j][i] = null;
                }
                else if (elements[i] == 'g') {
                    Walls element = new Walls(Color.black, 1);
                    elementArray[j][i] = element;
                }
                else if (elements[i] == 'p') {
                    BWalls element = new BWalls(Color.blue, 2);
                    elementArray[j][i] = element;
                }
                else if (elements[i] == 'e') {
                    EWalls element = new EWalls(Color.red, 3);
                    elementArray[j][i] = element;
                }
                else if (elements[i] == 'i') {
                    Walls element = new Walls(Color.gray, 1);
                    elementArray[j][i] = element;
                }
                else if (elements[i] == 'm') {
                    MWalls element = new MWalls(Color.yellow, 4, 3);
                    elementArray[j][i] = element;
                }
                else if (elements[i] == '-') {
                    Path element = new Path(Color.gray, 5);
                    elementArray[j][i] = element;
                }
            }
        }
    }
    public void editLevel(int x, int y)
    {
        int row = x/StaticPong.NUMBEROFCOLUMNS;
        int col = y/StaticPong.NUMBEROFLINES;
        if (row!=1 && row!=10) {
            char[] line = definitions[row].toCharArray();
            if (line[col] == ':') {
                line[col] = 'g';
            }
            else if (line[col] == 'g') {
                line[col] = 'p';
            }
            else if (line[col] == 'p') {
                line[col] = 'e';
            }
            else if (line[col] == 'e') {
                line[col] = ':';
            }
            definitions[row] = line.toString();
        }
        resetLevel(definitions);
    }

The editlevel method is called in Board when you click on a grid box in "leveleditor" mode (a gamestate).
This should change the row/col that you clicked on to a different element, but the applet freezes when you click on something.

Any help making the editor work?

Try debugging !
Code isn't complete ? where is StaticPong?
Do simple step by step debugging using some debugger like Eclipse. Put a break point in the handler.
Otherwise do it old style, put some traces in your handler function and the editxx() function to see where it is hung.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.