Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners displaying image in awt

Have Programming Question? Ask it here!
 
 
 


mln15584
displaying image in awt
2 Answer(s)      6 years and 2 months ago
Posted in : Java Beginners



Advertisement
View Answers

July 16, 2008 at 6:39 PM


Hi friend,

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

class imageLoad extends Canvas {
Image img;
public imageLoad(Image img) {
this.img = img;
}
public void paint (Graphics g) {
if (img != null)
{
g.drawImage(img, 0, 0, 1000, 1000, this);
}
}
public void setImage (Image img){
this.img = img;
}
}
public class ImagesLoading implements ActionListener{
JFrame fr = new JFrame ("Image loading program Using awt");
Label Label1 = new Label("Label1 ");
Button Button1 = new Button("Click Here");
Image Image1;
imageLoad Canvas1;
FileDialog fd = new FileDialog(fr,"Open", FileDialog.LOAD);

void initialize (){
fr.setSize(500,500);
fr.setLocation(300,300);
fr.setBackground(Color.lightGray);
fr.setLayout(new FlowLayout());
fr.add(Label1);
fr.add(Button1);
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Button1.addActionListener(this);
Canvas1 = new imageLoad(null);
Canvas1.setSize(1000,1000);
fr.add(Canvas1);
fr.show();
}
void imageload () {
fd.show();
if(fd.getFile() == null){
Label1.setText("You have not chosen any image files yet");
}
else{
String d = (fd.getDirectory() + fd.getFile());
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image1 = toolkit.getImage(d);
Canvas1.setImage(Image1);
Canvas1.repaint();
}
}

public void windowClosing(WindowEvent e){
System.exit(0);
}
public void windowActivated(WindowEvent e){
}
public void windowClosed(WindowEvent e){
}
public void windowDeactivated(WindowEvent e){
}
public void windowDeiconified(WindowEvent e){
}
public void windowIconified(WindowEvent e){
}
public void windowOpened(WindowEvent e){
}
public void actionPerformed(ActionEvent event){
Button b = (Button)event.getSource();
if(b == Button1){
imageload();
}
}
public static void main(String args[]){
ImagesLoading a = new ImagesLoading();
a.initialize();
}
}

---------------------------------------------------

Read for more information,

http://www.roseindia.net/java

Thanks


July 17, 2008 at 10:58 AM


You can use JAI (Java Advanced Imaging) to display an image.

eg.,

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.media.jai.JAI;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class ImagePanel extends JPanel
{
private BufferedImage image;

public ImagePanel(String fileName)
{
image = JAI.create("fileload",fileName).getAsBufferedImage();
setPreferredSize(new Dimension(image.getWidth(),image.getHeight()));
}

public void paint(Graphics g)
{
if(image != null)
g.drawImage(image, 0, 0, this);
}

public static void main(String[] args)
{
ImagePanel panel = new ImagePanel("D:/Sunset.jpeg");
JFrame frame = new JFrame("Image Frame");
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(panel.getPreferredSize());
frame.setResizable(false);
frame.setVisible(true);
}
}

-Thanks
Ramesh A.V


