Python Cookbook 2Nd Edition Jun 1002005 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Python Cookbook 2Nd Edition Jun 1002005 [Electronic resources] - نسخه متنی

David Ascher, Alex Martelli, Anna Ravenscroft

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







Recipe 11.16. Viewing an Image from a URL with Swing and Jython


Credit: Joel Lawhead, Chuck Parker


Problem



You want to make a simple Swing
image viewer, accepting the URL to an image and displaying the image
in a Swing window.


Solution


Jython makes this task very easy:

from pawt import swing
from java import net
def view(url):
frame = swing.JFrame("Image: " + url, visible=1)
frame.getContentPane( ).add(swing.JLabel(swing.ImageIcon(net.URL(url))))
frame.setSize(400,250)
frame.show( )
if _ _name_ _ == '_ _main_ _':
view("http://www.python.org/pics/pythonHi.gif")


Discussion


Swing's JLabel and
ImageIcon widgets can be easily combined in Jython
to make a simple image viewer. The need to pass a URL to the
view function is not at all a limitation, because
you can always use the file: protocol in your URL
if you want to display an image that lives on your filesystem rather
than out there on the Web. Remember that the U in URL stands for
Universal!


See Also


Swing docs are at http://java.sun.com/docs/books/tutorial/uiswing/;
Jython is at http://www.jython.org.


/ 394