资源简介
JAVA核心技术卷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.length; 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个文件信息
相关资源
- JAVA JSP公司财务管理系统 源代码 论文
- JSP+MYSQL旅行社管理信息系统
- 推荐算法的JAVA实现
- 基于Java的酒店管理系统源码(毕业设
- java-图片识别 图片比较
- android毕业设计
- java23种设计模式+23个实例demo
- java Socket发送/接受报文
- JAVA828436
- java界面美化 提供多套皮肤直接使用
- 在线聊天系统(java代码)
- 基于Java的图书管理系统807185
- java中实现将页面数据导入Excel中
- java 企业销售管理系统
- java做的聊天系统(包括正规课程设计
- Java编写的qq聊天室
- 商店商品管理系统 JAVA写的 有界面
- JAVA开发聊天室程序
- 在linux系统下用java执行系统命令实例
- java期末考试试题两套(答案) 选择(
- JAVA3D编程示例(建模、交互)
- Java 文件加密传输
- java做的房产管理系统
- 基于jsp的bbs论坛 非常详细
- [免费]java实现有障碍物的贪吃蛇游戏
- java Servlet投票实例
- 操作系统作业 (pv,作业管理,等5个
- 基于C/S架构考试系统(Java)
- java access 仓库管理系统 源码
- 一元多项式相加 java实现
评论
共有 条评论