/**the Imageviewer
*it can is used to view image
*author:ginger547 qq:420607
* */
Import java.awt.*;
Import java.awt.image.*;
Import java.io.*;//the necessary files
Inherit from frame
public class Imageviewer extends Frame {
Constructors
Public Imageviewer () {
Set Title
Settitle ("image browser");
Menu bar
MenuBar mbar = new MenuBar ();
Menu m = new Menu ("file");
M.add (New MenuItem ("Open"));
M.add (New MenuItem ("Exit"));
Mbar.add (m);
Setmenubar (mbar);
}
public boolean handleevent (Event evt) {
if (evt.id = = Event.window_destroy)
System.exit (0);
Return super.handleevent (EVT);
}
Menu mouse click to handle
Public boolean action (Event evt, Object Arg) {
if (Arg.equals ("open")) {
File dialog box
FileDialog d = new FileDialog (this, "Open image File", filedialog.load);
D.setfile ("*.jpg");
D.setdirectory (Lastdir);
D.show ();
String f = d.getfile ();
Lastdir = D.getdirectory ();
if (f!= null)
Image = Toolkit.getdefaulttoolkit (). GetImage (Lastdir + f);
Repaint ();
else if (Arg.equals ("Exit")) {
System.exit (0);
} else
return false;
return true;
}
public void Paint (Graphics g) {
if (image!= null) {
One of the most important methods used in this example
G.drawimage (image, M, this);
}
}
public static void Main (String args[]) {
Frame f = new Imageviewer ();
F.resize (800, 600);
F.show ();
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service