I have a picture(a map) drawn to a panel using a BufferedImage and I want to draw circle on different parts of the map. I'm using a Graphics object to draw the circles onto the map but everytime I call the repaint function, everything I've drawn on the map disappears. Really need help with this. The following functions are the functions that draws the map unto the panel and the function that draws the images unto the map. Am I doing something wrong here??? -
-
public void loadBImage(){
-
bImage = new BufferedImage(image.getWidth(null), image.getHeight(null),
-
BufferedImage.TYPE_INT_RGB);
-
bImage2 = new BufferedImage(image.getWidth(null), image.getHeight(null),
-
BufferedImage.TYPE_INT_RGB);
-
Graphics bImageG = bImage.getGraphics();
-
Graphics bImage2 = bImage.getGraphics();
-
bImageG.drawImage(image, 0,0,null, null);
-
bImage2.drawImage(image, 0,0,null, null);
-
}
-
-
public void drawCard(int ax, int ay){
-
Graphics g = this.getGraphics();
-
g.setColor(new Color(150, 150, 150));
-
g.fillRect(ax, ay, 10, 10);
-
}
-
-
public void drawArmy(Country country, Player player){
-
country = currentCountry;
-
int xLoc = country.getXLoc();
-
int yLoc = country.getYLoc();
-
if (xLoc == 0){
-
xLoc = x;
-
country.setXLoc(x);
-
}
-
if (yLoc == 0){
-
yLoc = y;
-
country.setYLox(y);
-
}
-
-
int numArmies = country.getNumArmies();
-
char armies = (char)(numArmies + '0');
-
char army[] = {armies};
-
-
Graphics g = this.getGraphics();
-
String color = player.getColor();
-
Color aColor = null;
-
if (color == "Red"){
-
aColor = Color.RED;
-
}
-
else if (color == "Yellow"){
-
aColor = Color.YELLOW;
-
}
-
else if (color == "Blue"){
-
aColor = Color.BLUE;
-
}
-
else if (color == "Green"){
-
aColor = Color.GREEN;
-
}
-
else if (color == "Gray"){
-
aColor = Color.GRAY;
-
}
-
else if (color == "Orange"){
-
aColor = Color.ORANGE;
-
}
-
g.setColor(aColor);
-
g.fillOval(xLoc, yLoc, 10, 10);
-
-
Color black = Color.BLACK;
-
g.setColor(black);
-
g.drawChars(army, 0, 1, xLoc, yLoc);
-
}
-
-
public void paintComponent(Graphics g) {
-
super.paintComponent(g);
-
if (!panelSized) {
-
scaleImage(getWidth(), getHeight());
-
loadBImage();
-
panelSized = true;
-
}
-
g.drawImage(bImage, 0, 0, image.getWidth(null), image.getHeight(null), this);
-
-
}
-
-
0 858 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Tomi Holger Engdahl |
last post by:
I am looking for a solution to add on-line drawing tool
to a phpBB discussion board.
The idea would be that the users can draw their own
simple drawings with the tool and attach them easily
as...
|
by: zengou |
last post by:
My application have many picturebox objects,when run it ,sometimes i will have a strange error,how to work out ,help me please!(in windows98,the error cause frequently than in windowsxp)
...
|
by: funcSter |
last post by:
Hey, got a prob which is driving me nuts!
I'm trying to resize the resolution of an image as well as it's pyhsical byte size.
I've got:
byte bytImage = null;
System.Drawing.Image imgImage =...
|
by: billy |
last post by:
I'm working on a sort of paint program that has the usual canvas pane in the
middle of the main form. I'm working on that class and have a couple quick
questions.. actually more like I'm looking...
|
by: anastasia |
last post by:
I get an out of memory exception when attempting to excecute the
following code:
original = System.Drawing.Image.FromFile(file.FileName,true);
I ONLY get this exception when the file is in the...
| |
by: Marc Pelletier |
last post by:
Hello all,
I have a class which includes a method to create a chart. I want to be able
to call this method from asp.net code as well as windows application code,
so I have sketched it out as...
|
by: George |
last post by:
Dear colleagues,
I refer to your help with specific graphic problem. It is
necessary to create a viewfinder in graphic application.
It seems that the algorithm is simple: just draw lines
in...
|
by: bookon |
last post by:
I was running into the System.Drawing.Image.FromStream "parameter is
not valid" on some of the images I was retrieving from a blob column in
Sql Server. I thought there were corrupt images as...
|
by: ThatsIT.net.au |
last post by:
I have this code that writes a pie chart in a asp.net page, but I want to
use it in a server control.
When I try I get a error on the last line "Response.OutputStream"
Obviously there is no...
|
by: saadkhan |
last post by:
please help me that how could i be able to save images in an array. I have made an array like:
System.Drawing.Image arr = new System.Drawing.Image;
But i have no idea how to save different images...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |