Simple Image Viewer in Java
Submitted by mehfuza on Thursday, September 12, 2013 - 17:22.
Language
Introduction
In this tutorial we will learn how to display picture in Java Application. There is difference between how a picture displayed in application and applet. For application we require drawImage() method which draws the image to specific component and not the entire frame. Implementation Step 1: Creating the components We require a label, text field where user will enter name or address of the image and a button which when clicked will display the image. A panel to keep all these components.- JLabel label;
- JTextField name;
- JButton display;
- JPanel upperPanel;
- ImageDisplay()
- {
- super("Image Demo");
- DrawPanel panel=new DrawPanel();
- display.addActionListener(panel);
- upperPanel.add(label);
- upperPanel.add(name);
- upperPanel.add(display);
- }
- {
- repaint();
- }
Step 4: Defining main() method
main() method is defined which set the different properties of the frame and execution begins from here.
- ImageDisplay img=new ImageDisplay();
- img.setSize(800,600);
- img.setVisible(true);
- img.setDefaultCloseOperation(EXIT_ON_CLOSE);
- img.setResizable(false);
- }
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Comments
Hi there
Hi there
Thanks for your sharing.I am not the common user of image.I have only tried a free trial for imaging viewer.And now i want to get an image viewer for my mac.But i want to know that if it is possible for this image viewer to work offline?
Thanks for any suggestion.
Add new comment
- Add new comment
- 883 views