Please help with BufferedImage
hi,
I'm making a space invaders game and need some help with image buffering. I so far have classes for:
ImageHandler - which should handle the loading of images
GameEntities - which contains methods for the ship movements etc
AlienEntitiy - which will draw an alien and have methods for its movement, shooting etc.
SpaceInvaders - which extends Canvas and handles the main game
The problem is that when I create a new alien which has a call to the setImageName(String name) method, which should call the getImage(String imageName) method in ImageHandler, a null pointer exception is thrown.
I have searched my code and can't trace the error (by the way, this is the first ime I've used buffered image). Can someone PLEASE help.
Here's my code:
package InvadersGame;
import java.awt.image.BufferedImage;
import java.io.PrintStream;
import java.util.HashMap;
import javax.imageio.ImageIO;
public class ImageHandler
private HashMap images;
public ImageHandler()
images = new HashMap();
public BufferedImage loadImage(String name)
try
java.net.URL url = null;
url = getClass().getResource(name);
return ImageIO.read(url);
catch(Exception e)
System.exit(0);
System.out.println("image not found");
return null;
public BufferedImage getImage(String name)
BufferedImage image = (BufferedImage)images.get(name);
return image;
public HashMap getImages()
return images;
public void setImages(HashMap val)
images = val;
}and
package InvadersGame;
import java.awt.Graphics;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;
public class GameEntities {
private double x, y;
private int width, height;
private String imageName;
private boolean deletionMark = false;
private SpaceInvaders invaders;
private ImageHandler imageHandler;
public GameEntities(SpaceInvaders invaders)
this.invaders = invaders;
imageHandler = invaders.getImageHandler();
public double getX()
return x;
public double getY()
return y;
public int getWidth()
return width;
public int getHeight()
return height;
public Rectangle getBounds()
return new Rectangle((int)x, (int)y, width, height);
public void setX(int x)
this.x = x;
public void setY(int y)
this.y = y;
public void setWidth(int width)
this.width = width;
public void setHeight(int height)
this.height = height;
public boolean deletionMarked()
return deletionMark;
public void setDeletionMarkedTrue(boolean value)
deletionMark = value;
public String getImageName()
return imageName;
public void setImageName(String name)
imageName = name;
BufferedImage image = imageHandler.getImage(imageName);
height = image.getHeight();
width = image.getWidth();
public boolean collidesWith(GameEntities other)
Rectangle thisEntity = new Rectangle();
Rectangle otherEntity = new Rectangle();
thisEntity.setBounds((int)this.getX(), (int)this.getY(), this.getWidth(), this.getHeight());
otherEntity.setBounds((int)other.getX(),(int)other.getY(), other.getWidth(), other.getHeight());
return thisEntity.intersects(otherEntity);
public void move(){}
public void paint(Graphics2D g)
g.drawImage(imageHandler.getImage(imageName), (int)x, (int)y, invaders);
}and
package InvadersGame;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import java.awt.Graphics2D;
import java.lang.Math;
import java.util.Random;
public class AlienEntity extends GameEntities {
double x, y;
int alienType;
int speedx = 2;
int speedy = 2;
public AlienEntity(SpaceInvaders invaders)
super(invaders);
setImageName("alien4.gif");
public void move()
y = y + speedy;
}and finally..
package InvadersGame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics2D;
import java.awt.geom.*;
import java.util.ArrayList;
import java.util.Random;
import java.awt.image.BufferStrategy;
public class SpaceInvaders extends Canvas{
JPanel panel;
//AlienEntity al, al2;
Graphics2D g2;
boolean gameRunning = true;
ArrayList<GameEntities> entitiesList;
AnimationThread thread;
AlienEntity alien;
private BufferStrategy buffer;
ImageHandler imageHandler;
class AnimationThread extends Thread
public void run()
while(true)
//paintAlien();
try
sleep(50);
catch(InterruptedException e){}
public SpaceInvaders()
super();
imageHandler = new ImageHandler();
JFrame window = new JFrame("Space Invaders");
JPanel panel = (JPanel)window.getContentPane();
setBounds(0, 0, 800, 600);
panel.add(this);
window.setBounds(0, 0, 800, 600);
window.setVisible(true);
window.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
setFocusable(true);
this.createBufferStrategy(2);
buffer = getBufferStrategy();
thread = new AnimationThread();
paintAlien();
public void paintAlien()
Graphics2D g = (Graphics2D)buffer.getDrawGraphics();
g.setColor(Color.black);
g.fillRect(0, 0, getWidth(), getHeight());
alien = new AlienEntity(this);
alien.paint(g);
buffer.show();
public void setBufferstrategy(BufferStrategy buffer)
buffer = buffer;
public ImageHandler getImageHandler()
return imageHandler;
public static void main(String[] args)
SpaceInvaders canvas = new SpaceInvaders();
canvas.thread.start();
}Can someone please take the time an give me some pointers.
Cheers
I've tracked the problem to this bit of the code in the ImageHandler class:
public BufferedImage loadImage(String name)
try
java.net.URL url = null;
url = getClass().getResource(name);
System.out.println(url); //to check whether the image was found
return ImageIO.read(url);
catch(Exception e)
System.exit(0);
System.out.println("image not found");
return null;
For some reason the url = getClass().getResource(name); equals null even though the name I supply as an argument is exactly the same as the file name (alien4.gif).
I'm not too sure whether the problem's with my code or the way netbeans is setup. Can someone please help.
Similar Messages
-
I switched over from an iPhone to a Samsung Galaxy S3 & I haven't been able to receive any text messages from iPhones. I have no problem sending the text messages but I'm not receivng any from iPhones at all. It has been about a week now that I'm having this problem. I've already tried fixing it myself and I also went into the sprint store, they tried everything as well. My last option was to contact Apple directly. Please help with turning my iMessage completely off so that I can receive my texts.
If you registered your iPhone with Apple using a support profile, try going to https://supportprofile.apple.com/MySupportProfile.do and unregistering it. Also, try changing the password associated with the Apple ID that you were using for iMessage.
-
How can I sync my iPhone on a different computer without erasing my applications? My iPhone was earlier synced with a PC which I don't use anymore.
On the new computer, I am getting a message that my all purchases would be deleted if I sync it with new iTunes library.
Please help with proper steps, if any.Also see... these 2 Links...
Recovering your iTunes library from your iPod or iOS device
https://discussions.apple.com/docs/DOC-3991
Syncing to a New Computer...
https://discussions.apple.com/docs/DOC-3141 -
Please help with the message I am receving on startup ""You can't open the application NovamediaDiskSupressor because PowerPC applications are no longer supported."
I have read some of the replies in the Apple Support Communities, but as I am no techie, I would have no idea how I would implement that solution.
Please help with what I need to type, how, where, etc.
Many thanks
AppleSueIn HunterCreekI am afraid there is no solution.
PowerPC refers to the processing chip used by Apple before they transferred to Intel chips. They are very different, and applications written only for PPC Macs cannot work on a Mac running Lion.
You could contact the developers to see if they have an updated version in the pipeline. -
Hi, please help with the installation of Lightroom 4, I bought a new Mac (Apple) and I want to install a software that I have on the album cd. My new computer does not have the drives. Can I download software from Adobe? Is my license number just to be able to download the srtony adobe.
Adobe - Lightroom : For Macintosh
Hal -
[ETL]Could you please help with a problem accessing UML stereotype attributes ?
Hi all,
Could you please help with a problem accessing UML stereotype attributes and their values ?
Here is the description :
-I created a UML model with Papyrus tool and I applied MARTE profile to this UML model.
-Then, I applied <<PaStep>> stereotype to an AcceptEventAction ( which is one of the element that I created in this model ), and set the extOpDemand property of the stereotype to 2.7 with Papyrus.
-Now In the ETL file, I can find the stereotype property of extOpDemand as follows :
s.attribute.selectOne(a|a.name="extOpDemand") , where s is a variable of type Stereotype.
-However I can't access the value 2.7 of the extOpDemand attribute of the <<PaStep>> Stereotype. How do I do that ?
Please help
Thank youHi Dimitris,
Thank you , a minimal example is provided now.
Version of the Epsilon that I am using is : ( Epsilon Core 1.2.0.201408251031 org.eclipse.epsilon.core.feature.feature.group Eclipse.org)
Instructions for reproducing the problem :
1-Run the uml2etl.etl transformation with the supplied launch configuration.
2-Open lqn.model.
There are two folders inside MinimalExample folder, the one which is called MinimalExample has 4 files, model.uml , lqn.model, uml2lqn.etl and MinimalExampleTransformation.launch.
The other folder which is LQN has four files. (.project),LQN.emf,LQN.ecore and untitled.model which is an example model conforming to the LQN metamodel to see how the model looks like.
Thank you
Mana -
Want a complete migration guide to upgrade 11.1.0.7 to 11.2.0.3 database using DBUA..We are implementing R12.1.3 version and then have to migrate the default 11gR1 database to 11.2.0.3 version. Please help with some step by step docs
Upgrade to 11.2.0.3 -- Interoperability Notes Oracle EBS R12 with Oracle Database 11gR2 (11.2.0.3) (Doc ID 1585578.1)
Upgrade to 11.2.0.4 (latest 11gR2 patchset certified with R12) -- Interoperability Notes EBS 12.0 and 12.1 with Database 11gR2 (Doc ID 1058763.1)
Thanks,
Hussein -
Welcome.
At the outset, I'm sorry for my English
Please help with configuration Photoshop CS6 appearance.
How to disable the background of the program so you can see the desktop. (same menus and tools)
i wantto be the same effect as CS5.Please try turning off
Window > Application Frame -
cont contact apple server error please help with ipad touch 4. im just fed up with apple please help me because why is it only apple with these kind of problems?
If you mean updae server
Update Server
Try:
- Powering off and then back on your router.
- iTunes for Windows: iTunes cannot contact the iPhone, iPad, or iPod software update server
- Change the DNS to either Google's or Open DNS servers
Public DNS — Google Developers
OpenDNS IP Addresses
- For one user uninstalling/reinstalling iTunes resolved the problem
- Try on another computer/network
- Wait if it is an Apple problem
Otherwise what server are you talking about -
Purchased DVD in US for Cdn viewing. Digital download will not work in Cda or US? please help with new Digital code that will work
You will need to contact the movie studio that produced the DVD and ask if they can issue you a new code valid for Canada. Apple cannot help you, and everyone here in these forums is just a fellow user.
Regards. -
Please help with slideshow problems!
Am using Photoshop Elements 8 and trying to make a slideshow. Have tried 4 times now and keep ending up with same problem, cannot reopen project to continue edititing. Won't show up in orginizer and when I find on harddrive and try to open get message " wmv file cannot be opened". How can I save a
slideshow inprogress and be able to reopen and continue to edit and make slideshow? I want to thank anyone who can help me with this in advance as I
have gotten so frustrated that I want to just scream.
ThanksThanks for the help, thought I had done so but maybe not. Anyway will have another go at it, now may I ask another
question? I am trying to add audio to slideshow. I have some music I purchased thru amazon as mp3 files but I get
message no codec and when I try to add wmv I get same message. What type of file do I need and how can I add
multiple songs to one slideshow. I have one little wmv file that will go in, but it just replicates itself multiple times until
it fills slide show.
Thanks again, sorry to be a bother, but this thing is driving this old man crazy.
Date: Sun, 26 Dec 2010 20:34:32 -0700
From: [email protected]
To: [email protected]
Subject: Please help with slideshow problems!
You need to save the slideshow project in order to be able to go back later and make changes or additions to an existing slideshow . The wmv file is a final output format.
Now you are most probably using only the Output command: that is what makes the wmv file.
You should also do the Save Project command. (and I make it a practice to do the Save Project command before I do the Output command).
If you look at the Elements Organizer 8 Help, there is a topic on "Create a slide show".
-- Very close to the beginning of that topic is a screen shot of the Sldie Show Editor screen,
-- The bar below the usual menu bar is labeled with a "B" and called the Shortcuts bar.
-- The 1st entry on that Shortcuts bar is "Save Project"
It is the Save Project command that saves the information about which photos, audio, etc you placed in that specific slide show so that you can come back again to do subsequent editing. Save each Project with a unique name.
After completing the Save Project command, you shoud see an "icon" in the Organizer for that slide show.
Note: you must also keep the photo files and audio files which you have used in this slide show: you can't delete them because the project file does NOT contain a copy of the photos, it only has the identification and folder location of the photo and audio files.
> -
Hi. I have an iPhone 4s. The music doesn't play when I connect it to my car stereo. It used to play previously but stopped playing all of a sudden. My phone is getting charged when I cut it to the USB port. Please help with this. The iOS is 6.1.3.
Hello Priyanks,
I found an article with steps you can take to troubleshoot issues with an iPhone not connecting to your car stereo:
iOS: Troubleshooting car stereo connections
http://support.apple.com/kb/TS3581
Thank you for using Apple Support Communities.
Best,
Sheila M. -
My "fn" button is stuck on only revealing mission control in Lion. With this problem none of my "f" keys will work nor can I hold "fn" and delete to delete text in opposite direction. Can someone please help with this?
Following the fix here worked for me:
https://discussions.apple.com/message/15680566#15680566
except my plist file was in ~/Library instead of /Library.
-Scott -
hi, when i am listening music and the screen goes to sleep my music stop playing.Please help with settings
No problem. And no worries, several people have made this same mistake!
Either way enjoy the iPod!
Brock -
Help with BufferedImage and JPanel
I have a program that should display some curves, but thats not the problem, the real problem is when i copy the image contained in the JPanel to the buffered image then i draw something there and draw it back to the JPanel. My panel initialy its white but after the operation it gets gray
Please if some one could help with this
here is my code divided in three classes
//class VentanaPrincipal
package gui;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JSeparator;
import javax.swing.border.LineBorder;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
public class VentanaPrincipal extends javax.swing.JFrame {
//Set Look & Feel
try {
javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch(Exception e) {
e.printStackTrace();
private JMenuItem helpMenuItem;
private JMenu jMenu5;
private JMenuItem deleteMenuItem;
private JSeparator jSeparator1;
private JMenuItem pasteMenuItem;
private JLabel jLabel4;
private JLabel jLabel5;
private JLabel jLabel3;
private JLabel jLabel2;
private JLabel jLabel1;
private JButton jSPLineButton;
private JButton jHermiteButton;
private JButton jBezierButton;
private JPanel jPanel2;
private JPanel jPanel1;
private JMenuItem jResetMenuItem1;
private JMenuItem copyMenuItem;
private JMenuItem cutMenuItem;
private JMenu jMenu4;
private JMenuItem exitMenuItem;
private JSeparator jSeparator2;
private JMenu jMenu3;
private JMenuBar jMenuBar1;
* Variables no autogeneradas
private int botonSeleccionado;
* Auto-generated main method to display this JFrame
public static void main(String[] args) {
VentanaPrincipal inst = new VentanaPrincipal();
inst.setVisible(true);
public VentanaPrincipal() {
super();
initGUI();
private void initGUI() {
try {
this.setTitle("Info3 TP 2");
jPanel1 = new pizarra();
getContentPane().add(jPanel1, BorderLayout.WEST);
jPanel1.setPreferredSize(new java.awt.Dimension(373, 340));
jPanel1.setMinimumSize(new java.awt.Dimension(10, 342));
jPanel1.setBackground(new java.awt.Color(0,0,255));
jPanel1.setBorder(BorderFactory.createCompoundBorder(
new LineBorder(new java.awt.Color(0, 0, 0), 1, true),
null));
BufferedImage bufimg = (BufferedImage)jPanel1.createImage(jPanel1.getWidth(), jPanel1.getHeight());
((pizarra) jPanel1).setBufferedImage(bufimg);
jPanel2 = new JPanel();
getContentPane().add(jPanel2, BorderLayout.CENTER);
GridBagLayout jPanel2Layout = new GridBagLayout();
jPanel2Layout.rowWeights = new double[] {0.0, 0.0, 0.0, 0.0};
jPanel2Layout.rowHeights = new int[] {69, 74, 76, 71};
jPanel2Layout.columnWeights = new double[] {0.0, 0.0, 0.1};
jPanel2Layout.columnWidths = new int[] {83, 75, 7};
jPanel2.setLayout(jPanel2Layout);
jBezierButton = new JButton();
jPanel2.add(jBezierButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
jBezierButton.setText("Bezier");
jBezierButton.setFont(new java.awt.Font("Tahoma",0,10));
jBezierButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
bezierActionPerformed();
jHermiteButton = new JButton();
jPanel2.add(jHermiteButton, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
jHermiteButton.setText("Hermite");
jHermiteButton.setFont(new java.awt.Font("Tahoma",0,10));
jSPLineButton = new JButton();
jPanel2.add(jSPLineButton, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
jSPLineButton.setText("SP Line");
jSPLineButton.setFont(new java.awt.Font("Tahoma",0,10));
jLabel1 = new JLabel();
jPanel2.add(jLabel1, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
jLabel1.setText("Posicion Mouse");
jLabel2 = new JLabel();
jPanel2.add(jLabel2, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(12, 0, 0, 0), 0, 0));
jLabel2.setText("X:");
jLabel3 = new JLabel();
jPanel2.add(jLabel3, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.SOUTH, GridBagConstraints.NONE, new Insets(0, 0, 12, 0), 0, 0));
jLabel3.setText("Y:");
jLabel4 = new JLabel();
jPanel2.add(jLabel4, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(12, 0, 0, 0), 0, 0));
jLabel4.setText("-");
jLabel5 = new JLabel();
jPanel2.add(jLabel5, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.SOUTH, GridBagConstraints.NONE, new Insets(0, 0, 12, 0), 0, 0));
jLabel5.setText("-");
this.setSize(600, 400);
jMenuBar1 = new JMenuBar();
setJMenuBar(jMenuBar1);
jMenu3 = new JMenu();
jMenuBar1.add(jMenu3);
jMenu3.setText("Archivo");
jSeparator2 = new JSeparator();
jMenu3.add(jSeparator2);
exitMenuItem = new JMenuItem();
jMenu3.add(exitMenuItem);
exitMenuItem.setText("Exit");
jResetMenuItem1 = new JMenuItem();
jMenu3.add(jResetMenuItem1);
jResetMenuItem1.setText("Reset");
jMenu4 = new JMenu();
jMenuBar1.add(jMenu4);
jMenu4.setText("Edit");
cutMenuItem = new JMenuItem();
jMenu4.add(cutMenuItem);
cutMenuItem.setText("Cut");
copyMenuItem = new JMenuItem();
jMenu4.add(copyMenuItem);
copyMenuItem.setText("Copy");
pasteMenuItem = new JMenuItem();
jMenu4.add(pasteMenuItem);
pasteMenuItem.setText("Paste");
jSeparator1 = new JSeparator();
jMenu4.add(jSeparator1);
deleteMenuItem = new JMenuItem();
jMenu4.add(deleteMenuItem);
deleteMenuItem.setText("Delete");
jMenu5 = new JMenu();
jMenuBar1.add(jMenu5);
jMenu5.setText("Help");
helpMenuItem = new JMenuItem();
jMenu5.add(helpMenuItem);
helpMenuItem.setText("Help");
} catch (Exception e) {
e.printStackTrace();
private void bezierActionPerformed(){
botonSeleccionado = 1;
((pizarra) jPanel1).setTipoFigura(botonSeleccionado);
((pizarra) jPanel1).pintarGrafico();
//class graphUtils
package func;
import java.awt.Image;
import java.awt.Point;
import java.awt.image.BufferedImage;
public class graphUtils {
public static void dibujarPixel(BufferedImage img, int x, int y, int color){
img.setRGB(x, y, color);
public static void dibujarLinea(BufferedImage img, int x0, int y0, int x1, int y1, int color){
int dx = x1 - x0;
int dy = y1 - y0;
if (Math.abs(dx) > Math.abs(dy)) { // Pendiente m < 1
float m = (float) dy / (float) dx;
float b = y0 - m*x0;
if(dx < 0) dx = -1; else dx = 1;
while (x0 != x1) {
x0 += dx;
dibujarPixel(img, x0, Math.round(m*x0 + b), color);
} else
if (dy != 0) { // Pendiente m >= 1
float m = (float) dx / (float) dy;
float b = x0 - m*y0;
if(dy < 0) dy = -1; else dy = 1;
while (y0 != y1) {
y0 += dy;
dibujarPixel(img, Math.round(m*y0 + b), y0, color);
public static void dibujarBezier(BufferedImage img, Point puntos, int color){
//class pizarra
package gui;
import javax.swing.*;
import sun.awt.VerticalBagLayout;
import sun.security.krb5.internal.bh;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import func.graphUtils;
* esta clase pizarra extiende la clase JPanel y se agregan las funciones de pintado
* y rellenado que se muestra en pantalla dentro del panel que se crea con esta clase
* @author victorg
public class pizarra extends JPanel implements MouseListener{
private int tipoFigura;
BufferedImage bufferImagen;
Image img;
Graphics img_gc;
private Color colorRelleno, colorLinea;
private Point puntosBezier[] = new Point[3];
public pizarra(){
super();
addMouseListener(this);
//this.setBackground(Color.BLUE);
colorLinea = Color.BLUE;
public void setTipoFigura(int seleccion){
// se setea para ver si es bezier, hermite, SP line
tipoFigura = seleccion;
public void setTipoRelleno(int seleccion){
public void setColorRelleno(Color relleno){
colorRelleno = relleno;
public void setColorLinea(Color linea){
colorLinea = linea;
public void setBufferedImage(BufferedImage bufimg){
bufferImagen = bufimg;
public void pintarGrafico(){
Graphics g = this.getGraphics();
g.setColor(colorLinea);
//accion ejecutada cuando se selecciona para graficar un poligono
if(tipoFigura == 1){// bezier
if(bufferImagen == null){
//mantiene guardada la imagen cuando la pantalla pasa a segundo plano
bufferImagen = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
this.setBackground(Color.WHITE);
bufferImagen = (BufferedImage)createImage(getWidth(), getHeight());
//bufferImagen = this.createImage(getWidth(), getHeight());
//g.drawImage(bufferImagen,0,0,this);
graphUtils.dibujarLinea(bufferImagen,10, 10, 50, 50, colorLinea.getRGB());
g.drawImage(bufferImagen,0,0,this);
protected void paintComponent(Graphics g) { // llamado al repintar
//setBackground(colorFondo);
super.paintComponent(g);
// Graphics2D g2 = (Graphics2D)g;
// g2.drawImage(bufferImagen, 0,0, this);
// g2.dispose();
public void mouseClicked(MouseEvent arg0) {
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}1) Swing related questions should be posted in the Swing forum.
Custom painting should be done in the paintComponent(..) method. You created a "pintarGraphico" method to do the custom painting, but that method is only execute once. When Java determines that the panel needs to be repainted, the paintComponent() method is executed which simply does a super.paintComponent(), which in turn simply paints the background of the panel overwriting you custom painting.
Maybe you are looking for
-
Hard disk unallocated all of a sudden
Hey all, I seem to have run into yet another problem. I have arch running on my second HDD, and my first one holds Vista. Originally Vista had both HDDs, one where it was installed on, and one where it had extra room to put data. Now I resized the
-
Can not start Weblogic Server Admin
Hi, I am new to Weblogic and trying to install v12.1.1 on Windows 7 64 bit. The installation "seems" to have gone fine, however I cannot see User Projects under "start" =>"all programs" => "Oracle Weblogic" => "user projects" => "base_domaine" => "st
-
When connecting to Synch how do I fix "The iphone cannot be used because thr Apple Mobile device service is not started"
-
My skype email is not real, and i dont remember my...
Hi, i was trying to log-in to Skype, but i got error, and it says "Sorry, we didn't recognize your sign-in details. Please check your Skype Name and password, then try again." I dont remember my password. I need to get my Skype account back, because
-
BPM Error --- RCVR_DETERMINATION NO_RECEIVER_CASE_ASYNC
Hi All, For my simple BPM scenario -- I am getting RCVR_DETERMINATION NO_RECEIVER_CASE_ASYNC Point to add -- My BPM has correct Receiver Determination. 1. Because When I activate my ID objects and checked in Environment -- Cache Status Overview It d