📄 index.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><html> <head> <title>Lesson: Learning Swing by Example (The Java™ Tutorials > Creating a GUI with JFC/Swing)</title><style type="text/css"> .FigureCaption { margin-left: 1in; margin-right: 1in; font-family: sans-serif; font-size: smaller; text-align: justify; } #TopBar_bl { background: url(../../images/java_bar_bl.gif) 0 100% no-repeat; width: 100%; height: 60px; } #TopBar_br { background: url(../../images/java_bar_br.gif) 100% 100% no-repeat; width: 100%; height: 60px; } #TopBar_tl { background: url(../../images/java_bar_tl.gif) 0 0 no-repeat; width: 100%; height: 60px; } #TopBar_tr { background: url(../../images/java_bar_tr.gif) 100% 0 no-repeat; width: 100%; height: 60px; } #TopBar { background: #35556B url(../../images/java_bar.gif); margin: 10px 10px 0 10px; height:60px; min-width:700px; color: white; font-family: sans-serif; font-weight: bold; } @media print { #BreadCrumbs, #Download { display: none; } } #TopBar_right { line-height: 14px; float: right; padding-top: 2px; padding-right: 30px; text-align: center; } @media print { #TopBar_right { display: none; } } #TopBar_right a { font-size: 12px; margin: 3px; padding: 0; } #TopBar a:visited, #TopBar a:link { color: white; text-decoration: none; } #TopBar a:hover, #TopBar a:active { background-color: white; color: #35556B; } #BreadCrumbs { padding: 4px 5px 0.5em 0; font-family: sans-serif; float: right; } #BreadCrumbs a { color: blue; } #BreadCrumbs a:visited, #BreadCrumbs a:link { text-decoration: none; } #BreadCrumbs a:hover, #BreadCrumbs a:active { text-decoration: underline; } #PageTitle { margin: 0 5px 0.5em 0; color: #E76F00; font-family: sans-serif; font-weight: bold; font-size: 20px; } .LeftBar_shown { width: 13em; float: left; margin-left: 10px; margin-top: 4px; margin-bottom: 2em; } @media print { .LeftBar_shown { display: none; } } .LeftBar_hidden { display: none; } #Footer { padding-top: 10px; padding-left: 10px; margin-right: 10px; } .NavBit { padding: 4px 5px 0.5em 0; font-family: sans-serif; } @media print { .NavBit { display: none; } } #TagNotes { text-align: right; font-size: smaller; font-family: sans-serif; } @media print { #TagNotes a:visited, #TagNotes a:link { color: #35556B; text-decoration: none; } } #Contents a, .NavBit a, #TagNotes a { color: blue } #TagNotes a:visited, #TagNotes a:link, #Contents a:visited, #Contents a:link, .NavBit a:visited, .NavBit a:link { text-decoration: none; } #TagNotes a:hover, #TagNotes a:active, #Contents a:hover, #Contents a:active, .NavBit a:hover, .NavBit a:active { text-decoration: underline; } #Contents { float: left; font-family: sans-serif; } @media print { #Contents { display: none; } } @media screen { div.PrintHeaders { display: none; } } .linkLESSON, .nolinkLESSON { margin-left: 0.5em; text-indent: -0.5em } .linkAHEAD, .nolinkAHEAD, .linkQUESTIONS, .nolinkQUESTIONS { margin-left: 1.5em; text-indent: -0.5em } .linkBHEAD, .nolinkBHEAD { margin-left: 2.5em; text-indent: -0.5em } .linkCHEAD, .nolinkCHEAD { margin-left: 3.5em; text-indent: -0.5em } .nolinkLESSON, .nolinkAHEAD, .nolinkBHEAD, .nolinkCHEAD, .nolinkQUESTIONS { font-weight: bold; color: #E76F00; } .MainFlow_indented { margin-right: 10px; margin-left: 15em; margin-bottom: 2em; } .MainFlow_wide { margin-right: 10px; margin-left: 10px; margin-bottom: 2em; } @media print { .MainFlow_indented, .MainFlow_wide { padding-top: 0; margin-top: 10px; margin-right: 10px; margin-left: 0; } } h3, h4, h5 { color: #E76F00; font-family: sans-serif; } #ToggleLeft { display: none; } /t</style><script type="text/javascript"> function leftBar() { var nameq = 'tutorial_showLeftBar=' var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookieString = cookies[i]; while (cookieString.charAt(0) == ' ') { cookieString = cookieString.substring(1, cookieString.length); } if (cookieString.indexOf(nameq) == 0) { cookieValue = cookieString.substring(nameq.length, cookieString.length); return cookieValue == 'yes'; } } return true; } function showLeft(b) { var contents = document.getElementById("LeftBar"); var main = document.getElementById("MainFlow"); var toggle = document.getElementById("ToggleLeft"); if (b) { contents.className = "LeftBar_shown"; main.className = "MainFlow_indented"; toggle.innerHTML = "Hide the TOC"; document.cookie = 'tutorial_showLeftBar=yes; path=/'; } else { contents.className = "LeftBar_hidden"; main.className = "MainFlow_wide"; toggle.innerHTML = "Show the TOC"; document.cookie = 'tutorial_showLeftBar=no; path=/'; } } function toggleLeft() { showLeft(document.getElementById("LeftBar").className == "LeftBar_hidden"); document.getElementById("ToggleLeft").blur(); } function load() { showLeft(leftBar()); document.getElementById("ToggleLeft").style.display="inline"; } </script> </head><body onload="load()"> <div id=TopBar> <div id=TopBar_tr> <div id=TopBar_tl> <div id=TopBar_br> <div id=TopBar_bl> <div id=TopBar_right> <a target="_blank" href="http://java.sun.com/javase/6/download.jsp">Download the JDK</a> <br> <a href="../../search.html" target="_blank">Search the Tutorials</a> <br> <a href="javascript:toggleLeft()" id="ToggleLeft">Hide the TOC</a> </div> </div> </div> </div> </div> </div> <div id=LeftBar> <div id=Contents> <div class="nolinkLESSON">Learning Swing by Example</div><div class="linkAHEAD"><a href="example1.html">Example One: Your First Swing Program</a></div><div class="linkAHEAD"><a href="example2.html">Example Two: <code>SwingApplication</code></a></div><div class="linkAHEAD"><a href="example3.html">Example Three: <code>CelsiusConverter</code></a></div><div class="linkAHEAD"><a href="example4.html">Example Four: An Improved <code>CelsiusConverter</code></a></div><div class="linkAHEAD"><a href="example5.html">Example Five: <code>LunarPhases</code></a></div><div class="linkAHEAD"><a href="example6.html">Example Six: <code>VoteDialog</code></a></div><div class="linkAHEAD"><a href="summary.html">Summary</a></div></div> </div> <div id=MainFlow class=MainFlow_indented> <div class=PrintHeaders> <b>Trail:</b> Creating a GUI with JFC/Swing </div> <div id=BreadCrumbs> <a href=../../index.html target=_top>Home Page</a> > <a href=../index.html target=_top>Creating a GUI with JFC/Swing</a> </div> <div class=NavBit> <a target=_top href=../start/index.html>« Previous</a> • <a target=_top href=../TOC.html>Trail</a> • <a target=_top href=example1.html>Next »</a> </div> <p style="text-align: center"> <a href=examples/index.html>Examples Index</a> </p> <div id=PageTitle>Lesson: Learning Swing by Example</div> <blockquote><!--Learning Swing by Example--><blockquote> <hr> <strong>This section has not yet been updated to reflect features and conventions of the latest release, JDK 6.0. </strong> <hr> </blockquote>This lesson explains the concepts you need to use Swing components in building a user interface. First we examine the simplest Swing application you can write. Then we present several progressively complicated examples of creating user interfaces using components in the <code>javax.swing</code> package. We cover several Swing components, such as buttons, labels, and text areas. The handling of events is also discussed, as are layout management and accessibility.This lesson ends with a set of questions and exercises so you can test yourself on what you抳e learned. <blockquote><hr><strong>Note:</strong> Most of the topics this lesson discusses are covered in depth in later lessons--for example, you can get detailed information on how to use components from <a class="TutorialLink" target="_top" href="../../uiswing/components/index.html">Using Swing Components</a>. This lesson is designed for readers who want to learnthe basics quickly by examining some simple examples. <hr></blockquote><blockquote><hr><strong>Note:</strong> You can download all the examples (including images) used in this trail from the <A HREF="examples/index.html">Example Index</A>.<hr></blockquote><dl><dt><B><a class="TutorialLink" target="_top" href="example1.html">Example One: Your First Swing Program</a></B></dt><dd>This small example has all the code that every Swing application must have.<P></dd><dt><B><a class="TutorialLink" target="_top" href="example2.html">Example Two: <code>SwingApplication</code></a></B></dt><dd>This section takes you through the code for a small Swing application.The topics covered include: look and feel, setting up buttons and labels, handling events, and adding borders. <P></dd><dt><B><a class="TutorialLink" target="_top" href="example3.html">Example Three: <code>CelsiusConverter</code></a></B></dt><dd>The third example, a program that converts a given temperature from Celsius to Fahrenheit, illustrates how to add an event listener to a text field and display the converted temperature on a label.<P></dd><dt><B><a class="TutorialLink" target="_top" href="example4.html">Example Four: An Improved <code>CelsiusConverter</code></a></B></dt><dd>The fourth example improves our temperature conversion exampleand illustrates how to add HTML and iconsto components, setting the default button and how to createa formatted text field.<P></dd><dt><B><a class="TutorialLink" target="_top" href="example5.html">Example Five: <code>LunarPhases</code></a></B></dt><dd>The fifth example covers how to set up multiple panels, compound borders, combo boxes, and how to load multiple images.<P></dd><dt><B><a class="TutorialLink" target="_top" href="example6.html">Example Six: <code>VoteDialog</code></a></B></dt><dd>You can vote for your favorite political candidate in the final example,<code>VoteDialog</code>. This application illustrates the use of radio buttons and dialogs.<P></dd><dt><B><a class="TutorialLink" target="_top" href="summary.html">Summary</a></B></dt><dd>A summary of important concepts covered in this section. <P></dd><dt><B><a class="TutorialLink" target="_top" href="../QandE/questions-learn.html">Questions and Exercises</a></B></dt><dd>Try these questions and exercises to test what you've learned in this lesson.<P></dd></dl><p> </blockquote> <div class=NavBit> <a href=../start/index.html>« Previous</a> • <a href=../TOC.html>Trail</a> • <a href=example1.html>Next »</a> </div> </div> <div id=Footer><div id=TagNotes> Problems with the examples? Try <a target="_blank" href=../../information/run-examples.html>Compiling and Running the Examples: FAQs</a>. <br> Complaints? Compliments? Suggestions? <a target="_blank" href="http://developer.sun.com/contact/tutorial_feedback.jsp">Give us your feedback</a>.<br><br> <a target="_blank" href="../../information/copyright.html">Copyright</a> 1995-2006 Sun Microsystems, Inc. All rights reserved. <span id=Download></span></div> </div> <div class=PrintHeaders> <b>Previous page:</b> Previous Lesson <br><b>Next page:</b> Example One: Your First Swing Program </div> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -