Java Swing AWT Program to Display Image in Canvas From Local File System Using JFrame Widget GUI Desktop App

You are currently viewing Java Swing AWT Program to Display Image in Canvas From Local File System Using JFrame Widget GUI Desktop App

If you want to learn the topic about “Java Swing AWT Program to Display Image in Canvas From Local File System Using JFrame Widget GUI Desktop App” then refer to this article to learn about it. Let’s start the article.

Java Swing AWT Program to Display Image in Canvas From Local File System Using JFrame Widget GUI Desktop App

displayimage.java

import java.awt.*;  
import javax.swing.JFrame;  
  
public class MyCanvas extends Canvas{  
      
    public void paint(Graphics g) {  
  
        Toolkit t=Toolkit.getDefaultToolkit();  
        Image i=t.getImage("p3.gif");  
        g.drawImage(i, 120,100,this);  
          
    }  
        public static void main(String[] args) {  
        MyCanvas m=new MyCanvas();  
        JFrame f=new JFrame();  
        f.add(m);  
        f.setSize(400,400);  
        f.setVisible(true);  
    }  
  
}

Final Words

I hope this article helps you to know about the “Java Swing AWT Program to Display Image in Canvas From Local File System Using JFrame Widget GUI Desktop App”. If you face any issues please let me know via the comment section. Share this article with other Java program developers via social networks. Thank You!

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply