Java Forum / General / March 2007
Swing better than Awt?
dolphin - 18 Mar 2007 11:12 GMT Hi !Swing better than Awt?How do you think?
Andrew Thompson - 18 Mar 2007 11:21 GMT > Hi !Swing better than Awt? Define 'better'.
>..How do you think? Why not start the thread rolling, by giving your views, first?
Andrew T.
jupiter - 18 Mar 2007 18:15 GMT >> Hi !Swing better than Awt? > > Define 'better'. My new mouse trap.
Xiaochuan Fang - 18 Mar 2007 11:28 GMT dolphin 写道:
> Hi !Swing better than Awt?How do you think? AWT is too simple, while SWing is too slow. I like SWT/JFace.
jb - 18 Mar 2007 12:06 GMT dolphin:
>>Hi !Swing better than Awt?How do you think? Better for what purpose?
Xiaochuan Fang:
> AWT is too simple, while SWing is too slow. AWT is not simple, but featureless. It might get complicated when you try to customize it a lot.
I use swing just for esthetic pleasure of using so well planned library, and because it is very easy to learn, to use, and to customize. But my apps aren't commercial, and my users (well there's only few :)) don't need very opiimized things.
Lew - 18 Mar 2007 16:36 GMT > dolphin: >>> Hi !Swing better than Awt?How do you think? [quoted text clipped - 11 lines] > customize. But my apps aren't commercial, and my users (well there's > only few :)) don't need very opiimized things. SWT is not standard enough for me.
Swing is only slow if your Swing app is poorly designed. Admittedly, it's tricky to get right because of the rules about the EDT, and the Motif/OpenLook style of coding takes some getting used to, and of course, it really helps if you are comfortable with Java listener idioms, but if programming was easy we'd be out of work.
I don't know that anyone is too impressed with Java user-interface libraries, but Swing definitely can get the job done.
Swing does not depend on the platform to implement its behaviors the way that AWT does. Most of Swing's behaviors are pure Java.
-- Lew
Michael Rauscher - 18 Mar 2007 17:29 GMT > dolphin 写道: >> Hi !Swing better than Awt?How do you think? >> > ... while SWing is too slow. No, not the old fairy-tale again.
Bye Michael
Christian - 18 Mar 2007 17:53 GMT Michael Rauscher schrieb:
>> dolphin 写道: >>> Hi !Swing better than Awt?How do you think? [quoted text clipped - 5 lines] > Bye > Michael Is it really a fairy tale?
from my understanding of swing (I haven't really used it)
swing hides the fact from you that an os usually only allows one single Gui-Thread that you have to use when you interact with the gui ...
don't know how swing does interaction then.. either you can't interact directly with os ressources .. so swing only lets the os paint, but all resources that are interacted with are java only.. or swing magically transfers your actions into the right thread for execution..
any of these seems to be non trivial ... if for example the os- developpers took a lot of care that the gui interaction thread is very responsive to the user .. java would throw that advantage away if the use their own threads..
transfering actions from a normal thread to the gui thread may be done in a non optimal way for your application ...
I am just guessing ... but from what I heard swing seems to be a tool getting faster and faster with every java version and less distinguishabel from the native gui ... though if it is like I guessed above .. there will always be a border swing can't cross ... where you need to force more work on the programmer for getting the native gui like in swt/jface
Christian please don't lapidate me
Lew - 18 Mar 2007 18:46 GMT dolphin wrote:
>>>> Hi !Swing better than Awt?How do you think? Xiaochuan Fang wrote:
>>> ... while SWing is too slow. Michael Rauscher schrieb:
>> No, not the old fairy-tale again.
> Is it really a fairy tale? Yes.
> from my understanding of swing (I haven't really used it) > swing hides the fact from you that an os usually only allows one single > Gui-Thread that you have to use when you interact with the gui ... And exposes the fact that Swing only allows one single Java Event Dispatch Thread (EDT) that you have to use when you interact with the GUI.
-- Lew
Michael Rauscher - 18 Mar 2007 19:25 GMT > Michael Rauscher schrieb: >>> dolphin 写道: [quoted text clipped - 4 lines] > > Is it really a fairy tale? Yes, it is.
Swing is based on AWT. The main difference between AWT and Swing is that Swing paints components (and manage their states) by itself while AWT let the native system paint them.
Consequences:
1. Swing is a tick slower than AWT. 2. Swing isn't thread-safe. 3. It's easier to produce Swing apps that aren't responsive.
ad 1) It's just a tick, so it's far away from being "too slow".
ad 2) As a result there's the single-thread rule: Swing components can be accessed by only one thread at a time.
Note, that there are no guarantees that AWT is thread-safe. It's a result of the underlying system.
ad 3) One can easily block the EDT - in both, Swing and AWT. It's just that one can recognize a blocked EDT in a Swing application immediately.
Let's compare what happens if one blocks the EDT in Swing and AWT. To do this, we'll have a look at a GUI containing one button that - if pressed - blocks the EDT for about 5 seconds.[1]
Swing: the button keeps pressed for 5 seconds. In fact, the whole content of that window will not get repainted within the 5 seconds.
AWT: the button returns to the normal state immediately.
So, how can one recognize a blocked EDT in a AWT app?
Resize the Window while the EDT is blocked. Both, the Swing and the AWT app will not resize the button until the 5 seconds are over.
In real apps one can't continue until the EDT is not blocked anymore - in both, Swing and AWT.
Bye Michael
[1] Sample application (negative), to call use java SwingAWT [mode]
If mode is not given, the Swing version will run. If mode is swing, the Swing version will run. If mode is anything other, the AWT version will run.
import java.awt.*; import java.awt.event.*; import javax.swing.*;
public class SwingAWT { private ActionListener listener = new ActionListener() { public void actionPerformed( ActionEvent e ) { try { Thread.sleep(5000); } catch ( InterruptedException ie ) {} } };
private Frame frame; private Component button;
private void initAWT() { button = new Button("Block EDT"); ((Button)button).addActionListener( listener ); frame = new Frame("SwingAWT - AWT"); }
private void initSwing() { button = new JButton("Block EDT"); ((JButton)button).addActionListener( listener ); frame = new JFrame("SwingAWT - Swing"); }
public void createAndShowGUI( boolean awt ) { if ( awt ) initAWT(); else initSwing();
frame.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { frame.dispose(); } }); frame.add( button ); frame.pack(); frame.setVisible(true); }
public static final void main( String args[] ) { final boolean awt = (args.length < 1 || "swing".equals(args[0])) ? false : true;
EventQueue.invokeLater( new Runnable() { public void run() { new SwingAWT().createAndShowGUI(awt); } }); } }
Chris Uppal - 18 Mar 2007 19:54 GMT > > ... while SWing is too slow. > > No, not the old fairy-tale again. I'd say it's far from being a fairy-tale. I agree that (what with improvements inside AWT/Swing /and/ general speedups of machines) it is no longer as true as it used to be, but it wasn't and isn't a complete myth.
It's like claiming that the Thames is polluted. That is true today, but not in anything like the way that the poor river was polluted a 50 or 100 years ago. Then it was so true that you'd build your life around that truth (not live near the bad bits of the river and so on). These days, you wouldn't actually /drink/ it, but not everyone who jumps in comes away with a health problem...
Swing is slow in the same sort of sense. It's /too/ slow, but it's no longer so bad that I'd automatically avoid using a Swing/AWT app just for that reason.
(And no, before anyone mentions it, I'm /not/ talking about the [lack of] startup speed -- that's a different issue IMO.)
- chris
Mark Thornton - 18 Mar 2007 22:04 GMT > Swing is slow in the same sort of sense. It's /too/ slow, but it's no longer > so bad that I'd automatically avoid using a Swing/AWT app just for that reason. In my opinion a Swing application needn't be /too/ slow but it may take an experienced Swing developer to achieve that result. For example many people would have trouble displaying a 100MB text document in Swing. However with a careful choice of Document implementation this can perform very well -- you can use the normal JTextArea to handle all the display details, all the bottlenecks were in the Document implementation (some of these have been fixed since I last experimented).
Mark Thornton
Michael Rauscher - 18 Mar 2007 23:27 GMT >>> ... while SWing is too slow. >> No, not the old fairy-tale again. [quoted text clipped - 11 lines] > Swing is slow in the same sort of sense. It's /too/ slow, but it's no longer > so bad that I'd automatically avoid using a Swing/AWT app just for that reason. In the same way SWT, my PC and internet connections are too slow. Your point is nearly always true for nearly anything.
I already mentioned that Swing is a tick slower than AWT and of course it would be nice if Swing would get faster.
NB: A few years ago I tried both NetBeans and Eclipse under Linux. A situation where SWT was much slower than Swing. But I would say that neither SWT nor Swing is too slow.
Bye Michael
Richard Maher - 19 Mar 2007 11:29 GMT Hi Chris,
> but not everyone who jumps in comes away with a health problem... Ah, but many do! Speaking as one who came away with a bruised/broken coccyx after jumping off Richmond Bridge two summers ago (the day before it reached 100F) I can testify that it's still not a pleasant experience :-) I didn't hit the bottom even though the tide was way out and, as a local, I should've known better, it was just the sheer majesty and height of that 45ft leap and tsunami-inducing entry that did the damage. But then there's that Viles disease, hacked up bodies in suitcases, numerous discharges from Iselworth treatment works, and the seemingly endless detritus that most of London seems to deposit in it, and only an idiot would jump in! That's alcohol for ya :-(
Anyway WRT Swing -vs- AWT, as a beginner I've been using AWT 'cos I thought it was a simpler yet still functional interface. Is that wrong? Did Swing supplant AWT? Is there a library better than Swing? I imagine technology hasn't stood still since the gridbag layout, but where should one invest there time? Does anyone handcraft this stuff anymore or is it all generated code now anyway?
Regards Richard Maher
> > > ... while SWing is too slow. > > [quoted text clipped - 17 lines] > > - chris Sherm Pendley - 19 Mar 2007 12:07 GMT > Does anyone handcraft this stuff anymore or is it all generated > code now anyway? I'd say that learning to handcraft GUI code is valuable even if you end up using a GUI builder tool for production work. The experience you gain from writing the code by hand will give you a better understanding of what the tool is creating for you.
sherm--
 Signature Web Hosting by West Virginians, for West Virginians: http://wv-www.net Cocoa programming in Perl: http://camelbones.sourceforge.net
