Content deleted Content added
importance=mid |
GreenC bot (talk | contribs) Add {{reflist-talk}} to #History (via reftalk bot) |
||
(29 intermediate revisions by 18 users not shown) | |||
Line 1:
{{WikiProject
{{WikiProject
{{WikiProject Java |importance=mid }}
}}
== More lightweight/heaviweigth discussion ==
Line 14 ⟶ 16:
I wondered about this, and found this article which seems kosher.
[[User:Ety uncertain|Ety uncertain]] ([[User talk:Ety uncertain|talk]]) 07:24, 30 June 2009 (UTC)
Line 39 ⟶ 41:
I think the example isn't great. I have removed the anonymous class, but really it just shows what a poor example it is.. something along these lines would be clearer.. [[User:Simonjl|Simonjl]]
: You, Simon, should read up on Swing's requirements in regard to thread safety. Your example handles components off of the EDT, which is SPECIFICALLY not correct. Do NOT spread knowledge you do not posses. [[User:Stolsvik|Stolsvik]] ([[User talk:Stolsvik|talk]]) 07:53, 30 June 2010 (UTC)
public class HelloWorld {
// NOTE NOTE!! THIS IS A INCORRECT AND BROKEN EXAMPLE.
// THE EXAMPLE HANDLES SWING COMPONENTS OFF OF THE EVENT DISPATCH THREAD.
// IT IS A THREADING AND CORRECTNESS DISASTER IN WAITING. [[User:Stolsvik|Stolsvik]] ([[User talk:Stolsvik|talk]]) 07:53, 30 June 2010 (UTC)
public static void main(String[] arg) {
JFrame f = new JFrame ("Hello, World!");
f.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE);
Line 51 ⟶ 57:
EventQueue.invokeLater (new Thread());
}
}'''
This is a cleaned up version of HelloWorld.java
<pre>
import javax.swing.JFrame;
import javax.swing.JLabel;
public class HelloWorld implements Runnable
{
public void run()
{
JFrame f = new JFrame ("Hello, World!");
f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
f.getContentPane().add (new JLabel("Hello, World!"));
f.pack();
f.setVisible(true);
}
public static void main(String[] args)
{
HelloWorld hw = new HelloWorld();
javax.swing.SwingUtilities.invokeLater (hw);
}
}
</pre>
[[User:Ncmathsadist|Ncmathsadist]] ([[User talk:Ncmathsadist|talk]]) 00:24, 29 January 2012 (UTC)ncmathsadist
=== Cryptic example ===
What's the Event Dispatch Thread?
This is where the event queue lives. Events come from the user; they consist of such things as mouse clicks, button clicks, menu selections keystrokes and other interactions between the program user and the GUI. As these occur, they are registered onto the event queue. This queue lives in a single thread, so the events are serviced in the order in which they arrive. Were this not so, the application would behave in a manner disconcerting to the user.
[[User:Ncmathsadist|Ncmathsadist]] ([[User talk:Ncmathsadist|talk]]) 00:35, 29 January 2012 (UTC)ncmathsadist
What's an anonymous Runnable class?
The runnable interface is a contract requiring the implementation of the method
<pre>public void run()</pre>
You can create a nameless class as follows.
<pre>
new Runnable(){
public void run()
{
.....
}
}
</pre>
Such a class is an anonymous runnable class.
[[User:Ncmathsadist|Ncmathsadist]] ([[User talk:Ncmathsadist|talk]]) 00:35, 29 January 2012 (UTC)ncmathsadist
Why do I have to go to the Concurrency tutorial to just show a label and a button? What rules changed in 2004? OK I don't really ask these questions, but I doubt that anyone who don't know about Swing will understand something about Swing with the example. Maybe he will understand that Swing is an overcomplicated affair and that he should stay clear of it and use Flex or C# instead ;) I'm kidding because I love to use Swing, but I doubt that in it's current state this example is useful at all, even if it is legit. [[User:Hervegirod|Hervegirod]] ([[User talk:Hervegirod|talk]]) 00:31, 6 November 2009 (UTC)
Use the outline I placed in the article itself. Do not use wildcard imports as the person who modified it did.
[[User:Ncmathsadist|Ncmathsadist]] ([[User talk:Ncmathsadist|talk]]) 00:35, 29 January 2012 (UTC)ncmathsadist
:Yes this is a bit awkward. However it only requires 4 lines
<pre>
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
....
}});
</pre>
:of standard boiler plate code to get thread safe behaviour. You can miss this out and it will probably work. However, I don't think it would be right to show technically incorrect code and bad practice.
:One way of organising this would be to have a code fragment first with just the Swing bits. Then introducing the threading example later.--[[User:Salix alba|Salix]] ([[User talk:Salix alba|talk]]): 07:34, 6 November 2009 (UTC)
::It's a few years later, but I've added a better explanation as to why we are using the EDT. I also note that you can indeed run code without it, but that it's considered better form to use SwingUtilities.invokeLater(). [[User:Thunderforge|Thunderforge]] ([[User talk:Thunderforge|talk]]) 15:20, 28 October 2013 (UTC)
== JAVA SWING ==
Line 59 ⟶ 135:
'''Swing''' is a set of classes that provides more powerful and flexible functionality that is possible with standard and advanced '''AWT(Abstract Window Toolkit)''' components.These are not implemented by platform specific code. Instead they are written entirely in Java, therefore, they are platform independent.
Fundamentals of swing is the '''JApplet''' class that extends the '''Applet''' class. Applets that use Swing must be subclasses of the '''JApplet''' class <small>—The preceding [[Wikipedia:Signatures|unsigned]] comment was added by [[User:AbhishekDutta1987|AbhishekDutta1987]] ([[User talk:AbhishekDutta1987|talk]] • [[Special:Contributions/AbhishekDutta1987|contribs]]) 02:22, 1 May 2007 (UTC{{{3|}}})</small>
The article says that Swing is derived from Applet. This is not true in the strict sense. Applet does not appear in the inheritance tree of most Swing components.
[[User:Ncmathsadist|Ncmathsadist]] ([[User talk:Ncmathsadist|talk]]) 01:02, 29 January 2012 (UTC)ncmathsadist
== Origin of Name ==
Line 67 ⟶ 146:
[[User:Jon914|Jon914]] 18:38, 15 September 2007 (UTC)
:[http://web.archive.org/web/20090426192821/http://blogs.sun.com/thejavatutorials/entry/why_is_swing_called_swing archived copy (April 26, 2009)] Would this be considered a reliable source for citation, or <heavy sarcasm - maybe> should I send an email to Sharon Zakhour asking for an official quote from Jeff Dinkins (one of the original Swing engineers at Sun), and whether I can that email on WikiMedia so it becomes part of the Collective Sourced Quotes Of The Age and can be properly cited?<sarcasm>
== Hello world ==
Line 88 ⟶ 169:
Every GUI framework that puts pixels on screens are single threaded, it's just a question of how they present it to the user. Flex disallows threading entirely, for example. Really Swing has only one thread allowed to touch pixels and objects representing the widgets, but any number of threads that can do anything else. Swing is merely upfront about it's nature. [[Special:Contributions/75.173.228.67|75.173.228.67]] ([[User talk:75.173.228.67|talk]]) 04:43, 28 June 2009 (UTC)
== download ==
Line 110 ⟶ 177:
That code at the end is a mess. I've written cleaner code and I'm 13. --[[Special:Contributions/75.166.224.107|75.166.224.107]] ([[User talk:75.166.224.107|talk]]) 21:41, 22 November 2009 (UTC)
I rewrote this code. Someone has changed it to use wildcard importing, which I do not consider good style. It violates the principle of keeping namespaces small. You always want to know exactly what classes you are making visible.
You will notice that I made the whole class a Runnable so you do not need an anonymous class in the main method. You just instantiate
the class and pass it to javax.swing.SwingUtilities.invokeLater(). <small><span class="autosigned">— Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[User:Ncmathsadist|Ncmathsadist]] ([[User talk:Ncmathsadist|talk]] • [[Special:Contributions/Ncmathsadist|contribs]]) 00:13, 29 January 2012 (UTC)</span></small><!-- Template:Unsigned --> <!--Autosigned by SineBot-->
== Use on the web ==
Added section about possibility to use Swing on web with third party product (similar section to for example [[Standard_Widget_Toolkit#Use_on_the_web|http://en.wikipedia.org/wiki/Standard_Widget_Toolkit#Use_on_the_web]]).
Change reveted by Salix_alba (reason: advert for AjaxSwing). Don't want to advert anything, want to show web possibility of Swing as compared to SWT, currently shows SWT as having that advantage over Swing. Would be glad to hear any comments or suggestions on that revision. <span style="font-size: smaller;" class="autosigned">—Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/79.135.222.215|79.135.222.215]] ([[User talk:79.135.222.215|talk]]) 18:18, 20 October 2010 (UTC)</span><!-- Template:UnsignedIP --> <!--Autosigned by SineBot-->
== External links modified ==
Hello fellow Wikipedians,
I have just modified {{plural:1|one external link|1 external links}} on [[Swing (Java)]]. Please take a moment to review [https://en.wikipedia.org/w/index.php?diff=prev&oldid=713592355 my edit]. If you have any questions, or need the bot to ignore the links, or the page altogether, please visit [[User:Cyberpower678/FaQs#InternetArchiveBot|this simple FaQ]] for additional information. I made the following changes:
*Corrected formatting/usage for http://www.sun.com/smi/Press/sunflash/1998-12/sunflash.981208.9.xml
When you have finished reviewing my changes, please set the ''checked'' parameter below to '''true''' or '''failed''' to let others know (documentation at {{tlx|Sourcecheck}}).
{{sourcecheck|checked=false}}
Cheers.—[[User:Cyberbot II|<sup style="color:green;font-family:Courier">cyberbot II</sup>]]<small><sub style="margin-left:-14.9ex;color:green;font-family:Comic Sans MS">[[User talk:Cyberbot II|<span style="color:green">Talk to my owner</span>]]:Online</sub></small> 22:44, 4 April 2016 (UTC)
== Why this example is needed? ==
I do not understand why the following example "[[Swing (Java)|Game]]" is needed in this article. This article is meant as a clear and concise description of the Swing widget toolkit not as a tutorial. Wikipedia articles provide information not serve as tutorials, there are other resources for that. If we take a look at the articles of other widget-toolkits I'm sure we won't find a "game-example".
Moreover the code in this example isn't very good Java code. It uses deprecated features and is certainly not well-written. The wording of the given explanation is also not clear and for some reason the text "File:C:\Users\Travor\Pictures\GameSample.png|thumb|class MoveObj run in Windows NT 6.2" has been inserted below it.--[[User:Furquanahmad|Furquanahmad]] ([[User talk:Furquanahmad|talk]]) 17:02, 13 May 2016 (UTC)
<syntaxhighlight lang="java">
package org.travor.game;
import javax.swing.*;
import java.awt.event.*;
@SuppressWarnings("serial")
public class MoveObj extends JFrame {
private JButton
obj=new JButton("obj"),
up=new JButton("Up"),
dn=new JButton("Down"),
lf=new JButton("Left"),
Rt=new JButton("Right");
@SuppressWarnings("deprecation")
public MoveObj(){
super("Game");
this.getContentPane().setLayout(null);
this.setBounds(100, 50, 600, 620);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.add(makeObj());
this.add(makeUpBtn());
this.add(makeDnBtn());
this.add(makeLfBtn());
this.add(makeRtBtn());
this.show();
}
private JButton makeObj(){
obj.setBounds(0, 0, 60, 60);
return obj;
}
private JButton makeUpBtn(){
up.setBounds(0,500,100,60);
up.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Integer a=obj.getY();
if(a.toString().equalsIgnoreCase("0"))
return;
obj.setLocation(obj.getX(),a-60);
}
});
return up;
}
private JButton makeDnBtn(){
dn.setBounds(100,500,100,60);
dn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Integer a=obj.getY();
if(a.toString().equalsIgnoreCase("420"))
return;
obj.setLocation(obj.getX(),a+60);
}
});
return dn;
}
private JButton makeLfBtn(){
lf.setBounds(200,500,100,60);
lf.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Integer a=obj.getX();
if(a.toString().equalsIgnoreCase("0"))
return;
obj.setLocation(a-60,obj.getY());
}
});
return lf;
}
private JButton makeRtBtn(){
Rt.setBounds(300,500,100,60);
Rt.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Integer a=obj.getX();
if(a.toString().equalsIgnoreCase("420"))
return;
obj.setLocation(a+60,obj.getY());
}
});
return Rt;
}
public static void main(String[] args) {
new MoveObj();
}
}
</syntaxhighlight>
* Hi [[User:Furquanahmad|Furquanahmad]] I agree its not needed and adds nothing so I have removed it. [[User:KylieTastic|KylieTastic]] ([[User talk:KylieTastic|talk]]) 15:02, 14 May 2016 (UTC)
== History ==
I added people who were on the Swing team to the history, along with sources. However, one source was not accepted.<ref>{{cite web |last1=Fowler |first1=Amy |title=Circa 1996 |url=https://amyfowlersblog.wordpress.com/2011/07/28/circa-1996/ |website=Aim's Blog}}</ref> I am not sure if there is another way of finding the information.
{{reflist-talk}}
== JavaFX successor POV issue ==
There are currently three mentions in the article text to JavaFX as Swing's 'successor', which seems strange to me, as they have different goals. Also, as time has shown, Swing is still in the base JDK/JRE, while JavaFX was jettisoned into an independent library.
The successor claims seem to be uncited, and [https://xtools.wmcloud.org/blame/en.wikipedia.org/Swing_%28Java%29/?q=successor blame suggests] the mentions were introduced arbitrarily by proponents of JavaFX. I propose removing them. [[User:Chabala|Chabala]] ([[User talk:Chabala|talk]]) 05:36, 20 March 2024 (UTC)
|