Related Tutorials/Questions & Answers:
displaying image in awt - Java Beginners
displaying image in awt  Hi All, I have downloaded the code to display image using awt from here and when I execute the code I am getting... ActionListener{ JFrame fr = new JFrame ("Image loading program Using awt"); Label
Image is not displaying
Image is not displaying  Hii i am using spring javamail with html template to send mail,i am facing that image displaying prob when mail have to cm in gmail,in template just i am giving my current location of image which
Advertisements
displaying image
displaying image  how to upload image and retrieve it form database mysql in php?   Here is an example of uploading image using php. 1)form.html: <form method="post" enctype="multipart/form-data" action="upload.php
image displaying in java
image displaying in java  how to display an image by using load image button in applet viewer
AWT Image
AWT Image  I have loaded two images using toolkit in java.one is concentric rectangle and other is concentric circle.kindly someone send me the source code of interchanging the inner most rectangle with the inner most circle
Displaying image using jsp and spring.
Displaying image using jsp and spring.  how to display an image stored in WEB-INF/images folder on the browser using jsp and spring
Image Manipulation in Swing AWT
Image Manipulation in Swing AWT  Sir, I'am new to Swing Programming. I have to create an application where an image is displayed on one Label. The same image has to be split in parts and stored in database pert wise. Later
loading image - Swing AWT
loading image  give me a source code to add any wallpaer of my PC as a background image to jpanel on a jframe
Image Selection - Swing AWT
Image Selection  Hi, I need to provide the image selection facility... click on any item, the image of that item should be selected as done in windows...; JButton saveButton; public DisplayImage() { super("Image Selection program
Displaying image with byte array[] - Java Beginners
Displaying image with byte array[]  Hi Frndz.. As per my requirement i need to show an image by using an byte array object which have image data... this only i have to image , i don't have any Inputstream object. If u have
problen in displaying the text and image in gallery using Android
problen in displaying the text and image in gallery using Android   public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); gallery = (Gallery
image displaying from database with some other information
image displaying from database with some other information  hi, in the following section of code when i am not displaying the image it is working properly but when i tried to display the image nothing is displayed on browser
How to retrive an inmage from database and displaying it in imgae box - Swing AWT
How to retrive an inmage from database and displaying it in imgae box ...? I want to retrive an image from database and to display it in a small imagebox... = con.createStatement(); ResultSet rs =stmt.executeQuery("select image from image where image
Displaying image when clicked on URL in jsp - JSP-Servlet
Displaying image when clicked on URL in jsp  Hi, I am using... in displaying the image from the folder. Regards, Anish... For Screenshot : abc.jpg here abc.jpg is a url and when clicked would show me an image
forwarding request to a jsp from a filter and displaying image in that jsp
forwarding request to a jsp from a filter and displaying image in that jsp ... correctly, but in login.jsp the image is not displaying. Can you help me in resolving this problem. Thanks & Regards, Suresh   Jsp Display Image <
displaying both image and records problem in jsp and servlet - JSP-Servlet
displaying both image and records problem in jsp and servlet  hello, Thanks for your reply on the question i asked the other time. It worked perfectly, but it's still not what i want. What i want is that, i want
Displaying the same image in a JPanel and using scroll - HELP - Java Beginners
Displaying the same image in a JPanel and using scroll - HELP  I hope someone can help me out here. I want to display an image in a JPanel which contain a Scroll, so using the scroll I want to see the first image displayed
how to set a image in frame? - Swing AWT
how to set a image in frame?  how to set a image in frame using swing
Error in laodin and saving the image . - Swing AWT
Error in laodin and saving the image .  I am a student who had... facing problem while laoding and saving the image with help of JFileChooser class... class UploadImage extends JPanel { static BufferedImage image; static File
how to retrive other details with an image - Swing AWT
to retrive an image as well as some other values from database.. but only image..... followingis my code..plz advice me how to get both values as well as image at a same...("Select visitor_firstname,Type_code, image_data from visiting_details where Ticket
java image loadin and saving problem - Swing AWT
java image loadin and saving problem  hey in this code i am trying to load a picture and save it.........but image is only visible whn we maximize... extends JPanel { static BufferedImage image; static File file=null; Image img
AWT
AWT  How to set size of button in awt
awt
Java AWT Applet example  how to display data using JDBC in awt/applet
awt
JDBC and AWT to display data  how to display data using JDBC in awt/applet
awt
JDBC in awt applet  how to display data using JDBC in awt/applet
put image on form creating in swing-swing code - Swing AWT
put image on form creating in swing-swing code  i want to display image on swing panel and get the image co ordinate by mouse clicking.and also zoom the image at particular area of image. please give solution on my email id
awt
JDBC in awt  how to display data using JDBC in awt/applet
Image is in same folder where the java file is located - Swing AWT
Image is in same folder where the java file is located  dear sir It is there in the same folder..means the photograph.jpg file is created in the same folder where my java file is present... wat I should do sir
how to set image in button using swing? - Swing AWT
how to set image in button using swing?  how to set the image in button using swing?  Hi friend, import java.awt.*; import... FlowLayout()); getContentPane().add(myJButton); setTitle("Image on Button
Image on Frame in Java AWT
Image on Frame in Java AWT       Introduction In this section, you will learn how to display image on the frame. This program shows you how to display image in your application
hybrid digital image embedding process using invisible watermarking - Swing AWT
hybrid digital image embedding process using invisible watermarking   sir/madam, I am subramanian from chennai.i did not create this project using rsa algorithm and i did not understand.please help me with source
AWT programmes - Swing AWT
AWT programmes  I need few programs for menus in AWT. how to open a filed dialog window, and how to save a image in the save window when we press... has all AWT programms which must open,save and make changes to a particular
displaying data
displaying data   how to display data from database on jsp using struts2
Image Size
Image Size       This Java awt (Abstract Windowing Toolkit) tutorial describes about the image size...; This program helps you in setting an image and getting the size of its
AWT & SWING
AWT & SWING  What is diffennce between AWT & SWING
image
image  how to add the image in servlet code
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
awt swings - Swing AWT
awt swings  hello sir, My requirement is to insert captured image......  Hi friend, This code will be captured your image. Please...(); BufferedImage image = robot.createScreenCapture(new Rectangle
PHP Displaying URL Content
PHP Displaying URL Content  In my PHP application form, on submitting the form details it always displaying url content. Can anyone tell me what is the reason and how to restrict it from displaying
awt in java
awt in java  using awt in java gui programming how to false the maximization property of a frame
codes for displaying in calendar
codes for displaying in calendar  can i get jsp codes for displaying comments, when the pointer is placed over the particular date in calendar
Java AWT
Java AWT  What interface is extended by AWT event listeners
awt jdbc
awt jdbc  programm in java to accept the details of doctor (dno,dname,salary)user & insert it into the database(use prerparedstatement class&awt
Displaying images - JDBC
Displaying images  How to display multiple images on a single jsp from MySql database
Displaying images - JDBC
Displaying images  How to display multiple images on a single jsp from MySql database
Java AWT Package Example
to be displayed on the frame.   Image Size This Java awt (Abstract... Java AWT Package Example       In this section you will learn about the AWT package of the Java
(Displaying a calendar in GUI
(Displaying a calendar in GUI  (Displaying a calendar) Write a program that displays the calendar for the current month, as Use labels, and set texts on the labels to display the calendar."The Calendar and GregorianCalendar
Image Demo
Image Demo       This section simply display the image demo that means multiple images and its name are based on the frame to a particular location. For displaying images demo
 

 

 

DMCA.com