<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_by_API%2Fjava.awt%2FFocusTraversalPolicy</id>
		<title>Java by API/java.awt/FocusTraversalPolicy - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_by_API%2Fjava.awt%2FFocusTraversalPolicy"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_by_API/java.awt/FocusTraversalPolicy&amp;action=history"/>
		<updated>2026-04-23T02:37:00Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_by_API/java.awt/FocusTraversalPolicy&amp;diff=1153&amp;oldid=prev</id>
		<title> в 17:43, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_by_API/java.awt/FocusTraversalPolicy&amp;diff=1153&amp;oldid=prev"/>
				<updated>2010-05-31T17:43:48Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 17:43, 31 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_by_API/java.awt/FocusTraversalPolicy&amp;diff=1154&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_by_API/java.awt/FocusTraversalPolicy&amp;diff=1154&amp;oldid=prev"/>
				<updated>2010-05-31T14:31:03Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== extends FocusTraversalPolicy ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.awt.ruponent;&lt;br /&gt;
import java.awt.Container;&lt;br /&gt;
import java.awt.FocusTraversalPolicy;&lt;br /&gt;
import java.awt.GridLayout;&lt;br /&gt;
import java.util.Map;&lt;br /&gt;
import java.util.SortedMap;&lt;br /&gt;
import java.util.TreeMap;&lt;br /&gt;
import javax.swing.JButton;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
import javax.swing.JPanel;&lt;br /&gt;
public class FocusTraversalExample extends JPanel {&lt;br /&gt;
 public FocusTraversalExample() {&lt;br /&gt;
     setLayout(new GridLayout(6, 1));&lt;br /&gt;
     add(new JButton(&amp;quot;A&amp;quot;));&lt;br /&gt;
     add(new JButton(&amp;quot;D&amp;quot;));&lt;br /&gt;
     &lt;br /&gt;
     add(new JButton(&amp;quot;C&amp;quot;));&lt;br /&gt;
     &lt;br /&gt;
     add(new JButton(&amp;quot;E&amp;quot;));&lt;br /&gt;
     add(new JButton(&amp;quot;B&amp;quot;));&lt;br /&gt;
     add(new JButton(&amp;quot;F&amp;quot;));&lt;br /&gt;
 }&lt;br /&gt;
 public static void main(String[] args) {&lt;br /&gt;
     JFrame frame = new JFrame();&lt;br /&gt;
     frame.setFocusTraversalPolicy(new AlphaButtonPolicy());&lt;br /&gt;
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;
     frame.setContentPane(new FocusTraversalExample());&lt;br /&gt;
     frame.setSize(400, 300);&lt;br /&gt;
     frame.setVisible(true);&lt;br /&gt;
 }&lt;br /&gt;
}&lt;br /&gt;
class AlphaButtonPolicy extends FocusTraversalPolicy {&lt;br /&gt;
  private SortedMap getSortedButtons(Container focusCycleRoot) {&lt;br /&gt;
    if (focusCycleRoot == null) {&lt;br /&gt;
      throw new IllegalArgumentException(&amp;quot;focusCycleRoot can&amp;quot;t be null&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    SortedMap result = new TreeMap(); // Will sort all buttons by text.&lt;br /&gt;
    sortRecursive(result, focusCycleRoot);&lt;br /&gt;
    return result;&lt;br /&gt;
  }&lt;br /&gt;
  private void sortRecursive(Map buttons, Container container) {&lt;br /&gt;
    for (int i = 0; i &amp;lt; container.getComponentCount(); i++) {&lt;br /&gt;
      Component c = container.getComponent(i);&lt;br /&gt;
      if (c instanceof JButton) { // Found another button to sort.&lt;br /&gt;
        buttons.put(((JButton) c).getText(), c);&lt;br /&gt;
      }&lt;br /&gt;
      if (c instanceof Container) { // Found a container to search.&lt;br /&gt;
        sortRecursive(buttons, (Container) c);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  // The rest of the code implements the FocusTraversalPolicy interface.&lt;br /&gt;
  public Component getFirstComponent(Container focusCycleRoot) {&lt;br /&gt;
    SortedMap buttons = getSortedButtons(focusCycleRoot);&lt;br /&gt;
    if (buttons.isEmpty()) {&lt;br /&gt;
      return null;&lt;br /&gt;
    }&lt;br /&gt;
    return (Component) buttons.get(buttons.firstKey());&lt;br /&gt;
  }&lt;br /&gt;
  public Component getLastComponent(Container focusCycleRoot) {&lt;br /&gt;
    SortedMap buttons = getSortedButtons(focusCycleRoot);&lt;br /&gt;
    if (buttons.isEmpty()) {&lt;br /&gt;
      return null;&lt;br /&gt;
    }&lt;br /&gt;
    return (Component) buttons.get(buttons.lastKey());&lt;br /&gt;
  }&lt;br /&gt;
  public Component getDefaultComponent(Container focusCycleRoot) {&lt;br /&gt;
    return getFirstComponent(focusCycleRoot);&lt;br /&gt;
  }&lt;br /&gt;
  public Component getComponentAfter(Container focusCycleRoot, Component aComponent) {&lt;br /&gt;
    if (!(aComponent instanceof JButton)) {&lt;br /&gt;
      return null;&lt;br /&gt;
    }&lt;br /&gt;
    SortedMap buttons = getSortedButtons(focusCycleRoot);&lt;br /&gt;
    // Find all buttons after the current one.&lt;br /&gt;
    String nextName = ((JButton) aComponent).getText() + &amp;quot;\0&amp;quot;;&lt;br /&gt;
    SortedMap nextButtons = buttons.tailMap(nextName);&lt;br /&gt;
    if (nextButtons.isEmpty()) { // Wrapped back to beginning&lt;br /&gt;
      if (!buttons.isEmpty()) {&lt;br /&gt;
        return (Component) buttons.get(buttons.firstKey());&lt;br /&gt;
      }&lt;br /&gt;
      return null; // Degenerate case of no buttons.&lt;br /&gt;
    }&lt;br /&gt;
    return (Component) nextButtons.get(nextButtons.firstKey());&lt;br /&gt;
  }&lt;br /&gt;
  public Component getComponentBefore(Container focusCycleRoot, Component aComponent) {&lt;br /&gt;
    if (!(aComponent instanceof JButton)) {&lt;br /&gt;
      return null;&lt;br /&gt;
    }&lt;br /&gt;
    SortedMap buttons = getSortedButtons(focusCycleRoot);&lt;br /&gt;
    SortedMap prevButtons = // Find all buttons before this one.&lt;br /&gt;
    buttons.headMap(((JButton) aComponent).getText());&lt;br /&gt;
    if (prevButtons.isEmpty()) { // Wrapped back to end.&lt;br /&gt;
      if (!buttons.isEmpty()) {&lt;br /&gt;
        return (Component) buttons.get(buttons.lastKey());&lt;br /&gt;
      }&lt;br /&gt;
      return null; // Degenerate case of no buttons.&lt;br /&gt;
    }&lt;br /&gt;
    return (Component) prevButtons.get(prevButtons.lastKey());&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>