資源簡介
JAVA核心技術(shù)卷2全部源代碼
官方

代碼片段和文件信息
import?java.awt.*;
import?java.awt.geom.*;
import?java.awt.event.*;
import?java.util.*;
import?java.util.concurrent.*;
import?javax.swing.*;
/**
???This?program?animates?a?sort?algorithm.
*/
public?class?AlgorithmAnimation
{
???public?static?void?main(String[]?args)
???{
??????Jframe?frame?=?new?Animationframe();
??????frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
??????frame.setVisible(true);
???}
}
/**
???This?frame?shows?the?array?as?it?is?sorted?together?with?buttons?to?single-step?the?animation
???or?to?run?it?without?interruption.
*/
class?Animationframe?extends?Jframe
{
???public?Animationframe()
???{
??????ArrayPanel?panel?=?new?ArrayPanel();
??????add(panel?BorderLayout.CENTER);
??????Double[]?values?=?new?Double[VALUES_LENGTH];
??????final?Sorter?sorter?=?new?Sorter(values?panel);
??????JButton?runButton?=?new?JButton(“Run“);
??????runButton.addActionListener(new
?????????ActionListener()
?????????{
????????????public?void?actionPerformed(ActionEvent?event)
????????????{
???????????????sorter.setRun();
????????????}
?????????});
??????JButton?stepButton?=?new?JButton(“Step“);
??????stepButton.addActionListener(new
?????????ActionListener()
?????????{
????????????public?void?actionPerformed(ActionEvent?event)
????????????{
???????????????sorter.setStep();
????????????}
?????????});
??????JPanel?buttons?=?new?JPanel();
??????buttons.add(runButton);
??????buttons.add(stepButton);?????
??????add(buttons?BorderLayout.NORTH);
??????setSize(DEFAULT_WIDTH?DEFAULT_HEIGHT);
??????for?(int?i?=?0;?i??????????values[i]?=?new?Double(Math.random());
??????Thread?t?=?new?Thread(sorter);
??????t.start();
???}
???private?static?final?int?DEFAULT_WIDTH?=?300;
???private?static?final?int?DEFAULT_HEIGHT?=?300;
???private?static?final?int?VALUES_LENGTH?=?30;
}
/**
???This?runnable?executes?a?sort?algorithm.
???When?two?elements?are?compared?the?algorithm
???pauses?and?updates?a?panel.
*/
class?Sorter?implements?Runnable
{
???/**
??????Constructs?a?Sorter.
??????@param?values?the?array?to?be?sorted
??????@param?panel?the?panel?on?which?to?display?the?sorting?progress
???*/?????
???public?Sorter(Double[]?values?ArrayPanel?panel)
???{
??????this.values?=?values;
??????this.panel?=?panel;
??????this.gate?=?new?Semaphore(1);
??????this.run?=?false;
???}
???/**
??????Sets?the?sorter?to?“run“?mode.
???*/
???public?void?setRun()
???{
??????run?=?true;
??????gate.release();
???}
???/**
??????Sets?the?sorter?to?“step“?mode.
???*/
???public?void?setStep()??????
???{
??????run?=?false;
??????gate.release();
???}
???public?void?run()
???{
??????Comparator?comp?=?new
?????????Comparator()
?????????{
????????????public?int?compare(Double?i1?Double?i2)
????????????{
???????????????panel.setValues(values?i1?i2);
???????????????try
???????????????{
??????????????????if?(run)
?????????????????????Thread.sleep(DELAY);
??????????????????else
?????????????????????gate.acquire();
???????????????}
???????????????c
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2008-09-21?11:55??Source?Code\
?????文件??????????79??2008-09-10?13:53??Source?Code\CodeFans.net.url
?????目錄???????????0??2013-08-02?11:35??__MACOSX\
?????目錄???????????0??2013-08-02?11:35??__MACOSX\Source?Code\
?????文件?????????241??2008-09-10?13:53??__MACOSX\Source?Code\._CodeFans.net.url
?????目錄???????????0??2008-09-21?11:54??Source?Code\gutenberg\
?????文件??????163184??2001-10-27?13:59??Source?Code\gutenberg\alice30.txt
?????目錄???????????0??2013-08-02?11:35??__MACOSX\Source?Code\gutenberg\
?????文件?????????241??2001-10-27?13:59??__MACOSX\Source?Code\gutenberg\._alice30.txt
?????文件?????2689721??2001-10-27?13:59??Source?Code\gutenberg\crsto10.txt
?????文件?????????241??2001-10-27?13:59??__MACOSX\Source?Code\gutenberg\._crsto10.txt
?????文件?????????241??2008-09-21?11:54??__MACOSX\Source?Code\._gutenberg
?????目錄???????????0??2008-09-21?11:54??Source?Code\v2ch1\
?????目錄???????????0??2008-09-21?11:54??Source?Code\v2ch1\AlgorithmAnimation\
?????文件????????4526??2004-09-07?07:07??Source?Code\v2ch1\AlgorithmAnimation\AlgorithmAnimation.java
?????目錄???????????0??2013-08-02?11:35??__MACOSX\Source?Code\v2ch1\
?????目錄???????????0??2013-08-02?11:35??__MACOSX\Source?Code\v2ch1\AlgorithmAnimation\
?????文件?????????241??2004-09-07?07:07??__MACOSX\Source?Code\v2ch1\AlgorithmAnimation\._AlgorithmAnimation.java
?????文件?????????241??2008-09-21?11:54??__MACOSX\Source?Code\v2ch1\._AlgorithmAnimation
?????目錄???????????0??2008-09-21?11:54??Source?Code\v2ch1\BlockingQueueTest\
?????文件????????3376??2004-09-29?19:45??Source?Code\v2ch1\BlockingQueueTest\BlockingQueueTest.java
?????目錄???????????0??2013-08-02?11:35??__MACOSX\Source?Code\v2ch1\BlockingQueueTest\
?????文件?????????241??2004-09-29?19:45??__MACOSX\Source?Code\v2ch1\BlockingQueueTest\._BlockingQueueTest.java
?????文件?????????241??2008-09-21?11:54??__MACOSX\Source?Code\v2ch1\._BlockingQueueTest
?????目錄???????????0??2008-09-21?11:54??Source?Code\v2ch1\Bounce\
?????文件????????4096??2004-09-07?07:07??Source?Code\v2ch1\Bounce\Bounce.java
?????目錄???????????0??2013-08-02?11:35??__MACOSX\Source?Code\v2ch1\Bounce\
?????文件?????????241??2004-09-07?07:07??__MACOSX\Source?Code\v2ch1\Bounce\._Bounce.java
?????文件?????????241??2008-09-21?11:54??__MACOSX\Source?Code\v2ch1\._Bounce
?????目錄???????????0??2008-09-21?11:54??Source?Code\v2ch1\BounceThread\
?????文件????????4727??2004-09-07?07:07??Source?Code\v2ch1\BounceThread\BounceThread.java
............此處省略1089個文件信息
評論
共有 條評論