Arne Vajhøj - 19 Mar 2007 14:26 GMT > Anyway WRT Swing -vs- AWT, as a beginner I've been using AWT 'cos I thought > it was a simpler yet still functional interface. Is that wrong? Did Swing > supplant AWT? Is there a library better than Swing? I imagine technology > hasn't stood still since the gridbag layout, but where should one invest > there time? I believe that >95% uses Swing and not AWT today if it is possible.
Note that it is not possible if you have to support applets running with old MS or NS JVM's.
> Does anyone handcraft this stuff anymore or is it all generated > code now anyway? The tradition in the Java world is handcoded GUI's.
Arne
Andrew Thompson - 19 Mar 2007 15:45 GMT ... (usage of Swing)
> Note that it is not possible if you have to support applets running > with old MS or NS JVM's. Apparently here was a 'swing.jar' (or similar) available for attaching to even Java 1.1 projects, though given it was at least a couple of hundred Kb, I never felt it was justified to deliver it with an applet that was ..I think the biggest applet I wrote was around 40Kb of bytecodes, just for the addition of buggy (think 'pre 1.2') Swing components to the end user.
This is mostly a moot point, of course, since the original Swing jar would still not support a lot of the things that were either introduced, or significantly improved, in Swing for later J2SE releases.
Andrew T.
RedGrittyBrick - 19 Mar 2007 20:00 GMT > Anyway WRT Swing -vs- AWT, as a beginner I've been using AWT 'cos I > thought it was a simpler yet still functional interface. Is that > wrong? AWT is simpler, it is functional. I ignored AWT and just started with Swing.
> Did Swing supplant AWT? Yes. Broadly speaking.
> Is there a library better than Swing? For specialised and restricted values of "better" there is SWT etc. There would be a different answer for J2ME. For server based Java apps the GUI could be HTML or even AJAX I guess.
> I imagine technology hasn't stood still since the gridbag layout, It hasn't.
> but where should one invest there time? In the areas most relevant to the type of application you are interested in creating. Maybe you should get a broad overview of the Java platform before deciding which areas to invest some time in?
> Does anyone handcraft this stuff anymore Yes. Some do.
> or is it all generated code now anyway? No. Some is not.
John W. Kennedy - 19 Mar 2007 22:58 GMT > Anyway WRT Swing -vs- AWT, as a beginner I've been using AWT 'cos I thought > it was a simpler yet still functional interface. Is that wrong? It's simpler in that it has fewer features, but for non-trivial jobs, Swing is frequently easier to /use/.
> Did Swing > supplant AWT? Not entirely. Swing uses some basic parts of AWT to get its job done, and event handling is still done using the improved AWT event system that was introduced in Java 1.1. But, in general, yes.
> Is there a library better than Swing? If you need to support versions of Java older than Swing, AWT is better. (But versions of Java older than Swing are all obsolete.) If you want to write a plug-in for Eclipse, SWT is better. But, in general, Swing is much more powerful.
> I imagine technology > hasn't stood still since the gridbag layout, Yes and no. GridBagLayout is still probably the most powerful tool for general-purpose layouts, but there are some new tools to simplify certain common cases. (Layouts are another instance of AWT features that are still used with Swing.)
> but where should one invest > there time? Does anyone handcraft this stuff anymore or is it all generated > code now anyway? There are a bunch of layout-design tools, but none of them seem to be likely to take over the world anytime soon. There are also some things in Swing that are self-contained solutions where AWT would have needed a layout, such as toolbars.
 Signature John W. Kennedy "The pathetic hope that the White House will turn a Caligula into a Marcus Aurelius is as naïve as the fear that ultimate power inevitably corrupts." -- James D. Barber (1930-2004) * TagZilla 0.066 * http://tagzilla.mozdev.org
