Hi all.
I'm trying to use Java to make a map designer for a tabletop rpg. So far, its going fairly well, but I've got one big problem: When I display the map, if I manipulate the image box (make it bigger/smaller), it re-runs the entire program, including the methods that built the map in the first place- meaning that the entire map changes completly.
Code:
import java.awt.*;
class GraphicsProgram extends Canvas{
public GraphicsProgram(){
setSize(200, 200);
setBackground(Color.white);
}
public static void main(String[] argS){
//GraphicsProgram class is now a type of canvas
//since it extends the Canvas class
//lets instantiate it
GraphicsProgram GP = new GraphicsProgram();
//create a new frame to which we will add a canvas
Frame aFrame = new Frame();
aFrame.setSize(1000, 1000);
//add the canvas
aFrame.add(GP);
aFrame.setVisible(true);
}
public void paint(Graphics g)
{
map1 test = new map1();
test.make1();
test.setElevation(1);
g.setColor(Color.blue);
g.drawLine(30, 30, 80, 80);
g.drawRect(20, 150, 100, 100);
g.fillRect(20, 150, 100, 100);
g.fillOval(150, 20, 100, 100);
{
for(int i = 0; i < 99; i++)
{
for(int i2 = 0; i2 < 99; i2++)
{
int [] temp =test.cellArray[i][i2].getCol();
g.setColor(new Color(temp[0], temp[1], temp[2]));
g.fillRect((i*10), (i2*10), 10, 10);
}
}
}
}
}
So it runs the bolded section everytime it redraws the image. Is there a different way of doing images so it avoids this?