Aeon 42 Share Posted August 1, 2020 As the title says, I'm trying to add an image to the screen for my script, but I can't seem to get it to work properly. I found this thread which has a bunch of dead screenshots so it wasn't too useful. Any help in pointing me in the direction would be greatly appreciated! Link to comment Share on other sites More sharing options...
Pixel_Life 21 Share Posted August 1, 2020 See Hashtag's tutorial here: The "Drawing an image" section. Super simple, that's the tutorial that helped me with it Aeon 1 Link to comment Share on other sites More sharing options...
Succulent 18 Share Posted August 1, 2020 Step 1: Add this method to your main class to return Image objects from a URL: private Image getImage(String url) { try { return ImageIO.read(new URL(url)); } catch (IOException e) { e.printStackTrace(); } return null; } Step 2: Create an Image property to store the image using this method: private final Image paintBackground = getImage("https://i.imgur.com/Muw7swQ.png"); Step 3: Draw the image using graphics in onPaint: if (paintBackground != null) { g.drawImage(paintBackground, 30, 316, null); } Sources: Aeon, Aeglen and Pandemic 2 1 Link to comment Share on other sites More sharing options...
Aeon 42 Author Share Posted August 1, 2020 @Succulent Thank you! I'd read through that thread at some point and I guess I didn't remember reading that... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now