+ 1
How can i make my code load an image when it's run i heard that i should also use html file or something but i don't understand
Be aware that image.gif is just random so what should i write instead . import java.applet.*; import java.awt.*; public class Final2022 extends Applet { Image img; public void init() { img = getImage(getCodeBase(), "image.gif"); } public void paint(Graphics g) { int iwidth = img.getWidth(this); int iheight = img.getHeight(this); int xpos = 10; g.drawImage(img, xpos, 10, iwidth / 4, iheight / 4, this); xpos += (iwidth / 4) + 10; g.drawImage(img, xpos, 10, iwidth / 2, iheight / 2, this); xpos += (iwidth / 2) + 10; g.drawImage(img, xpos, 10, this); } }
1 Answer
+ 1
Hi, the Applet API is deprecated, quite dead, since JDK 9 if im not wrong..
What you could do is to create a window with the JFrame class,
there is two ways to do it.
1. By createing object of JFrame class
2. By extending JFrame class
I made a lite program for you with comments, hope it helps.
https://www.sololearn.com/compiler-playground/cvNuZ3vxjIIJ