Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+6 votes
asked in CSC211_Winter2018 by (1 point)

Note that drawing images will not be necessary for the final exam... (although drawing figures using g.fillOval(), etc., will be!)

1 Answer

+1 vote

To add images to a DrawingPanel object, you would need to call some of the following lines of code:

DrawingPanel panel = new DrawingPanel(500, 500); // creating the object
Graphics g = panel.getGraphics();
panel.loadImageAndResizeWindow("my_image.jpg"); // loads image and resizes window, like in the ImageGallery project
BufferedImage buffimage = panel.loadImage("my_image.jpg"); // loads image, but doesn't draw it...
g.drawImage(buffImage, 50, 50, null); // draws the buffered image at given x and y coordinates

answered by (1 point)