Christian - 19 Mar 2007 23:23 GMT > If you need to support versions of Java older than Swing, AWT is better. > (But versions of Java older than Swing are all obsolete.) If you want to > write a plug-in for Eclipse, SWT is better. But, in general, Swing is > much more powerful. Swing may be more powerful alone .. but swing contains some things that are not representing gui-widgets, but also mappings from model to the gui... in swt this is strictly devided.. swt only represents the gui the average os has ... if you need help modelling you datamodel to the gui then there is jface..
though from what I have seen of swing I would think swing is still more powerful than swt and jface combined, but this separation is a strength that will make it easier for swt to develop in the future... and if you need some functionallity of swing that swt/jface doesn't have .. for example rendering text with the help of html .. then you can just embedd swing in swt..
But swing is definately much easier to deploy.. You don't have to get different libs for every os..
.. my experience so far.. Christian
Chris Uppal - 22 Mar 2007 12:06 GMT > > but not everyone who jumps in comes away with a health problem... > > Ah, but many do! Speaking as one who came away with a bruised/broken > coccyx after jumping off Richmond Bridge two summers ago (the day before > it reached 100F) Eek !
> then there's that Viles disease, hacked up bodies in suitcases, numerous > discharges from Iselworth treatment works, and the seemingly endless > detritus that most of London seems to deposit in it, and only an idiot > would jump in! That's alcohol for ya :-( Richmond's about 25 miles downstream from me as the crow flies -- or about 40 as the corpse floats ;-) So I daresay I'm responsible for some of the detritus...
> Anyway WRT Swing -vs- AWT, as a beginner I've been using AWT 'cos I > thought it was a simpler yet still functional interface. Is that wrong? I'd say that if you /can/ use Swing instead of raw AWT (and most people can), then Swing's to be preferred. The simplicity of AWT is mainly just from stuff that's missing, rather than because it has an inherently neater API.
-- chris
Richard Maher - 22 Mar 2007 21:10 GMT Hi Chris, et al
"Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> wrote in message
> I'd say that if you /can/ use Swing instead of raw AWT (and most people can), > then Swing's to be preferred. The simplicity of AWT is mainly just from stuff > that's missing, rather than because it has an inherently neater API. Even though I /can't/ do Swing, I'll make a point of looking up Sun's tutorial on the matter and giving it a go. (The fact that I "can't do" Java, HTML, JavaScript, or CSS hasn't stopped me so far; how hard can it be? : -) Actually it's all looking sh.t-hot at the moment and I'm quite pleased with the results of this functionality demo/proof-of-concept I've been working on!)
But before launching into Swing there is one niggle or possible spanner-in-the-works I'd like to quiz you about, and that is "footprint" both in terms of memory and bandwidth of a Swing evoking class. In my case I'm using an Applet that does little more user interaction than pop-up a couple of dialog boxes before handing control over to the web browser and html, and find AWT to be a stream-lined gazelle-like creature (albeit three-legged) and fear Swing could be more like an elephant. Are my fears ill-founded? Are all the class libraries in the JVM anyway so don't have to be sent over the network? Will my Class and JAR files be roughly the same size? Is relative resource consumption (or body mass index) an issue?
> Richmond's about 25 miles downstream from me as the crow flies -- or about 40 > as > the corpse floats ;-) So I daresay I'm responsible for some of the detritus... Yes, I thought that was your Christmas tree I saw floating down with the others each year. (Not to mention the black rubbish bags that people would leave out on the tow-path only to have the high-tide take them away :-( Why "The Royal Borough of Richmond Upon Thames" had yet to discover wheely-bins is beyond me.) All that aside, you live in a nice part of the world! I miss the Daffs, Crocuses, and cherry-blossoms this time of the year! The drive through Richmond park to take the kids to school was also pleasant, as was driving out through Surrey/Sussex. Henley/Marlow obviously worth a lunch. Still, it was swnowing there recently, wasn't it? As much as the kids used to love tobogganing down to Petersham gate, it's almost April and still 30C here so cop that! :-)
Cheers Richard Maher
PS. I bet you that if I knew what I was doing I wouldn't find the fact that there's only NSEW and Center such a limitation :-)
PPS. If I was holding a series of say employee photographs/images as blobs in a database, can anyone tell me how I would get one of them up into a web-browser without first having to export it to a .jpeg/.bmp/.gif file? I must have missed something? I know http servers/browsers are optimized to have seperate threads for uploading images but nonetheless, what's the alternative? Can I pass an BufferedImage back from an applet to Javascript? (And then what would it do with it without a SRC="#something"?)
> > > but not everyone who jumps in comes away with a health problem... > > [quoted text clipped - 21 lines] > > -- chris Arne Vajhøj - 23 Mar 2007 01:48 GMT > But before launching into Swing there is one niggle or possible > spanner-in-the-works I'd like to quiz you about, and that is "footprint" [quoted text clipped - 6 lines] > be sent over the network? Will my Class and JAR files be roughly the same > size? Is relative resource consumption (or body mass index) an issue? The Swing classes has been part of Java since version 1.2.
Your code may actually shrink a little bit in size because you may replace some of your code with builtin Swing functionality.
Swing apps do tend to use some memory. But would not consider it a problem on any PC that is not completely outdated.
> PPS. If I was holding a series of say employee photographs/images as blobs > in a database, can anyone tell me how I would get one of them up into a [quoted text clipped - 3 lines] > alternative? Can I pass an BufferedImage back from an applet to Javascript? > (And then what would it do with it without a SRC="#something"?) You can do a IMG tag with SRC pointing to a server side script that sends the image from the database to the browser with the correct content type.
Or you can use an applet that retrieves the images via socket and displays it within the applet.
Arne
Lew - 23 Mar 2007 22:33 GMT Richard Maher wrote:
>> PPS. If I was holding a series of say employee photographs/images as >> blobs [quoted text clipped - 6 lines] >> Javascript? >> (And then what would it do with it without a SRC="#something"?)
> You can do a IMG tag with SRC pointing to a server side script that > sends the image from the database to the browser with the correct > content type. > > Or you can use an applet that retrieves the images via socket > and displays it within the applet. If you are running a servlet engine you can have a servlet stream the image, and use that servlet as the img tag's src.
I recently implemented such a thing after googling around for some code.
-- Lew
Richard Maher - 24 Mar 2007 02:20 GMT Hi Lew,
Thanks for the reply.
> If you are running a servlet engine you can have a servlet stream the image, > and use that servlet as the img tag's src. Is the magic in the URL? Can I see the whole <img> tag? Or does the http request not change and it's the server that let's you specify a DSO other than a file to satisfy the GET?
Cheers Richard Maher
> Richard Maher wrote: > >> PPS. If I was holding a series of say employee photographs/images as [quoted text clipped - 21 lines] > > -- Lew Lew - 24 Mar 2007 05:04 GMT "Lew" <lew@nospam.lewscanon.com> wrote...
>> If you are running a servlet engine you can have a servlet stream the image, >> and use that servlet as the img tag's src.
> Is the magic in the URL? Can I see the whole <img> tag? Or does the http > request not change and it's the server that let's you specify a DSO other > than a file to satisfy the GET? Did you try googling for this information? That's how I learned it.
Your servlet has a URL just like any servlet. The img tag takes a URL. Let's say you call your web app "foo" and have your image servlet mapped to "Display", looking for a parameter "name".
<img src="Display?name=myimage.jpg" />
Your Display servlet would have lines its doGet() something like
byte [] image = getImageBytes(); OutputStream os = response.getOutputStream(); os.write( image ); os.flush();
-- Lew
"Google is way bigger then Viacom. They've even got their own verb!" - The Daily Show, 2007-03-22
Richard Maher - 24 Mar 2007 01:22 GMT Hi Arne,
Thanks for the reply.
> Or you can use an applet that retrieves the images via socket > and displays it within the applet. This is very important to me. Are you really saying "can" or "as far as I know you used to be able to"? Are you referring to Microsoft's implementation of Data Source Objects in Internet Explorer or something else? The reason that I am so sceptical is that I asked the following question xposted here and c.l.javascript a while back: -
----- Original Message ----- From: "Richard Maher" <maher_rj@hotspamnotmail.com> Newsgroups: comp.lang.java.programmer,comp.lang.javascript Sent: Saturday, March 10, 2007 9:24 AM Subject: Applet as DSO in Browser example? MSIE only?
> Hi, > > Recently on the web I came across documentation discussing Data Source > Objects (DSO) in relation to browser and html functionality (in particular > the ability to declare a Java applet as a data source that can be used with
> any or the HTML tags that take the src="" attribute). I find it interesting
> and potentially *very* useful and would like to know more, so if anyone can
> answer any of the following questions that would be great: - > > 1) Do you have an example of an Applet functioning as an applet to something
> like a <Table> that I can see? > [quoted text clipped - 11 lines] > .JPEGs are designed for parallel http webservers, but think of a blob in a > database that has an employee photo of geological survey or something. . .)
> Thanks for any help! > > Regards Richard Maher > > PS. I am already passing result set <options>s back to a <select> list quite
> happily; it's the tighter integration between the html tags and my socket > that I'm striving for here. > > One of the places I've been looking: - http://msdn.microsoft.com/library/default.asp?url=/workshop/author/databind/data sources.asp
. . .and the only answer I got was: - [ The reference to Java applet on MSDN is a bit mysterious to me. I guess for IE 4/5 Microsoft allowed to use their JVM for bridging to the needed ActiveX, so people could use either <object> or <applet> depending on personal preferences. In either case it is definitely in relation to the Microsoft own JVM which is not provided any more. It has nothing to do with Sun plugin. ]
It would be great if you could still do this! Do you (or anyone) have an example?
Hold on, I've just re-read what your post actually says and not what I wanted it to say "displays it within the applet." :-( I assume that means as opposed to displaying it within the browser?
Cheers Richard Maher
> > But before launching into Swing there is one niggle or possible > > spanner-in-the-works I'd like to quiz you about, and that is "footprint" [quoted text clipped - 31 lines] > > Arne Arne Vajhøj - 24 Mar 2007 01:34 GMT >> Or you can use an applet that retrieves the images via socket >> and displays it within the applet. [quoted text clipped - 4 lines] > else? The reason that I am so sceptical is that I asked the following > question xposted here and c.l.javascript a while back: - I am referring to showing the image within the applet.
Then it is 100% Java and has nothing to do with browser and JavaScript.
Yes. It is possible.
Arne
Richard Maher - 24 Mar 2007 03:35 GMT Hi Arne,
> I am referring to showing the image within the applet. > > Then it is 100% Java and has nothing to do with browser and JavaScript. > > Yes. It is possible. OK, so I stream the image off my socket and form a BufferedImage and then, having implemented/overriden/the-correct-terminology the paint(graphics g) method, I can g.drawImage(myBufferedImage) to output it to applet-reserved pixels in the browser. Am I getting warm? You couldn't throw in a few more dots to join up couldya?
I am honestly not being lazy, If you knew how much floundering I've had to do with other stuff (lying on my back, wee flippers flailing madly in the air) then sheer compassion, nay pity, would compel you to deliver a full-blown working example :-) Anyway, I'm on this full-time now (it's only money :-) but I really want to ramp-up my lightweight, full-throttle applet-uploader so people won't need to install some whale of a webserver just to gain access to this stuff.
I personnaly know of no application that needs to show a photo from an applet in a browser; if someone shows me then all I'm gonna do is let other people know about it as a "How To". So if anyone has the time/inclination for this then I'm sure many, including myself would be grateful. Web reference?
Cheers Richard Maher
PS. I presume the Browser calls paint() and if the image is changed then repaint() needs to be called? But isn't repaint under the component.container.window.frame.blah hierachy of classes and Graphics somewhere else? See how much I need that example :-)
> >> Or you can use an applet that retrieves the images via socket > >> and displays it within the applet. [quoted text clipped - 12 lines] > > Arne Arne Vajhøj - 25 Mar 2007 03:31 GMT >> I am referring to showing the image within the applet. >> [quoted text clipped - 7 lines] > pixels in the browser. Am I getting warm? You couldn't throw in a few more > dots to join up couldya? That is it.
http://java.sun.com/docs/books/tutorial/uiswing/components/applet.html#images http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html#applet
has an example (it reads the image bytes from the jar file instead of the socket, but I assume you have the bytes).
OK - it is also Swing. Searching for an AWT example finds:
http://www.realapplets.com/tutorial/ImageExample.html http://www.dgp.toronto.edu/~mjmcguff/learn/java/08-painting/
It must have been done a gazillion times.
Arne
Richard Maher - 24 Mar 2007 02:03 GMT Hi (again) Arne,
On second thoughts, this might not be so bad if I knew what I was doing.
Would it be fair to say that I could embed an Applet <Object> tag within a <DIV> or an <IFrame> and then have complete flexibility in positioning, size, style of whatever the applet paints "within" the browser? I'm guessing <object> attributes such as height and width can be manipulated with DOM like any other; is that right? This is beginning to sound pretty sexy!
I don't know enough about graphics and how paint() works, and I'm struggling to disassociate the Applet code from its html tag presence; Does anyone have a small example of this in progress? (Yes, I will do more RTFMing :-)
What if two tags call the same applet; does init() get called twice? Two instances of the applet of just one? two pannels,frames,canvasses and just one applet?
What if there are three Applets active in the frameset; How can they invoke each others methods without having been aware of each other at compile-time? Given the (at least by default) single-threading of browser-applet interaction, can I share the one socket connection between the three? Is there global memory/references?
I've got a JavaScript DOM (getElementById) identifier that lets JS lnow when I'm calling a given applet's methods but surely this handle/object-instance would be of little use in telling applet[2] about the existance of applet[1] (and its methods)?
I think this is getting into that dynamic activation stuff that you told me about (and I didn't understand :-) the first time - Sorry. An example would really, really help here though.
Let's start small - "An example of an Applet painting and Image in a browser" any takers? websites?
Cheers Richard Maher
> Hi Arne, > [quoted text clipped - 56 lines] > > > > One of the places I've been looking: - http://msdn.microsoft.com/library/default.asp?url=/workshop/author/databind/data sources.asp
> . . .and the only answer I got was: - > [ [quoted text clipped - 59 lines] > > > > Arne Arne Vajhøj - 25 Mar 2007 03:41 GMT > Would it be fair to say that I could embed an Applet <Object> tag within a > <DIV> or an <IFrame> and then have complete flexibility in positioning, > size, style of whatever the applet paints "within" the browser? I'm guessing > <object> attributes such as height and width can be manipulated with DOM > like any other; is that right? This is beginning to sound pretty sexy! I am not a JavaScript guy, but I think that it will be possible.
> What if two tags call the same applet; does init() get called twice? Two > instances of the applet of just one? two pannels,frames,canvasses and just > one applet? Good question.
I would assume that it is called once per instance.
> What if there are three Applets active in the frameset; How can they invoke > each others methods without having been aware of each other at compile-time? > Given the (at least by default) single-threading of browser-applet > interaction, can I share the one socket connection between the three? Is > there global memory/references? If I read:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6506118
correctly then it is supposed to run in same JVM and same classloader (but there is a bug in 1.6).
And if that is the case you can share static fields and singleton objects.
Have you considered using one instance of the applet with some panels (maybe tabbed panels) ?
> Let's start small - "An example of an Applet painting and Image in a > browser" any takers? websites? I posted some links in previous post.
The super simple (hello world style) is available at: http://www.vajhoej.dk/arne/eksperten/applet_image/
Arne
SSMelaNB@gmail.com - 29 Mar 2007 04:29 GMT What about making copy/paste functional? My understanding is that it is more difficult to do in swing.
Andrew Thompson - 29 Mar 2007 07:12 GMT On Mar 29, 1:29 pm, SSMel...@gmail.com wrote:
> What about making copy/paste functional? My understanding is that it > is more difficult to do in swing. Why would you say that? Some AWT components implemented Ctrl^c copy and Ctrl^v paste automatically (dependant on the underlying OS), but it was inconsistently supported.
Early Swing components did not at first implement this copy paste functionality (as far as I vaguely recall), but now they do. As such, it would be more reliable for modern VM's.
OTOH, copy/paste functionality implemented in code is equally as easy (or difficult, depending on how you look at it) in either Swing or AWT. It is the exact same classes for both.
Andrew T.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|