├── .gitattributes
├── .gitignore
├── .idea
├── Java-Swing-Projects.iml
├── inspectionProfiles
│ └── Project_Default.xml
├── misc.xml
├── modules.xml
├── sbt.xml
├── uiDesigner.xml
└── vcs.xml
├── README.md
├── com
└── ten
│ ├── demo
│ ├── Jar
│ │ ├── ResourceTest.java
│ │ └── ResourceTestFrame.java
│ ├── ball
│ │ ├── Ball.java
│ │ ├── BallComponent.java
│ │ ├── BounceFrame.java
│ │ └── BounceThread.java
│ ├── chart
│ │ └── BloodPresure.java
│ ├── dataExchange
│ │ ├── DataExchangeFrame.java
│ │ ├── PasswordChooser.java
│ │ └── User.java
│ ├── fileChooser
│ │ ├── FileIconView.java
│ │ ├── ImagePreviewer.java
│ │ └── ImageViewerFrame.java
│ ├── login
│ │ └── TextComponentFrame.java
│ ├── mouse
│ │ └── RobotTest.java
│ ├── panel
│ │ ├── Popup.java
│ │ └── TabbedPane.java
│ ├── reflection
│ │ └── ReflectionTest.java
│ ├── search
│ │ └── BlockingQueueSearcher.java
│ └── sin
│ │ ├── SineDraw.java
│ │ └── SineWave.java
│ └── sort
│ ├── ButtonComponent.java
│ ├── Mapping
│ ├── ButtonPanel.java
│ ├── CommonCanvas.java
│ ├── DerivativeCanvas.java
│ ├── FittingCanvas.java
│ ├── LinePanel.java
│ ├── MyCanvas.java
│ └── doMapping.java
│ ├── ProgressComponent.java
│ ├── RandomArray.java
│ ├── SelectComponent.java
│ ├── Sort.java
│ ├── SortExecutors.java
│ ├── SortFile
│ ├── ReadSortArray.java
│ ├── SaveSortArray.java
│ └── SortFile.java
│ ├── SortFrame.java
│ ├── SortPanel.java
│ ├── TextComponent.java
│ ├── dialogFrame
│ ├── ExDialog.java
│ └── TooBarFrame.java
│ ├── doSort.java
│ └── sortmethod
│ ├── Bubble_Sort.java
│ ├── Example.java
│ ├── Heap_Sort.java
│ ├── Insert_Sort.java
│ ├── Merge_Sort.java
│ ├── Quick_Sort.java
│ ├── Radix_Sort.java
│ ├── Select_Sort.java
│ └── Shell_Sort.java
├── out
└── production
│ └── Java-Swing-Projects
│ ├── .gitattributes
│ ├── .idea
│ ├── Java-Swing-Projects.iml
│ ├── inspectionProfiles
│ │ └── Project_Default.xml
│ ├── misc.xml
│ ├── modules.xml
│ ├── sbt.xml
│ ├── uiDesigner.xml
│ ├── vcs.xml
│ └── workspace.xml
│ ├── README.md
│ ├── com
│ └── ten
│ │ └── sort
│ │ ├── ButtonComponent.class
│ │ ├── Mapping
│ │ ├── ButtonPanel$1.class
│ │ ├── ButtonPanel$2.class
│ │ ├── ButtonPanel$3.class
│ │ ├── ButtonPanel.class
│ │ ├── CommonCanvas.class
│ │ ├── DerivativeCanvas.class
│ │ ├── FittingCanvas.class
│ │ ├── LinePanel$LineCanve.class
│ │ ├── LinePanel.class
│ │ ├── MyCanvas.class
│ │ └── doMapping.class
│ │ ├── ProgressComponent.class
│ │ ├── RandomArray.class
│ │ ├── SelectComponent.class
│ │ ├── Sort.class
│ │ ├── SortExecutors.class
│ │ ├── SortFile
│ │ ├── ReadSortArray.class
│ │ ├── SaveSortArray.class
│ │ └── SortFile.class
│ │ ├── SortFrame.class
│ │ ├── SortPanel.class
│ │ ├── TextComponent$1.class
│ │ ├── TextComponent$2.class
│ │ ├── TextComponent.class
│ │ ├── dialogFrame
│ │ ├── ExDialog.class
│ │ ├── TooBarFrame$ToolAction.class
│ │ └── TooBarFrame.class
│ │ ├── doSort.class
│ │ └── sortMethod
│ │ ├── Bubble_Sort.class
│ │ ├── Example.class
│ │ ├── Heap_Sort.class
│ │ ├── Insert_Sort.class
│ │ ├── Merge_Sort.class
│ │ ├── Quick_Sort.class
│ │ ├── Radix_Sort.class
│ │ ├── Select_Sort.class
│ │ └── Shell_Sort.class
│ ├── 主界面.png
│ ├── 拟合曲线.png
│ ├── 排序曲线.png
│ └── 排序过程.png
├── 主界面.png
├── 拟合曲线.png
├── 排序曲线.png
└── 排序过程.png
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | .idea/workspace.xml
3 |
--------------------------------------------------------------------------------
/.idea/Java-Swing-Projects.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/sbt.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Sort-Swing
2 |
3 | > 这是一个使用JavaSwing组件实现的桌面应用,它能够进行八种排序的时间复杂度计算,并将结果绘制图线或持久化到文件,最后对比八种算法的性能。
4 |
5 | ## 部署运行
6 | ```txt
7 | # Clone Project
8 | git clone https://github.com/kevinten10/Sort-Swing
9 |
10 | # 启动
11 | com.ten.sort: 运行Sort.java的main方法
12 | ```
13 |
14 | ## 其他DEMO
15 |
16 | > com.ten.domo文件下为基于Swing编程的实例应用,用于学习相关的方法
17 |
18 | ## 功能概述
19 | * 八大排序算法
20 | * 进度检测
21 | * 执行结果文件的保存和读取
22 | * 曲线的绘制
23 | * 曲线导数计算 绘制
24 | * 曲线拟合计算 绘制
25 | * 多线程操作
26 |
27 | ## 操作流程
28 | * 选择排序方式 或 导入文件
29 | * 点击按钮
30 | * 排序完成-->点击 绘制曲线
31 | * 三种功能 和 生成文件
32 |
33 | ## 主界面
34 |
35 | 
36 |
37 | 
38 |
39 | ### 绘图界面
40 |
41 | 
42 |
43 | 
44 |
--------------------------------------------------------------------------------
/com/ten/demo/Jar/ResourceTest.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.Jar;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 |
6 | public class ResourceTest {
7 | public static void main(String[] args) {
8 | EventQueue.invokeLater(() -> {
9 | JFrame frame = new ResourceTestFrame();
10 | frame.setTitle("ResourceTest");
11 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
12 | frame.setVisible(true);
13 | });
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/com/ten/demo/Jar/ResourceTestFrame.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.Jar;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 | import java.io.InputStream;
6 | import java.net.URL;
7 | import java.util.Scanner;
8 |
9 | public class ResourceTestFrame extends JFrame {
10 | private static final int DEFAULT_WIDTH = 300;
11 | private static final int DEFAULT_HEIGHT = 300;
12 |
13 | public ResourceTestFrame() {
14 | setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
15 | URL aboutURL = getClass().getResource("about.gif");
16 | Image img = new ImageIcon(aboutURL).getImage();
17 | setIconImage(img);
18 |
19 | JTextArea textArea = new JTextArea();
20 | InputStream stream = getClass().getResourceAsStream("about.txt");
21 | try (Scanner in = new Scanner(stream, "UTF-8")) {
22 | while (in.hasNext())
23 | textArea.append(in.nextLine() + "\n");
24 | }
25 | add(textArea);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/com/ten/demo/ball/Ball.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.ball;
2 |
3 | import java.awt.geom.Ellipse2D;
4 | import java.awt.geom.Rectangle2D;
5 |
6 | /**
7 | * Ball Object
8 | */
9 | class Ball {
10 | /**
11 | * Ball Size
12 | */
13 | private static final int XSIZE = 15;
14 | private static final int YSIZE = 15;
15 | /**
16 | * Ball Location
17 | */
18 | private double x = 0;
19 | private double y = 0;
20 | /**
21 | * Ball Moving Distance
22 | */
23 | private double dx = 1;
24 | private double dy = 1;
25 |
26 | /**
27 | * Move Method, If ball touch the edge, it will be rebound
28 | */
29 | void move(Rectangle2D bounds) {
30 | // 位置d距离
31 | x += dx;
32 | y += dy;
33 | // 碰触左边缘
34 | if (x < bounds.getMinX()) {
35 | x = bounds.getMinX();
36 | dx = -dx;
37 | }
38 | // 右边缘
39 | if (x + XSIZE >= bounds.getMaxX()) {
40 | x = bounds.getMaxX() - XSIZE;
41 | dx = -dx;
42 | }
43 | // 上边缘
44 | if (y < bounds.getMinY()) {
45 | y = bounds.getMinY();
46 | dy = -dy;
47 | }
48 | // 下边缘
49 | if (y + YSIZE >= bounds.getMaxY()) {
50 | y = bounds.getMaxY() - YSIZE;
51 | dy = -dy;
52 | }
53 | }
54 |
55 | /**
56 | * @return Ball Region
57 | */
58 | Ellipse2D getShape() {
59 | return new Ellipse2D.Double(x, y, XSIZE, YSIZE);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/com/ten/demo/ball/BallComponent.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.ball;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 | import java.util.ArrayList;
6 |
7 | /**
8 | * Balls Collection
9 | */
10 | public class BallComponent extends JPanel {
11 | private static final int DEFAULT_WIDTH = 450;
12 | private static final int DEFAULT_HEIGHT = 350;
13 |
14 | private java.util.List balls = new ArrayList<>();
15 |
16 | public void add(Ball ball) {
17 | balls.add(ball);
18 | }
19 |
20 | @Override
21 | protected void paintComponent(Graphics g) {
22 | super.paintComponent(g);
23 | Graphics2D g2 = (Graphics2D) g;
24 | for (Ball ball : balls) {
25 | g2.fill(ball.getShape());
26 | }
27 | }
28 |
29 | @Override
30 | public Dimension getPreferredSize() {
31 | return new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/com/ten/demo/ball/BounceFrame.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.ball;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 | import java.awt.event.ActionListener;
6 |
7 | /**
8 | * Frame
9 | */
10 | class BounceFrame extends JFrame {
11 | private BallComponent component;
12 | private static final int STEPS = 1000;
13 | private static final int DELAY = 5;
14 |
15 | BounceFrame() {
16 | component = new BallComponent();
17 | add(component, BorderLayout.CENTER);
18 | JPanel buttonPanel = new JPanel();
19 | addButton(buttonPanel, "Start", e -> addBall());
20 | addButton(buttonPanel, "End", e -> System.exit(0));
21 | add(buttonPanel, BorderLayout.SOUTH);
22 | pack();
23 | }
24 |
25 | private void addButton(Container c, String title, ActionListener listener) {
26 | JButton button = new JButton(title);
27 | c.add(button);
28 | button.addActionListener(listener);
29 | }
30 |
31 | private void addBall() {
32 | Ball ball = new Ball();
33 | component.add(ball);
34 | Runnable r = () -> {
35 | try {
36 | while (true) {
37 | ball.move(component.getBounds());
38 | component.repaint();
39 | Thread.sleep(DELAY);
40 | }
41 | } catch (InterruptedException e) {
42 | e.printStackTrace();
43 | }
44 | };
45 | Thread t = new Thread(r);
46 | t.start();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/com/ten/demo/ball/BounceThread.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.ball;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 |
6 | /**
7 | * Bounce Balls
8 | */
9 | public class BounceThread {
10 | public static void main(String[] args) {
11 | EventQueue.invokeLater(() -> {
12 | JFrame frame = new BounceFrame();
13 | frame.setTitle("BounceThread");
14 | frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
15 | frame.setVisible(true);
16 | });
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/com/ten/demo/chart/BloodPresure.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.chart;
2 |
3 | import java.awt.BasicStroke;
4 | import java.awt.BorderLayout;
5 | import java.awt.Canvas;
6 | import java.awt.Color;
7 | import java.awt.Graphics;
8 | import java.awt.Graphics2D;
9 | import java.awt.Image;
10 | import java.awt.event.ActionEvent;
11 | import java.awt.event.ActionListener;
12 | import javax.swing.JButton;
13 | import javax.swing.JFrame;
14 | import javax.swing.JLabel;
15 | import javax.swing.JPanel;
16 | import javax.swing.JTextField;
17 | import javax.swing.UIManager;
18 |
19 | /**
20 | * 血压变化趋势图,包括坐标轴,高压、低压基准线,动态高压、低压线,分度值等
21 | *
22 | * @author Freedoman
23 | * @Time 2014-1-1
24 | */
25 | public class BloodPresure extends JFrame {
26 |
27 | private static final long serialVersionUID = 1L;
28 | private Image iBuffer;
29 | private MyCanvas trendChartCanvas = new MyCanvas();
30 | private JTextField highPressText, lowPressText;
31 |
32 | // 框架起点坐标、宽高
33 | private final int FRAME_X = 100;
34 | private final int FRAME_Y = 100;
35 | private final int FRAME_WIDTH = 700;
36 | private final int FRAME_HEIGHT = 250;
37 |
38 | // 原点坐标
39 | private final int Origin_X = FRAME_X + 40;
40 | private final int Origin_Y = FRAME_Y + FRAME_HEIGHT - 30;
41 |
42 | // X轴、Y轴终点坐标
43 | private final int XAxis_X = FRAME_X + FRAME_WIDTH - 30;
44 | private final int XAxis_Y = Origin_Y;
45 | private final int YAxis_X = Origin_X;
46 | private final int YAxis_Y = FRAME_Y + 30;
47 |
48 | // X轴上的时间分度值(1分度=2天=40像素)
49 | private final int TIME_INTERVAL = 40;
50 |
51 | // y轴上血压分度值
52 | private final int PRESS_INTERVAL = 10;
53 |
54 | // 保存当前测量高压和低压值数组,数组长度计数器
55 | private int[] CurrentHighPressInput = {150, 150, 150, 150, 150, 150, 150,
56 | 150, 150, 150, 150, 150, 150, 150, 150, 150};
57 | private int[] CurrentLowPressInput = {75, 75, 75, 75, 75, 75, 75, 75, 75,
58 | 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75};
59 | private int CurrentPressInputLength = 1;
60 |
61 | public BloodPresure() {
62 |
63 | super("自定义血压趋势坐标图-FreeDoman");
64 | this.setDefaultCloseOperation(EXIT_ON_CLOSE);
65 | this.setBounds(300, 100, 900, 600);
66 |
67 | // 添加控制到框架北部区
68 | JPanel topPanel = new JPanel();
69 | this.add(topPanel, BorderLayout.NORTH);
70 |
71 | // 高压值与文本框
72 | highPressText = new JTextField(5);
73 | topPanel.add(new JLabel("高压值", JLabel.CENTER));
74 | topPanel.add(highPressText);
75 |
76 | // 低压值与文本框
77 | lowPressText = new JTextField(5);
78 | topPanel.add(new JLabel("低压值", JLabel.CENTER));
79 | topPanel.add(lowPressText);
80 |
81 | // 打点按钮与事件
82 | JButton pressButton = new JButton("打点");
83 | pressButton.addActionListener(new ActionListener() {
84 |
85 | // 把当前输入的高压和低压值
86 | @Override
87 | public void actionPerformed(ActionEvent arg0) {
88 |
89 | // 绘制当前输入的高压趋势
90 | int InputHighPress = Integer.parseInt(highPressText.getText());
91 | int InputLowPress = Integer.parseInt(lowPressText.getText());
92 | CurrentHighPressInput[CurrentPressInputLength] = InputHighPress;
93 | CurrentLowPressInput[CurrentPressInputLength] = InputLowPress;
94 | CurrentPressInputLength++;
95 | trendChartCanvas.repaint();
96 | // 输入文本框清零
97 | highPressText.setText("");
98 | lowPressText.setText("");
99 | }
100 | });
101 |
102 | topPanel.add(pressButton);
103 |
104 | // 添加画布到中央区
105 | this.add(trendChartCanvas, BorderLayout.CENTER);
106 | this.setResizable(false);
107 | this.setVisible(true);
108 | }
109 |
110 | /**
111 | * 画布重绘血压趋势图
112 | */
113 | class MyCanvas extends Canvas {
114 |
115 | private static final long serialVersionUID = 1L;
116 |
117 | public void paint(Graphics g) {
118 | Graphics2D g2D = (Graphics2D) g;
119 |
120 | // 画边框
121 | g.setColor(Color.BLACK);
122 | g.draw3DRect(FRAME_X, FRAME_Y, FRAME_WIDTH, FRAME_HEIGHT, true);
123 |
124 | // 画坐标轴
125 | g.setColor(Color.BLACK);
126 | g2D.setStroke(new BasicStroke(Float.parseFloat("2.0f")));
127 | // X轴及方向箭头
128 | g.drawLine(Origin_X, Origin_Y, XAxis_X, XAxis_Y);
129 | g.drawLine(XAxis_X, XAxis_Y, XAxis_X - 5, XAxis_Y - 5);
130 | g.drawLine(XAxis_X, XAxis_Y, XAxis_X - 5, XAxis_Y + 5);
131 | // Y轴及方向箭头
132 | g.drawLine(Origin_X, Origin_Y, YAxis_X, YAxis_Y);
133 | g.drawLine(YAxis_X, YAxis_Y, YAxis_X - 5, YAxis_Y + 5);
134 | g.drawLine(YAxis_X, YAxis_Y, YAxis_X + 5, YAxis_Y + 5);
135 |
136 | // 画X轴上时间刻度(从坐标原点起,每隔TIME_INTERVAL(时间分度)像素画一时间点,到X轴终点至)
137 | g.setColor(Color.BLUE);
138 | g2D.setStroke(new BasicStroke(Float.parseFloat("1.0f")));
139 | for (int i = Origin_X, j = 0; i < XAxis_X; i += TIME_INTERVAL, j += 2) {
140 | g.drawString("1-" + j, i - 10, Origin_Y + 20);
141 | }
142 | g.drawString("日期", XAxis_X + 5, XAxis_Y + 5);
143 |
144 | // 画Y轴上血压刻度(从坐标原点起,每隔10像素画一压力值,到Y轴终点至)
145 | for (int i = Origin_Y, j = 0; i > YAxis_Y; i -= PRESS_INTERVAL, j += 10) {
146 | g.drawString(j + "", Origin_X - 30, i + 3);
147 | }
148 | g.drawString("血压/mmgh", YAxis_X - 5, YAxis_Y - 5);
149 |
150 | // 画网格线
151 | g.setColor(Color.BLACK);
152 | // 横线
153 | for (int i = Origin_Y - PRESS_INTERVAL; i > YAxis_Y; i -= PRESS_INTERVAL) {
154 | g.drawLine(Origin_X, i, Origin_X + 15 * TIME_INTERVAL, i);
155 | }
156 | // 竖线
157 | for (int i = Origin_X + TIME_INTERVAL; i < XAxis_X; i += TIME_INTERVAL) {
158 | g.drawLine(i, Origin_Y, i, Origin_Y - 18 * PRESS_INTERVAL);
159 |
160 | }
161 |
162 | // 理想血压基准线
163 | // 高压
164 | g.setColor(Color.MAGENTA);
165 | g2D.setStroke(new BasicStroke(Float.parseFloat("2.0f")));
166 | g.drawLine(Origin_X, Origin_Y - 150, Origin_X + 15 * TIME_INTERVAL,
167 | Origin_Y - 150);
168 | g2D.setStroke(new BasicStroke(Float.parseFloat("1.0f")));
169 | g.drawString("理想高压线", Origin_X + 15 * TIME_INTERVAL + 3,
170 | Origin_Y - 150 + 3);
171 | // 低压
172 | g.setColor(Color.CYAN);
173 | g2D.setStroke(new BasicStroke(Float.parseFloat("2.0f")));
174 | g.drawLine(Origin_X, Origin_Y - 75, Origin_X + 15 * TIME_INTERVAL,
175 | Origin_Y - 75);
176 | g2D.setStroke(new BasicStroke(Float.parseFloat("1.0f")));
177 | g.drawString("理想低压线", Origin_X + 15 * TIME_INTERVAL + 3,
178 | Origin_Y - 75 + 3);
179 |
180 | // 当前测量高压线,循环画出高压数组CurrentHighPressInput[]中保存的线段
181 | g.setColor(Color.ORANGE);
182 | g2D.setStroke(new BasicStroke(Float.parseFloat("3.0f")));
183 |
184 | // 当前高压起点横坐标为CurrentHighPressStart_X,纵坐标为数组第一个,当前终点横坐标为CurrentHighPressStart_X
185 | // + TIMA_INTERVAL,纵坐标为数组第二个,依次类推画出各线段
186 | for (int i = 1, CurrentHighPressStart_X = Origin_X; i < CurrentPressInputLength; i++, CurrentHighPressStart_X += TIME_INTERVAL) {
187 | g.drawLine(CurrentHighPressStart_X, Origin_Y
188 | - CurrentHighPressInput[i - 1], CurrentHighPressStart_X
189 | + TIME_INTERVAL, Origin_Y - CurrentHighPressInput[i]);
190 | }
191 |
192 | // 当前测量低压线,循环画出低压数组CurrentLowPressInput[]中保存的线段
193 | g.setColor(Color.PINK);
194 | g2D.setStroke(new BasicStroke(Float.parseFloat("3.0f")));
195 | // 当前低压起点横坐标为CurrentHighPressStart_X,纵坐标为数组第一个,当前终点横坐标为CurrentLowPressStart_X
196 | // + TIMA_INTERVAL,纵坐标为数组第二个,依次类推画出各线段
197 | for (int i = 1, CurrentLowPressStart_X = Origin_X; i < CurrentPressInputLength; i++, CurrentLowPressStart_X += TIME_INTERVAL) {
198 | g.drawLine(CurrentLowPressStart_X, Origin_Y
199 | - CurrentLowPressInput[i - 1], CurrentLowPressStart_X
200 | + TIME_INTERVAL, Origin_Y - CurrentLowPressInput[i]);
201 | }
202 | }
203 |
204 | // 双缓冲技术解决图像显示问题
205 | public void update(Graphics g) {
206 | if (iBuffer == null) {
207 | iBuffer = createImage(this.getSize().width,
208 | this.getSize().height);
209 |
210 | }
211 | Graphics gBuffer = iBuffer.getGraphics();
212 | gBuffer.setColor(getBackground());
213 | gBuffer.fillRect(0, 0, this.getSize().width, this.getSize().height);
214 | paint(gBuffer);
215 | gBuffer.dispose();
216 | g.drawImage(iBuffer, 0, 0, this);
217 | }
218 | }
219 |
220 | public static void main(String[] args) {
221 |
222 | // 设置界面的外观,为系统外观
223 | try {
224 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
225 | } catch (Exception e) {
226 | e.printStackTrace();
227 | }
228 |
229 | new BloodPresure();
230 | }
231 | }
--------------------------------------------------------------------------------
/com/ten/demo/dataExchange/DataExchangeFrame.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.dataExchange;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 | import java.awt.event.ActionEvent;
6 | import java.awt.event.ActionListener;
7 |
8 | //数据交互对话框
9 | public class DataExchangeFrame extends JFrame {
10 | public static final int TEXT_ROWS = 20;
11 | public static final int TEXT_COLUMNS = 40;
12 | private PasswordChooser dialog = null;
13 | private JTextArea textArea;
14 |
15 | //构造函数,生成一个面板
16 | public DataExchangeFrame() {
17 | JMenuBar menuBar = new JMenuBar();
18 | setJMenuBar(menuBar);
19 | JMenu fileMenu = new JMenu("File");
20 | menuBar.add(fileMenu);
21 |
22 | JMenuItem connectItem = new JMenuItem("Connect");
23 | connectItem.addActionListener(new ConnectAction());
24 | fileMenu.add(connectItem);
25 |
26 | JMenuItem exitItem = new JMenuItem("Exit");
27 | exitItem.addActionListener(e -> System.exit(0));
28 | fileMenu.add(exitItem);
29 |
30 | textArea = new JTextArea(TEXT_ROWS, TEXT_COLUMNS);
31 | add(new JScrollPane((textArea)), BorderLayout.CENTER);
32 | pack();
33 | }
34 |
35 | //Connect按钮的事件监听类,能够打开信息交互窗口
36 | private class ConnectAction implements ActionListener {
37 | //dialog就是要打开的交互窗口
38 | @Override
39 | public void actionPerformed(ActionEvent e) {
40 | //当交互窗口不存在时,创建并初始化
41 | if (dialog == null) {
42 | dialog = new PasswordChooser();
43 | }
44 | dialog.setUser(new User("yourname", null));
45 | //当点击Ok(返回true)时,获取对话框信息,并显示在textArea上
46 | if (dialog.showDialog(DataExchangeFrame.this, "Connect")) {
47 | User u = dialog.getUser();
48 | textArea.append("user name=" + u.getUserName() + ",password=" + (new String(u.getPassword())) + "\n");
49 | }
50 | }
51 | }
52 |
53 | public static void main(String[] args) {
54 | JFrame frame = new DataExchangeFrame();
55 | frame.setVisible(true);
56 | frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
57 | frame.setSize(300, 300);
58 | frame.setLocation(200, 200);
59 | frame.pack();
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/com/ten/demo/dataExchange/PasswordChooser.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.dataExchange;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 |
6 | //交互面板 extends JPanel
7 | public class PasswordChooser extends JPanel {
8 | private JTextField username;
9 | private JPasswordField password;
10 | private JButton okButton;
11 | private boolean ok;
12 | private JDialog dialog;
13 |
14 | //创建面板
15 | public PasswordChooser() {
16 | setLayout(new BorderLayout());
17 |
18 | JPanel panel = new JPanel();
19 | panel.setLayout(new GridBagLayout());
20 | panel.add(new JLabel("username:"), new GBS(0, 0, 1, 1, 1, 1));
21 | panel.add(username = new JTextField(""), new GBS(1, 0, 1, 2, 2, 1));
22 | panel.add(new JLabel("password:"), new GBS(0, 1, 1, 1, 1, 1));
23 | panel.add(password = new JPasswordField(""), new GBS(1, 1, 1, 2, 2, 1));
24 | add(panel, BorderLayout.CENTER);
25 | //Ok按钮事件
26 | okButton = new JButton("OK");
27 | okButton.addActionListener(e -> {
28 | ok = true;
29 | dialog.setVisible(false);
30 | });
31 | //cancel按钮事件
32 | JButton cancelButton = new JButton("Cancel");
33 | cancelButton.addActionListener(e -> {
34 | dialog.setVisible(false);
35 | });
36 |
37 | JPanel buttonPanel = new JPanel();
38 | buttonPanel.add(okButton);
39 | buttonPanel.add(cancelButton);
40 | add(buttonPanel, BorderLayout.SOUTH);
41 | }
42 |
43 | //设置用户名
44 | public void setUser(User u) {
45 | username.setText(u.getUserName());
46 | }
47 |
48 | //获取用户名
49 | public User getUser() {
50 | return new User(username.getText(), password.getPassword());
51 | }
52 |
53 | //返回Ok的值,若点击ok返回true,若点击cancel则返回false
54 | public boolean showDialog(Component parent, String title) {
55 | ok = false;
56 |
57 | Frame owner = null;
58 | //如果传入的框架是frame,那么owner设置为传入的这个窗口
59 | if (parent instanceof Frame)
60 | owner = (Frame) parent;
61 | else//若不是,那么新建一个窗口作为Parent
62 | owner = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);
63 | //若交互窗口为空 或者 窗口的owner不是上面的owner
64 | if (dialog == null || dialog.getOwner() != owner) {
65 | //新建一个dialog
66 | dialog = new JDialog(owner, true);
67 | dialog.add(this);
68 | dialog.getRootPane().setDefaultButton(okButton);
69 | dialog.pack();
70 | }
71 |
72 | dialog.setTitle(title);
73 | dialog.setVisible(true);
74 | return ok;
75 | }
76 |
77 | //布局管理
78 | private class GBS extends GridBagConstraints {
79 | private GBS(int x, int y, int heigh, int width, int weightx, int weighty) {
80 | this.gridx = x;
81 | this.gridy = y;
82 | this.gridheight = heigh;
83 | this.gridwidth = width;
84 | this.weightx = weightx;
85 | this.weighty = weighty;
86 | this.fill = GridBagConstraints.BOTH;
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/com/ten/demo/dataExchange/User.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.dataExchange;
2 |
3 | //用户 对象
4 | public class User {
5 | private String userName;
6 | private char[] Password;
7 |
8 | //构造方法
9 | public User() {
10 | this("null", null);
11 | }
12 |
13 | public User(String username, char[] password) {
14 | this.userName = username;
15 | this.Password = password;
16 | }
17 |
18 | //getter setter方法
19 | public String getUserName() {
20 | return userName;
21 | }
22 |
23 | public void setUserName(String userName) {
24 | this.userName = userName;
25 | }
26 |
27 | public char[] getPassword() {
28 | return Password;
29 | }
30 |
31 | public void setPassword(char[] password) {
32 | Password = password;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/com/ten/demo/fileChooser/FileIconView.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.fileChooser;
2 |
3 | import javax.swing.*;
4 | import javax.swing.filechooser.FileFilter;
5 | import javax.swing.filechooser.FileView;
6 | import java.io.File;
7 |
8 | //文件选择类
9 | public class FileIconView extends FileView {
10 | private FileFilter filter;
11 | private Icon icon;
12 |
13 | //设置过滤器和文件的图标
14 | public FileIconView(FileFilter aFilter, Icon anIcon) {
15 | filter = aFilter;
16 | icon = anIcon;
17 | }
18 |
19 | //当点击的文件1、不是目录2、满足过滤器的accept方法时,返回图片预览图
20 | public Icon getIcon(File f) {
21 | if (!f.isDirectory() && filter.accept(f)) return icon;
22 | else return null;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/com/ten/demo/fileChooser/ImagePreviewer.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.fileChooser;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 | import java.io.File;
6 |
7 | //预览附件,右侧图片预览模块
8 | public class ImagePreviewer extends JLabel {
9 | public ImagePreviewer(JFileChooser chooser) {
10 | setPreferredSize(new Dimension(100, 100));//设置显示区域尺寸
11 | setBorder(BorderFactory.createEtchedBorder());//边框
12 |
13 | chooser.addPropertyChangeListener(e -> {//changeListener 当点击发生变化时,执行
14 | //当点击的图片名称==图片的名称时
15 | if (e.getPropertyName() == JFileChooser.SELECTED_FILE_CHANGED_PROPERTY) {
16 | File f = (File) e.getNewValue();
17 | if (f == null) {
18 | setIcon(null);
19 | return;
20 | }
21 |
22 | ImageIcon icon = new ImageIcon(f.getPath());
23 | //若图片尺寸过大,则缩小
24 | if (icon.getIconWidth() > getWidth()) {
25 | icon = new ImageIcon(icon.getImage().getScaledInstance(getWidth(), -1, Image.SCALE_DEFAULT));//尺寸重置
26 | }
27 | setIcon(icon);
28 | }
29 | });
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/com/ten/demo/fileChooser/ImageViewerFrame.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.fileChooser;
2 |
3 | import javax.swing.*;
4 | import javax.swing.filechooser.FileNameExtensionFilter;
5 | import javax.swing.filechooser.*;
6 | import java.io.File;
7 |
8 | //图片选择对话框
9 | public class ImageViewerFrame extends JFrame {
10 | private static final int DEFAULT_WIDTH = 300;
11 | private static final int DEFAULT_HEIGHT = 400;
12 | private JLabel label;
13 | private JFileChooser chooser;
14 |
15 | public static void main(String[] args) {
16 | JFrame frame = new ImageViewerFrame();
17 | frame.setVisible(true);
18 | frame.setLocation(200, 200);
19 | frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
20 | frame.setTitle("图片选择框");
21 | frame.pack();
22 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
23 | }
24 |
25 | public ImageViewerFrame() {
26 | //设置菜单视图
27 | setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
28 |
29 | JMenuBar menuBar = new JMenuBar();
30 | setJMenuBar(menuBar);
31 |
32 | JMenu menu = new JMenu("File");
33 | menuBar.add(menu);
34 |
35 | JMenuItem openItem = new JMenuItem("open");
36 | menu.add(openItem);
37 | //"open"按钮打开事件
38 | openItem.addActionListener(e -> {
39 | chooser.setCurrentDirectory(new File("."));//设置默认目录->本目录
40 |
41 | int result = chooser.showOpenDialog(ImageViewerFrame.this);//显示对话框
42 |
43 | if (result == JFileChooser.APPROVE_OPTION) ;
44 | {//如果选择了图片
45 | String name = chooser.getSelectedFile().getPath();
46 | label.setIcon(new ImageIcon(name));//预览
47 | pack();
48 | }
49 | });
50 |
51 | JMenuItem exitItem = new JMenuItem("exit");
52 | menu.add(exitItem);
53 | exitItem.addActionListener(e -> System.exit(0));
54 |
55 | label = new JLabel();
56 | add(label);
57 | //过滤器
58 | chooser = new JFileChooser();
59 | FileFilter filter = new FileNameExtensionFilter("Image files", "jpg", "jpeg", "png");//过滤器的过滤内容
60 | chooser.setFileFilter(filter);
61 | chooser.setAccessory(new ImagePreviewer(chooser));//ImagePreviewer 预览类
62 | chooser.setFileView(new FileIconView(filter, new ImageIcon("palette.gif")));//FileIconView 文件浏览类
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/com/ten/demo/login/TextComponentFrame.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.login;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 |
6 | /**
7 | * 一个登录的Panel
8 | *
9 | * @author wshten
10 | * @date 2018/11/11
11 | */
12 | public class TextComponentFrame extends JFrame {
13 | private static final int TEXTAREA_ROWS = 8;
14 | private static final int TEXTAREA_COLUMNS = 20;
15 |
16 | public TextComponentFrame() {
17 | //用户名 密码
18 | JTextField textField = new JTextField(10);
19 | JPasswordField passwordField = new JPasswordField(10);
20 | //用户名和密码面板
21 | JPanel northPanel = new JPanel();
22 | northPanel.setLayout(new GridBagLayout());
23 | //添加组件和布局约束
24 | northPanel.add(new JLabel("User name: ", SwingConstants.RIGHT), getConstraints(0, 0));
25 | northPanel.add(textField, getConstraints(1, 0));
26 | northPanel.add(new JLabel("Password: ", SwingConstants.RIGHT), getConstraints(0, 1));
27 | northPanel.add(passwordField, getConstraints(1, 1));
28 |
29 | add(northPanel, BorderLayout.NORTH);
30 |
31 | //获取文本域+滚动区域
32 | JTextArea textArea = new JTextArea(TEXTAREA_ROWS, TEXTAREA_COLUMNS);
33 | textArea.setLineWrap(true);
34 | JScrollPane scrollPane = new JScrollPane(textArea);
35 |
36 | add(scrollPane, BorderLayout.CENTER);
37 |
38 | //添加按钮
39 | JPanel southPanel = new JPanel();
40 | JButton insertButton = new JButton("Insert");
41 | southPanel.add(insertButton);
42 | //Button的监听事件
43 | insertButton.addActionListener(event ->
44 | textArea.append("User name: " + textField.getText() + "\n" + "Password: " + new String(passwordField.getPassword()) + "\n"));
45 |
46 | add(southPanel, BorderLayout.SOUTH);
47 | pack();
48 | }
49 |
50 | public static void main(String[] args) {
51 | //创建窗口
52 | JFrame frame = new TextComponentFrame();
53 | frame.setVisible(true);
54 | }
55 |
56 | //布局约束
57 | private GridBagConstraints getConstraints(int x, int y) {
58 | GridBagConstraints constraints = new GridBagConstraints();
59 | constraints.gridx = x;
60 | constraints.gridy = y;
61 | constraints.gridwidth = 1;
62 | constraints.gridheight = 1;
63 | constraints.weightx = 100;
64 | constraints.weighty = 100;
65 | return constraints;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/com/ten/demo/mouse/RobotTest.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.mouse;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 | import java.awt.event.InputEvent;
6 | import java.awt.image.BufferedImage;
7 |
8 | public class RobotTest {
9 | public static void main(String[] args) throws AWTException {
10 |
11 | EventQueue.invokeLater(() -> {
12 | ButtonFrame frame = new ButtonFrame();
13 | frame.setLocation(0, 0);
14 | frame.setSize(400, 400);
15 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
16 | frame.setVisible(true);
17 | });
18 |
19 | GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
20 | GraphicsDevice graphicsDevice = environment.getDefaultScreenDevice();
21 |
22 | Robot robot = new Robot(graphicsDevice);
23 | int i = 0;
24 | while (i++ < 100) {
25 | robot.keyPress(' ');
26 | robot.keyRelease(' ');
27 |
28 | robot.mouseMove(100 + i, 100 + i);
29 | robot.mousePress(InputEvent.BUTTON1_MASK);
30 | robot.mouseRelease(InputEvent.BUTTON1_MASK);
31 |
32 | Rectangle rectangle = new Rectangle(i, i, 200 + i, 200 + i);
33 | BufferedImage image = robot.createScreenCapture(rectangle);
34 | ImageFrame frame = new ImageFrame(image);
35 | robot.delay(100);
36 | }
37 |
38 | }
39 |
40 | static class ButtonFrame extends JFrame {
41 | public ButtonFrame() {
42 | add(new JButton("hello11"));
43 | add(new JButton("hello22"));
44 | add(new JButton("hello33"));
45 | add(new JButton("hello444"));
46 |
47 | this.setLayout(new FlowLayout());
48 | }
49 | }
50 |
51 | static class ImageFrame extends JFrame {
52 | private static final int DEFAULT_WIDTH = 250;
53 | private static final int DEFAULT_HEIGHT = 250;
54 |
55 | public ImageFrame(Image image) {
56 | setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
57 | setTitle("Image");
58 | JLabel label = new JLabel(new ImageIcon(image));
59 | add(label);
60 | }
61 | }
62 |
63 | }
--------------------------------------------------------------------------------
/com/ten/demo/panel/Popup.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.panel;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 | import java.awt.event.*;
6 |
7 | //JPopupMenu弹出式菜单
8 | public class Popup extends JFrame {
9 | private JPopupMenu popupMenu = new JPopupMenu();
10 | private JTextField textField = new JTextField(10);
11 |
12 | public Popup() {
13 | setLayout(new FlowLayout());
14 | add(textField);
15 | //标签的点击事件
16 | ActionListener al = new ActionListener() {
17 | @Override
18 | public void actionPerformed(ActionEvent e) {
19 | textField.setText(((JMenuItem) e.getSource()).getText());
20 | }
21 | };
22 | JMenuItem menuItem = new JMenuItem("hither");
23 | menuItem.addActionListener(al);
24 | popupMenu.add(menuItem);
25 | menuItem = new JMenuItem("exit");
26 | menuItem.addActionListener(al);
27 | popupMenu.add(menuItem);
28 |
29 | PopupListener pl = new PopupListener();
30 | addMouseListener(pl);
31 | textField.addMouseListener(pl);
32 | }
33 |
34 | //菜单的事件监听类
35 | class PopupListener extends MouseAdapter {
36 | //鼠标点击事件
37 | @Override
38 | public void mousePressed(MouseEvent e) {
39 | maybeShowPopup(e);
40 | }
41 |
42 | //鼠标重新点击事件
43 | @Override
44 | public void mouseReleased(MouseEvent e) {
45 | maybeShowPopup(e);
46 | }
47 |
48 | //在鼠标点击的位置显示菜单
49 | private void maybeShowPopup(MouseEvent event) {
50 | if (event.isPopupTrigger())
51 | popupMenu.show(event.getComponent(), event.getX(), event.getY());
52 | }
53 | }
54 |
55 | public static void main(String[] args) {
56 | SwingUtilities.invokeLater(new Runnable() {
57 | @Override
58 | public void run() {
59 | JFrame frame = new Popup();
60 | frame.setSize(300, 300);
61 | frame.setVisible(true);
62 | frame.pack();
63 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
64 | }
65 | });
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/com/ten/demo/panel/TabbedPane.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.panel;
2 |
3 | import javax.swing.*;
4 | import javax.swing.event.ChangeEvent;
5 | import javax.swing.event.ChangeListener;
6 | import java.awt.*;
7 |
8 | //页签面板
9 | public class TabbedPane extends JFrame {
10 | private String[] statements = {"hello", "how are you", "are you ok", "nice to meet you"};//页签数组
11 | private JTabbedPane tabbedPane = new JTabbedPane();
12 | private JTextField textField = new JTextField(20);
13 |
14 | public TabbedPane() {
15 | int i = 0;
16 | //JTabbedPane的addTab方法,添加页签和它对应的面板
17 | for (String state : statements) {
18 | tabbedPane.addTab(statements[i], new Button("Tabbed pane " + i++));
19 | }
20 | tabbedPane.addChangeListener(new ChangeListener() {
21 | @Override
22 | public void stateChanged(ChangeEvent e) {
23 | textField.setText("Tab selected: " + tabbedPane.getSelectedIndex());
24 | }
25 | });
26 | add(BorderLayout.SOUTH, textField);
27 | add(tabbedPane);
28 | }
29 |
30 | public static void main(String[] args) {
31 | SwingUtilities.invokeLater(new Runnable() {
32 | @Override
33 | public void run() {
34 | JFrame frame = new TabbedPane();
35 | frame.setSize(200, 200);
36 | frame.setVisible(true);
37 | frame.pack();
38 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
39 | }
40 | });
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/com/ten/demo/reflection/ReflectionTest.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.reflection;
2 |
3 | import java.lang.reflect.Constructor;
4 | import java.lang.reflect.Field;
5 | import java.lang.reflect.Method;
6 | import java.lang.reflect.Modifier;
7 | import java.util.Scanner;
8 |
9 | /**
10 | * 利用反射,分析打印一个类的全部信息
11 | *
12 | * @author wang shihao
13 | * @version 2017-11-26
14 | */
15 | public class ReflectionTest {
16 | public static void main(String[] args) {
17 | String name;
18 | if (args.length > 0) name = args[0];
19 | else {
20 | Scanner in = new Scanner(System.in);
21 | System.out.print("Enter class name (e.g. java.util.Date): ");
22 | name = in.next();
23 | }
24 |
25 | try {
26 | Class c1 = Class.forName(name);
27 | Class superc1 = c1.getSuperclass();
28 | String modifiers = Modifier.toString(c1.getModifiers());
29 | //输出修饰符,例如public
30 | if (modifiers.length() > 0) System.out.print(modifiers + " ");
31 | //输出类名,例如Sort
32 | System.out.print("class " + name);
33 | //输出父类,例如javax.swing.JPanel
34 | if (superc1 != null && superc1 != Object.class) System.out.print(" extends " + superc1.getName());
35 |
36 | //输出构造方法,函数,域
37 | System.out.print("\n{\n");
38 | printConstructors(c1);//构造方法
39 | System.out.println();
40 | printMethods(c1);//方法函数
41 | System.out.println();
42 | printFields(c1);//域
43 | System.out.println("}");
44 | } catch (ClassNotFoundException e) {
45 | e.printStackTrace();
46 | }
47 | System.exit(0);//执行完后退出程序
48 | }
49 |
50 |
51 | /**
52 | * constructor:构造函数
53 | *
54 | * @param c1
55 | */
56 | private static void printConstructors(Class c1) {
57 | //返回包含constructor对象的数组
58 | Constructor[] constructors = c1.getDeclaredConstructors();
59 | //遍历每个constructor对象的信息
60 | for (Constructor c : constructors) {
61 | String name = c.getName();
62 | System.out.print(" ");//缩进
63 | String modifiers = Modifier.toString(c.getModifiers());
64 | //输出修饰符
65 | if (modifiers.length() > 0) System.out.print(modifiers + " ");
66 | //输出方法名
67 | System.out.print(name + "(");
68 |
69 | //打印参数类型
70 | Class[] paramTypes = c.getParameterTypes();
71 | for (int j = 0; j < paramTypes.length; j++) {
72 | if (j > 0) System.out.print(", ");
73 | System.out.print(paramTypes[j].getName());
74 | }
75 | System.out.println(");");
76 | }
77 | }
78 |
79 | /**
80 | * 方法
81 | *
82 | * @param c1
83 | */
84 | private static void printMethods(Class c1) {
85 | Method[] methods = c1.getMethods();
86 | //遍历每个方法的信息
87 | for (Method m : methods) {
88 | Class returnType = m.getReturnType();
89 | String name = m.getName();
90 | System.out.print(" ");
91 | String modifiers = Modifier.toString(m.getModifiers());
92 | //输出modifier
93 | if (modifiers.length() > 0) System.out.print(modifiers + " ");
94 | //输出返回值类型+方法名
95 | System.out.print(returnType.getName() + " " + name + "(");
96 | Class[] paramTypes = m.getParameterTypes();
97 | //输出参数信息
98 | for (int j = 0; j < paramTypes.length; j++) {
99 | if (j > 0) System.out.print(", ");
100 | System.out.print(paramTypes[j].getName());
101 | }
102 | System.out.println(");");
103 | }
104 | }
105 |
106 | /**
107 | * 域
108 | *
109 | * @param c1
110 | */
111 | private static void printFields(Class c1) {
112 | Field[] fields = c1.getFields();
113 | //遍历域的信息
114 | for (Field f : fields) {
115 | Class type = f.getType();
116 | String name = f.getName();
117 | System.out.print(" ");
118 | String modifiers = Modifier.toString(f.getModifiers());
119 | //输出modifier
120 | if (modifiers.length() > 0) System.out.print(modifiers + " ");
121 | System.out.println(type.getName() + " " + name + ";");
122 | }
123 | }
124 |
125 | }
126 |
--------------------------------------------------------------------------------
/com/ten/demo/search/BlockingQueueSearcher.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.search;
2 |
3 | import java.io.File;
4 | import java.io.FileNotFoundException;
5 | import java.util.Scanner;
6 | import java.util.concurrent.ArrayBlockingQueue;
7 | import java.util.concurrent.BlockingQueue;
8 |
9 | /**
10 | * 根据输入directory目录查找子文件中包含keyword的字符串
11 | *
12 | * @author wshten
13 | * @date 2018/11/11
14 | */
15 | public class BlockingQueueSearcher {
16 | private static final int FILE_QUEUE_SIZE = 10;
17 | private static final int SEARCH_THREAD = 100;
18 | private static final File DUMMY = new File("");
19 | private static BlockingQueue queue = new ArrayBlockingQueue<>(FILE_QUEUE_SIZE);
20 |
21 | public static void main(String[] args) {
22 | try (Scanner in = new Scanner(System.in)) {
23 | // 获取查找根目录
24 | System.out.println("Enter base directory (e.g. /opt/jdk1.8.0/src):");
25 | String directory = in.nextLine();
26 | // 获取查找关键词
27 | System.out.println("Enter keyword (e.g. volatile):");
28 | String keyword = in.nextLine();
29 | // 启动根目录的枚举方法
30 | Runnable enumerator = () -> {
31 | try {
32 | //从根目录启动enumerate
33 | enumerate(new File(directory));
34 | //虚拟对象,标志队列结束,将其加入到队列最后
35 | queue.put(DUMMY);
36 | } catch (InterruptedException e) {
37 | e.printStackTrace();
38 | }
39 | };
40 | new Thread(enumerator).start();
41 | //启动大量搜索线程
42 | for (int i = 1; i <= SEARCH_THREAD; i++) {
43 | Runnable searcher = () -> {
44 | try {
45 | //标志位管理结束查找
46 | boolean done = false;
47 | while (!done) {
48 | //take:取出下一个队列项
49 | File file = queue.take();
50 | //如果为虚拟对象,那么将其放回,并结束进程
51 | if (file == DUMMY) {
52 | queue.put(file);
53 | done = true;
54 | }
55 | //若不是虚拟对象,那么继续查找search
56 | else {
57 | search(file, keyword);
58 | }
59 | }
60 | } catch (InterruptedException | FileNotFoundException e) {
61 | e.printStackTrace();
62 | }
63 | };
64 | new Thread(searcher).start();
65 | }
66 | }
67 | }
68 |
69 | /**
70 | * 获取所有文件:生产者线程枚举在所有子目录下的所有文件并把它们放到一个阻塞队列中
71 | */
72 | private static void enumerate(File directory) throws InterruptedException {
73 | // listFiles方法,将目录包含的文件放进File[]数组中
74 | File[] files = directory.listFiles();
75 | if (files != null) {
76 | for (File file : files) {
77 | if (file.isDirectory()) {
78 | // 如果子文件为目录,继续向下寻找
79 | enumerate(file);
80 | } else {
81 | // 如果为文件,那么加入到阻塞队列中
82 | queue.put(file);
83 | }
84 | }
85 | }
86 | }
87 |
88 | /**
89 | * 查找每个文件:每个搜索线程从队列中取出一个文件,打开它,打印所有包含该关键字的行,然后取出下一个文件
90 | */
91 | private static void search(File file, String keyword) throws FileNotFoundException {
92 | // 从文件中读取字符串,采用UTF-8编码
93 | try (Scanner in = new Scanner(file, "UTF-8")) {
94 | int lineNumber = 0;
95 | // 不断读取文件的内容
96 | while (in.hasNextLine()) {
97 | lineNumber++;
98 | String line = in.nextLine();
99 | // 如果本次读取的字符串包含keyword
100 | if (line.contains(keyword)) {
101 | System.out.printf("%s:%d:%s%n", file.getPath(), lineNumber, line);
102 | }
103 | }
104 | }
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/com/ten/demo/sin/SineDraw.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.sin;
2 |
3 | import javax.swing.*;
4 | import javax.swing.event.ChangeEvent;
5 | import javax.swing.event.ChangeListener;
6 | import java.awt.*;
7 |
8 | //正弦函数绘制动作
9 | public class SineDraw extends JPanel {
10 | private static final int SCALEFACTOR = 200;//比例系数
11 | private int cycles;//所希望的完整的正弦波的个数
12 | private int points;//要绘制的点的总数
13 | private double[] sines;//包含了正弦函数的值
14 | private int[] pts;//包含将要绘制在JPanel上的y的坐标
15 |
16 | public SineDraw() {
17 | setCycles(5);
18 | }//默认为五个周期
19 |
20 | //覆盖pointComponent方法(绘制部件、成分、组件)
21 | @Override
22 | protected void paintComponent(Graphics g) {
23 | super.paintComponent(g);
24 | int maxWidth = getWidth();//获取面板宽度和高度
25 | int maxHeight = getHeight();
26 | double hstep = (double) maxWidth / (double) points;//hstep表示每个点之间的距离
27 |
28 | pts = new int[points];
29 | for (int i = 0; i < points; i++)
30 | pts[i] = (int) (sines[i] * maxHeight / 2 * .95 + maxHeight / 2);//获取每个点的y坐标:函数值*高度的一半*0.95+高度的一半-->当函数值为零时,恰好在中央,且会随高度的变化而自动拉伸,0.95确保到边界的距离
31 | g.setColor(Color.RED);
32 | for (int i = 1; i < points; i++) {//一共绘制points个点
33 | int x1 = (int) ((i - 1) * hstep);//起始点x:距离间隔为hstep
34 | int x2 = (int) (i * hstep);
35 | int y1 = pts[i - 1];//y去pts中y的坐标
36 | int y2 = pts[i];
37 | g.drawLine(x1, y1, x2, y2);
38 | }
39 | }
40 |
41 | //获取显示的周期个数
42 | public void setCycles(int newCycles) {
43 | cycles = newCycles;
44 |
45 | //points:比例系数*周期数*2
46 | points = SCALEFACTOR * cycles * 2;
47 | sines = new double[points];
48 | for (int i = 0; i < points; i++) {
49 | //radians:PI除以比例系数表示每隔多少数值取一个sin点,例如PI/200,表示一个PI周期中,取200次值,每隔PI/200取一次
50 | double radians = (Math.PI / SCALEFACTOR) * i;
51 | sines[i] = Math.sin(radians);//sines中保存每个点的sin值
52 | }
53 | repaint();//没调用一次setCycles 重新绘画
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/com/ten/demo/sin/SineWave.java:
--------------------------------------------------------------------------------
1 | package com.ten.demo.sin;
2 |
3 | import javax.swing.*;
4 | import javax.swing.event.ChangeEvent;
5 | import javax.swing.event.ChangeListener;
6 | import java.awt.*;
7 |
8 | //正弦函数绘制控制
9 | public class SineWave extends JFrame {
10 | private SineDraw sines = new SineDraw();
11 | private JSlider adjustCycles = new JSlider(1, 30, 5);
12 |
13 | public SineWave() {
14 | add(sines);
15 | //滑块点击事件
16 | adjustCycles.addChangeListener(new ChangeListener() {
17 | @Override
18 | public void stateChanged(ChangeEvent e) {
19 | //通过e.getSource方法获取
20 | sines.setCycles(((JSlider) e.getSource()).getValue());
21 | }
22 | });
23 | add(BorderLayout.SOUTH, adjustCycles);
24 | }
25 |
26 | public static void main(String[] args) {
27 | SwingUtilities.invokeLater(new Runnable() {
28 | @Override
29 | public void run() {
30 | JFrame frame = new SineWave();
31 | frame.setVisible(true);
32 | frame.pack();
33 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
34 | }
35 | });
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/com/ten/sort/ButtonComponent.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort;
2 |
3 | import com.ten.sort.Mapping.doMapping;
4 | import com.ten.sort.SortFile.ReadSortArray;
5 | import com.ten.sort.SortFile.SaveSortArray;
6 |
7 | import javax.swing.*;
8 | import java.awt.event.ActionEvent;
9 | import java.awt.event.ActionListener;
10 | import java.io.IOException;
11 |
12 | /**
13 | * 获取按钮组件,并添加响应事件
14 | */
15 | public class ButtonComponent {
16 | private static JButton sortButton;
17 | private static JButton mappingButton;
18 | private static JButton inputButton;
19 | private static JButton outputButton;
20 |
21 | private static JComboBox comboBox;
22 |
23 | private static String sortFunction = "Default";
24 |
25 | //对文本框的操作
26 | private static TextComponent textArea = new TextComponent();
27 |
28 | //初始化
29 | public ButtonComponent() {
30 | }
31 |
32 | /**
33 | * 获取"排序"按钮 并 添加响应事件
34 | */
35 | public static JButton getSortButton() {
36 | sortButton = new JButton("开始排序");
37 | sortButton.addActionListener(e -> {
38 | //开启一个排序线程
39 | Runnable r = () -> {
40 | try {
41 | new SortExecutors();
42 | Thread.sleep(500);
43 | } catch (Exception e1) {
44 | e1.printStackTrace();
45 | }
46 | };
47 | Thread thread = new Thread(r);
48 | thread.start();
49 | });
50 | return sortButton;
51 | }
52 |
53 | /**
54 | * 获取"绘图"按钮 并 添加响应事件
55 | */
56 | public static JButton getMappingButton() {
57 | mappingButton = new JButton("绘制图像");
58 | mappingButton.addActionListener(e -> {
59 | Runnable r = () -> {
60 | try {
61 | new doMapping();
62 | } catch (Exception e1) {
63 | e1.printStackTrace();
64 | }
65 | };
66 | Thread thread = new Thread(r);
67 | thread.start();
68 | });
69 | return mappingButton;
70 | }
71 |
72 | /**
73 | * 获取"读取"按钮 并 添加响应事件
74 | */
75 | public static JButton getInputButton() {
76 | inputButton = new JButton("导入时间复杂度文件");
77 | inputButton.addActionListener(e -> {
78 | Runnable r = () -> {
79 | try {
80 | new ReadSortArray();
81 | Thread.sleep(500);
82 | } catch (IOException | InterruptedException e1) {
83 | e1.printStackTrace();
84 | }
85 | };
86 | Thread thread = new Thread(r);
87 | thread.start();
88 | });
89 | return inputButton;
90 | }
91 |
92 | /**
93 | * 获取"写入"按钮 并 添加响应事件
94 | *
95 | * @return outputButton
96 | */
97 | public static JButton getOutputButton() {
98 | outputButton = new JButton("生成时间复杂度文件");
99 | outputButton.addActionListener(e -> {
100 | Runnable r = () -> {
101 | // 将Swing操作加入到事件队列中
102 | TextComponent.setResultText("正在生成TXT文件................");
103 | try {
104 | sortFunction = SelectComponent.getComboBoxSelection();
105 | new SaveSortArray();
106 | Thread.sleep(500);
107 | } catch (IOException e1) {
108 | e1.printStackTrace();
109 | TextComponent.setResultText("文件生成异常!................");
110 | } catch (InterruptedException e1) {
111 | e1.printStackTrace();
112 | }
113 | TextComponent.setResultText("已经生成文件!................");
114 | };
115 | Thread thread = new Thread(r);
116 | thread.start();
117 | });
118 | return outputButton;
119 | }
120 | }
--------------------------------------------------------------------------------
/com/ten/sort/Mapping/ButtonPanel.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.Mapping;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 | import java.awt.event.ActionEvent;
6 | import java.awt.event.ActionListener;
7 |
8 | /**
9 | * 右侧:按钮面板
10 | */
11 | class ButtonPanel extends JPanel {
12 | //普通按钮,导数按钮,拟合按钮
13 | private JButton commonButton;
14 | private JButton derivativeButton;
15 | private JButton fittingButton;
16 |
17 | private doMapping mapping;
18 | private MyCanvas trendChartCanvas = new MyCanvas();
19 | private CommonCanvas commonCanvas = new CommonCanvas();
20 | private DerivativeCanvas derivativeCanvas = new DerivativeCanvas();
21 | private FittingCanvas fittingCanvas = new FittingCanvas();
22 |
23 | public ButtonPanel() {
24 |
25 | commonButton = new JButton("普通曲线");
26 | derivativeButton = new JButton("一阶导数");
27 | fittingButton = new JButton("拟合曲线");
28 |
29 | setBorder(BorderFactory.createEtchedBorder());
30 | setLayout(new GridLayout(4, 1, 0, 10));
31 |
32 | add(new JLabel("功能选择:"));
33 |
34 | //添加按钮以及响应事件
35 | add(commonButton);
36 | commonButton.addActionListener(new ActionListener() {
37 | @Override
38 | public void actionPerformed(ActionEvent e) {
39 | //打开普通画布
40 | System.out.println("hello");
41 | }
42 | });
43 |
44 | add(derivativeButton);
45 | derivativeButton.addActionListener(new ActionListener() {
46 | @Override
47 | public void actionPerformed(ActionEvent e) {
48 | //打开导数画布
49 | new DerivativeCanvas();
50 | }
51 | });
52 | add(fittingButton);
53 | fittingButton.addActionListener(new ActionListener() {
54 | @Override
55 | public void actionPerformed(ActionEvent e) {
56 | //打开拟合画布
57 | new FittingCanvas();
58 | }
59 | });
60 | }
61 | }
--------------------------------------------------------------------------------
/com/ten/sort/Mapping/CommonCanvas.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.Mapping;
2 |
3 | public class CommonCanvas {
4 | }
5 |
--------------------------------------------------------------------------------
/com/ten/sort/Mapping/DerivativeCanvas.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.Mapping;
2 |
3 | import javax.swing.*;
4 |
5 | public class DerivativeCanvas extends JFrame {
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/com/ten/sort/Mapping/FittingCanvas.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.Mapping;
2 |
3 | import javax.swing.*;
4 |
5 | public class FittingCanvas extends JFrame {
6 | }
7 |
--------------------------------------------------------------------------------
/com/ten/sort/Mapping/LinePanel.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.Mapping;
2 |
3 | import com.ten.sort.SelectComponent;
4 |
5 | import javax.swing.*;
6 | import java.awt.*;
7 |
8 | /**
9 | * 右侧:画线面板
10 | */
11 | class LinePanel extends JPanel {
12 | private int X_Start;
13 | private int Y_Start;
14 | private int Y_Change = 10;
15 | private String[] sortType;
16 | private Color[] lineColor;
17 |
18 | public LinePanel() {
19 | //初始化
20 | sortType = SelectComponent.getSortType();
21 | lineColor = doMapping.getLineColor();
22 |
23 | setBorder(BorderFactory.createEtchedBorder());
24 | setLayout(new GridLayout(16, 1, 0, 10));
25 |
26 | //获取画线位置
27 | X_Start = this.getX() + 10;
28 | Y_Start = this.getY() + 10;
29 |
30 | //八次排序画线
31 | for (int i = 0; i < 8; i++) {
32 | JButton lineButton = new JButton(sortType[i]);
33 | lineButton.setBackground(lineColor[i]);
34 | lineButton.setBorder(BorderFactory.createEmptyBorder());
35 | add(lineButton);
36 | add(new LineCanve(lineColor[i]));
37 | }
38 | }
39 |
40 | //线的画布
41 | class LineCanve extends Canvas {
42 | private Color color;
43 |
44 | public LineCanve(Color linecoler) {
45 | //获取颜色
46 | color = linecoler;
47 | }
48 |
49 | //画线
50 | @Override
51 | public void paint(Graphics g) {
52 | super.paint(g);
53 | Graphics2D g2D = (Graphics2D) g;
54 | //绘图提示-消除锯齿
55 | g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
56 | g2D.setStroke(new BasicStroke(Float.parseFloat("2.0F")));// 轴线粗度
57 |
58 | //对八种排序绘制
59 | g.setColor(color);
60 | //绘制直线,通过循环,将所有的点连线
61 | g2D.drawLine(X_Start, Y_Start, X_Start + 80, Y_Start);
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/com/ten/sort/Mapping/MyCanvas.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.Mapping;
2 |
3 | import com.ten.sort.SelectComponent;
4 | import com.ten.sort.SortFile.SortFile;
5 |
6 | import java.awt.*;
7 |
8 | // 主画布
9 | public class MyCanvas extends Canvas {
10 | // 画布框架起点坐标
11 | private final int FREAME_X = 50;
12 | private final int FREAME_Y = 50;
13 | private final int FREAME_WIDTH = 1000;// 横
14 | private final int FREAME_HEIGHT = 500;// 纵
15 |
16 | // 画布原点坐标
17 | private final int Origin_X = FREAME_X + 50;
18 | private final int Origin_Y = FREAME_Y + FREAME_HEIGHT;
19 |
20 | // 画布X,Y轴终点坐标
21 | private final int XAxis_X = FREAME_X + FREAME_WIDTH;
22 | private final int XAxis_Y = Origin_Y;
23 | private final int YAxis_X = Origin_X;
24 | private final int YAxis_Y = FREAME_Y;
25 |
26 | // 画布X,Y轴上的分度值(1分度=像素)
27 | private final int LENGTH_INTERVAL = 40;
28 | private final int TIME_INTERVAL = 20;
29 |
30 | private Color[] lineColor;
31 |
32 | //缓存要显示的数组
33 | private static int[] Select;
34 | private static int[] Insert;
35 | private static int[] Bubble;
36 | private static int[] Heap;
37 | private static int[] Merge;
38 | private static int[] Radix;
39 | private static int[] Shell;
40 | private static int[] Quick;
41 |
42 | //排序总数组
43 | private static int[][] sortArray;
44 |
45 | //每次画线时的缓存数组
46 | private int[] tempArray;
47 |
48 | //画线的的名称
49 | private String[] lineName;
50 |
51 | //获取每个排序的时间(原单位:毫秒)
52 | public MyCanvas() {
53 | //获取画线颜色
54 | lineColor = doMapping.getLineColor();
55 |
56 | //获取画线的名称
57 | lineName = SelectComponent.getSortType();
58 |
59 | //为排序数组获取数值
60 | Select = SortFile.getSelect();
61 | Insert = SortFile.getInsert();
62 | Bubble = SortFile.getBubble();
63 | Heap = SortFile.getHeap();
64 | Merge = SortFile.getMerge();
65 | Radix = SortFile.getRadix();
66 | Shell = SortFile.getShell();
67 | Quick = SortFile.getQuick();
68 | sortArray = new int[][]{Select, Bubble, Quick, Shell, Insert, Heap, Radix, Merge};
69 | }
70 |
71 | //绘图
72 | public void paint(Graphics g) {
73 | Graphics2D g2D = (Graphics2D) g;
74 | //定义颜色
75 | Color c = new Color(200, 70, 0);
76 | g.setColor(c);
77 | //绘图提示-消除锯齿
78 | g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
79 | // 画坐标轴
80 | g2D.setStroke(new BasicStroke(Float.parseFloat("2.0F")));// 轴线粗度
81 | // X轴以及方向箭头
82 | g.drawLine(Origin_X, Origin_Y, XAxis_X, XAxis_Y);// x轴线的轴线
83 | g.drawLine(XAxis_X, XAxis_Y, XAxis_X - 5, XAxis_Y - 5);// 上边箭头
84 | g.drawLine(XAxis_X, XAxis_Y, XAxis_X - 5, XAxis_Y + 5);// 下边箭头
85 | // Y轴以及方向箭头
86 | g.drawLine(Origin_X, Origin_Y, YAxis_X, YAxis_Y);
87 | g.drawLine(YAxis_X, YAxis_Y, YAxis_X - 5, YAxis_Y + 5);
88 | g.drawLine(YAxis_X, YAxis_Y, YAxis_X + 5, YAxis_Y + 5);
89 | // 画X轴上的空间刻度(从坐标轴原点起,每隔LENGTH_INTERVAL(容量分度)像素画一时间点,到100万止)
90 | g.setColor(Color.BLUE);
91 | g2D.setStroke(new BasicStroke(Float.parseFloat("1.0f")));
92 | // X轴刻度依次变化情况
93 | for (int i = Origin_X, j = 0; j <= 100; i += LENGTH_INTERVAL, j += 5) {
94 | g.drawString(" " + j, i - 10, Origin_Y + 20);
95 | }
96 | g.drawString("数组大小/万", XAxis_X - 20, XAxis_Y + 20);
97 | // 画Y轴上时间刻度(从坐标原点起,每隔10像素画一格,到1000止)
98 | for (int i = Origin_Y, j = 0; j <= 500; i -= TIME_INTERVAL, j += TIME_INTERVAL) {
99 | g.drawString(j + " ", Origin_X - 30, i + 3);
100 | }
101 | g.drawString("时间/秒", YAxis_X - 5, YAxis_Y - 15);// 时间刻度小箭头值
102 | // 画网格线
103 | g.setColor(Color.LIGHT_GRAY);
104 | // 坐标内部横线
105 | for (int i = Origin_Y; i >= YAxis_Y; i -= TIME_INTERVAL) {
106 | g.drawLine(Origin_X, i, XAxis_X, i);
107 | }
108 | // 坐标内部竖线
109 | for (int i = Origin_X; i <= XAxis_X; i += LENGTH_INTERVAL) {
110 | g.drawLine(i, Origin_Y, i, YAxis_Y);
111 | }
112 |
113 | g.setColor(c);
114 | g2D.setStroke(new BasicStroke(Float.parseFloat("2.0F")));// 轴线粗度
115 |
116 | //八种排序绘制
117 | for (int j = 0; j < 8; j++) {
118 | g.setColor(lineColor[j]);
119 | if (sortArray[j] != null) {
120 | tempArray = new int[sortArray[j].length];
121 | tempArray = sortArray[j];
122 | System.out.println(j);
123 | } else
124 | continue;
125 | //绘制直线,通过循环,将所有的点连线
126 | for (int i = 0; i < 20; i++) {
127 | g2D.drawLine(Origin_X + i * LENGTH_INTERVAL, Origin_Y - tempArray[i],
128 | Origin_X + (i + 1) * LENGTH_INTERVAL, Origin_Y - tempArray[i + 1]);
129 | if (i == 19) {
130 | g2D.drawString(lineName[j], Origin_X + (i + 1) * LENGTH_INTERVAL + 10, Origin_Y - tempArray[i + 1]);
131 | }
132 | }
133 | }
134 | }
135 | }
--------------------------------------------------------------------------------
/com/ten/sort/Mapping/doMapping.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.Mapping;
2 |
3 | import java.awt.*;
4 |
5 | import javax.swing.*;
6 |
7 | /**
8 | * 绘图
9 | */
10 | public class doMapping extends JFrame {
11 | //主坐标图
12 | private MyCanvas trendChartCanvas = new MyCanvas();
13 | private CommonCanvas commonCanvas = new CommonCanvas();
14 | private DerivativeCanvas derivativeCanvas = new DerivativeCanvas();
15 | private FittingCanvas fittingCanvas = new FittingCanvas();
16 |
17 | //辅助栏面板
18 | private LinePanel line = new LinePanel();
19 | private ButtonPanel button = new ButtonPanel();
20 | private JPanel ButtonAndLine = new JPanel();
21 |
22 | //排序线的颜色
23 | private static final Color[] lineColor = {Color.RED, Color.BLUE, Color.GREEN, Color.CYAN, Color.MAGENTA, Color.ORANGE, Color.BLACK, Color.GRAY};
24 |
25 | //构造函数
26 | public doMapping() {
27 | super("排序时间复杂度:");
28 | this.setBounds(0, 0, 1400, 700);
29 | this.setLayout(new BorderLayout());
30 |
31 | //添加主画布到中心
32 | this.add(trendChartCanvas, BorderLayout.CENTER);
33 | this.add(trendChartCanvas, BorderLayout.CENTER);
34 |
35 | //边侧辅助面板
36 | ButtonAndLine.setBorder(BorderFactory.createLineBorder(Color.RED));
37 | ButtonAndLine.setLayout(new BorderLayout(0, 50));
38 | ButtonAndLine.add(button, BorderLayout.NORTH);
39 | ButtonAndLine.add(line, BorderLayout.CENTER);
40 | this.add(ButtonAndLine, BorderLayout.EAST);
41 |
42 | this.setVisible(true);
43 | pack();
44 | }
45 |
46 | //获取线的颜色
47 | public static Color[] getLineColor() {
48 | return lineColor;
49 | }
50 | }
--------------------------------------------------------------------------------
/com/ten/sort/ProgressComponent.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 |
6 | public class ProgressComponent {
7 | private static JProgressBar progressBar;
8 |
9 | public ProgressComponent() {
10 |
11 | }
12 |
13 | public static JProgressBar getProgressBar() {
14 | progressBar = new JProgressBar();
15 | progressBar.setMinimum(0);
16 | progressBar.setMaximum(1000);
17 | //计算某项操作的百分比,并显示出来
18 | progressBar.setStringPainted(true);
19 | progressBar.setBackground(Color.GREEN);
20 | return progressBar;
21 | }
22 |
23 | //更新进度条——线程安全
24 | public void setProgress() {
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/com/ten/sort/RandomArray.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort;
2 |
3 | public class RandomArray {
4 | //数组长度,数组,默认长度
5 | private int number;
6 |
7 | public RandomArray(int[] array, int length) {
8 | System.out.println("数组的容量为:" + length);
9 | try {
10 | for (int i = 0; i < length; i++) {
11 | number = (int) (Math.random() * 1000000);
12 | array[i] = number;
13 | }
14 | } catch (Exception e) {
15 | e.printStackTrace();
16 | System.out.println("创建数组失败");
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/com/ten/sort/SelectComponent.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort;
2 |
3 | import javax.swing.*;
4 |
5 | /**
6 | * 获取选择部件,并添加响应事件
7 | */
8 | public class SelectComponent {
9 | //排序方法
10 | private static String[] sortType = {"选择排序", "冒泡排序", "快速排序", "希尔排序", "插入排序", "堆排序", "基数排序", "合并排序"};
11 | //下拉组合框
12 | private static JComboBox comboBox;
13 | //复选框面板
14 | private static JCheckBox[] checkBoxes;
15 | private static JPanel checkBoxPanel;
16 |
17 | //获取JComboBox组合框
18 | public static JComboBox getComboBox() {
19 | comboBox = new JComboBox();
20 | comboBox.setEditable(true);
21 |
22 | //为组合框添加Item
23 | for (int i = 0; i < sortType.length; i++) {
24 | comboBox.addItem(sortType[i]);
25 | }
26 | return comboBox;
27 | }
28 |
29 | //获取JCheckBox复选框
30 | public static JPanel getCheckBox() {
31 | checkBoxes = new JCheckBox[sortType.length];
32 | checkBoxPanel = new JPanel();
33 |
34 | //为复选框添加Item
35 | for (int i = 0; i < sortType.length; i++) {
36 | checkBoxes[i] = new JCheckBox(sortType[i]);
37 | checkBoxPanel.add(checkBoxes[i]);
38 | }
39 | return checkBoxPanel;
40 | }
41 |
42 | //获取comboBox选择-单选
43 | public static String getComboBoxSelection() {
44 | String select = new String();
45 |
46 | //获取单选框选择的Item
47 | return select = (String) comboBox.getSelectedItem();
48 | }
49 |
50 | //获取checkBox选择-多选
51 | public static String[] getCheckBoxSelection() {
52 | String[] selects = new String[sortType.length];
53 |
54 | //获取复选框选择情况
55 | for (int i = 0; i < sortType.length; i++) {
56 | if (checkBoxes[i].isSelected()) selects[i] = sortType[i];
57 | else selects[i] = null;
58 | }
59 | return selects;
60 | }
61 |
62 | //获取排序数组名称
63 | public static String[] getSortType() {
64 | return sortType;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/com/ten/sort/Sort.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 |
6 | /**
7 | * 程序入口
8 | *
9 | * @author wshten
10 | * @date 2018/11/11
11 | */
12 | public class Sort {
13 | public static void main(String[] args) {
14 | EventQueue.invokeLater(() -> {
15 | JFrame frame = new SortFrame();
16 | frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
17 | frame.setTitle("算法设计-时间复杂度分析");
18 | frame.setVisible(true);
19 | });
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/com/ten/sort/SortExecutors.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort;
2 |
3 | import com.ten.sort.SortFile.SortFile;
4 |
5 | /**
6 | * 排序线程池
7 | * 点击一次排序按钮,则开启一个排序线程
8 | * 排序完成后会自动把结果存储在SortFile对应数组中
9 | */
10 | public class SortExecutors {
11 | private String sortType;
12 | private doSort newSortThread;
13 |
14 | private TextComponent textArea;
15 |
16 | public SortExecutors() {
17 | //获取排序类型
18 | sortType = SelectComponent.getComboBoxSelection();
19 | textArea = new TextComponent();
20 |
21 | try {
22 | System.out.println("选择的排序方式为:" + sortType);
23 |
24 | //将文本框切换到排序显示模式
25 | TextComponent.setSortText("--------开始排序--------");
26 | TextComponent.setResultText("--------开始排序--------");
27 |
28 | newSortThread = new doSort(sortType);
29 |
30 | //将结果保存在SortFile中
31 | SortFile.setSortTypeArray(sortType, newSortThread.getTimes());
32 |
33 | } catch (Exception e) {
34 | e.printStackTrace();
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/com/ten/sort/SortFile/ReadSortArray.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.SortFile;
2 |
3 | import com.ten.sort.SelectComponent;
4 | import com.ten.sort.TextComponent;
5 |
6 | import java.io.*;
7 |
8 | /**
9 | * "读取"按钮触发,从本地txt文件中读入选择项的文件,获取已经保存的时间数组
10 | */
11 | public class ReadSortArray extends SortFile {
12 | //输入流
13 | private BufferedReader bufferedReader;
14 |
15 | //字符串缓存
16 | private String arrayString;
17 |
18 | //结果数组缓存
19 | private int[] sortResult;
20 |
21 | //构造函数
22 | public ReadSortArray() throws IOException {
23 | //获取复选框数据
24 | filenames = SelectComponent.getCheckBoxSelection();
25 |
26 | //对每个选择项进行操作
27 | for (String filename : filenames) {
28 | //若选择项不为null,则读取文件
29 | if (filename != null) {
30 | //生成文件
31 | file = new File(DEFAULT_DIRECTORY + filename + ".txt");
32 |
33 | //若文件不存在
34 | if (!file.exists()) {
35 | textComponent.setSortText("此文件不存在");
36 | continue;
37 | }
38 |
39 | //当文件存在,那么读取字符串
40 | else {
41 | //将读取到的便于阅读的字符串存储到arratString中
42 | arrayString = new String();
43 | arrayString = this.getContent(file);
44 |
45 | //获取对应的数组
46 | String[] textString = arrayString.split("\r\n");
47 | int[] textInt = new int[textString.length];
48 | System.out.println("本次排序" + filename + "数组容量为" + textInt.length);
49 | for (int i = 1; i < textString.length; i++) {
50 | //ms转换成s
51 | if (filename == "希尔排序" || filename == "堆排序" || filename == "快速排序" || filename == "基数排序") {
52 | textInt[i] = Integer.parseInt(textString[i]);
53 | } else {
54 | textInt[i] = (Integer.parseInt(textString[i])) / 1000;
55 | }
56 | System.out.println(textInt[i]);
57 | }
58 |
59 | //用提取到的数据修改对应的排序时间数组
60 | setSortTypeArray(filename, textInt);
61 |
62 | }
63 | }
64 | }
65 | }
66 |
67 | //获取文件的内容,生成一个字符串
68 | private String getContent(File file) throws IOException {
69 | //初始化输入流
70 | bufferedReader = new BufferedReader(new FileReader(this.file));
71 | stringBuilder = new StringBuilder();
72 |
73 | String content = " ";
74 | //若输入流不为空,则继续读取下一行
75 | while (content != null) {
76 | content = bufferedReader.readLine();
77 |
78 | //若读到null,则读取结束
79 | if (content == null) break;
80 |
81 | String[] contentsplit = content.split("\\|");
82 |
83 | //将读取的字符串加到StringBuilder中
84 | stringBuilder.append(contentsplit[1].trim());
85 | stringBuilder.append("\r\n");
86 | }
87 |
88 | //关闭输入流
89 | bufferedReader.close();
90 |
91 | //将读取的文件显示在result中
92 | textComponent = new TextComponent();
93 | textComponent.setSortText(stringBuilder.toString());
94 |
95 | //返回读取到的字符串
96 | return stringBuilder.toString();
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/com/ten/sort/SortFile/SaveSortArray.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.SortFile;
2 |
3 | import com.ten.sort.SelectComponent;
4 | import com.ten.sort.TextComponent;
5 |
6 | import java.io.BufferedWriter;
7 | import java.io.File;
8 | import java.io.FileWriter;
9 | import java.io.IOException;
10 |
11 | /**
12 | * "生成"按钮触发,将排序好的结果存储起来,如果已存在那么更新
13 | */
14 | public class SaveSortArray extends SortFile {
15 | //输出流
16 | private BufferedWriter bufferedWriter;
17 |
18 | //数组缓存
19 | private int[] timeArray;
20 |
21 | //构造函数
22 | public SaveSortArray() throws IOException {
23 | filenames = SelectComponent.getCheckBoxSelection();
24 |
25 | //遍历每一个复选框对象
26 | for (String filename : filenames) {
27 | //若选择项不为null,则写入文件
28 | if (filename != null) {
29 | //生成文件
30 | file = new File(DEFAULT_DIRECTORY + filename + ".txt");
31 |
32 | //若文件不存在,创建try
33 | if (!file.exists()) {
34 | try {
35 | file.createNewFile();
36 | } catch (Exception e) {
37 | System.out.println("创建失败");
38 | }
39 | }
40 |
41 | //获取数据源,参数为排序类型 String类型
42 | String s = this.getDataSource(filename);
43 |
44 | //打印显示出来
45 | this.setResultText();
46 |
47 | //写入文件
48 | bufferedWriter = new BufferedWriter(new FileWriter(file));
49 | bufferedWriter.write(s);
50 | bufferedWriter.close();
51 | }
52 | }
53 | }
54 |
55 | //获取数据源
56 | private String getDataSource(String sortType) {
57 | //获取对应排序类型的数组
58 | timeArray = getSortTypeArray(sortType);
59 |
60 | //构建字符串
61 | stringBuilder = new StringBuilder();
62 | stringBuilder.append(String.join("|", "数组大小", "所用时间"));
63 | stringBuilder.append("\r\n");
64 | //length每次递增5万,时间与之对应
65 | for (int i = 0, length = 0; i < timeArray.length; i++, length += 50000) {
66 | stringBuilder.append(length).append("|").append(timeArray[i]);
67 | stringBuilder.append("\r\n");
68 | }
69 |
70 | stringBuilder.deleteCharAt(stringBuilder.length() - 1);
71 | return stringBuilder.toString();
72 | }
73 |
74 | //将数据源在result上显示出来
75 | private void setResultText() {
76 | textComponent = new TextComponent();
77 | for (int i = 0, length = 0; i < timeArray.length; i++, length += 50000) {
78 | textComponent.setResultText(length + "|" + timeArray[i] + "ms");
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/com/ten/sort/SortFile/SortFile.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.SortFile;
2 |
3 | import com.ten.sort.TextComponent;
4 |
5 | import java.io.File;
6 |
7 | /**
8 | * 文件读写
9 | */
10 | public class SortFile {
11 | //读写文件操作的文件名
12 | protected File file;
13 |
14 | //获取复选框选择
15 | protected String[] filenames;
16 |
17 | //字符构建
18 | protected StringBuilder stringBuilder;
19 |
20 | //对文本框的操作
21 | protected TextComponent textComponent;
22 |
23 | //TODO 默认文件和默认目录
24 | protected static final String DEFAULT_PATH = "C:\\Users\\59682\\Desktop\\Java\\SortArray\\Default.txt";
25 | protected static final String DEFAULT_DIRECTORY = "C:\\Users\\59682\\Desktop\\Java\\SortArray\\";
26 |
27 | //保存每个排序方法的结果的数组
28 | private static int[] Select;
29 | private static int[] Insert;
30 | private static int[] Bubble;
31 | private static int[] Heap;
32 | private static int[] Merge;
33 | private static int[] Radix;
34 | private static int[] Shell;
35 | private static int[] Quick;
36 |
37 | //获取参数对应的 排序数组
38 | public static int[] getSortTypeArray(String sortType) {
39 | int[] arrays = new int[21];
40 |
41 | //选择器
42 | switch (sortType) {
43 | case "选择排序":
44 | arrays = Select;
45 | break;
46 | case "冒泡排序":
47 | arrays = Bubble;
48 | break;
49 | case "快速排序":
50 | arrays = Quick;
51 | break;
52 | case "希尔排序":
53 | arrays = Shell;
54 | break;
55 | case "插入排序":
56 | arrays = Insert;
57 | break;
58 | case "堆排序":
59 | arrays = Heap;
60 | break;
61 | case "基数排序":
62 | arrays = Radix;
63 | break;
64 | case "合并排序":
65 | arrays = Merge;
66 | break;
67 | default:
68 | break;
69 | }
70 | return arrays;
71 | }
72 |
73 | //将参数对应的排序结果,写入排序数组
74 | public static void setSortTypeArray(String arrayType, int[] array) {
75 | //排序选择器
76 | switch (arrayType) {
77 | case "选择排序":
78 | Select = new int[array.length];
79 | Select = array;
80 | break;
81 | case "冒泡排序":
82 | Bubble = new int[array.length];
83 | Bubble = array;
84 | break;
85 | case "快速排序":
86 | Quick = new int[array.length];
87 | Quick = array;
88 | break;
89 | case "希尔排序":
90 | Shell = new int[array.length];
91 | Shell = array;
92 | break;
93 | case "插入排序":
94 | Insert = new int[array.length];
95 | Insert = array;
96 | break;
97 | case "堆排序":
98 | Heap = new int[array.length];
99 | Heap = array;
100 | break;
101 | case "基数排序":
102 | Radix = new int[array.length];
103 | Radix = array;
104 | break;
105 | case "合并排序":
106 | Merge = new int[array.length];
107 | Merge = array;
108 | break;
109 | default:
110 | break;
111 | }
112 | }
113 |
114 |
115 | public static int[] getSelect() {
116 | return Select;
117 | }
118 |
119 | public static int[] getInsert() {
120 | return Insert;
121 | }
122 |
123 | public static int[] getBubble() {
124 | return Bubble;
125 | }
126 |
127 | public static int[] getHeap() {
128 | return Heap;
129 | }
130 |
131 | public static int[] getMerge() {
132 | return Merge;
133 | }
134 |
135 | public static int[] getRadix() {
136 | return Radix;
137 | }
138 |
139 | public static int[] getShell() {
140 | return Shell;
141 | }
142 |
143 | public static int[] getQuick() {
144 | return Quick;
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/com/ten/sort/SortFrame.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort;
2 |
3 | import javax.swing.*;
4 |
5 | /**
6 | * Swing Frame
7 | *
8 | * @author wshten
9 | * @date 2018/11/11
10 | * @see Sort
11 | */
12 | public class SortFrame extends JFrame {
13 | private static JMenuBar menuBar;
14 |
15 | public SortFrame() {
16 | // 设置外观
17 | selectUI();
18 |
19 | // 添加菜单
20 | initMenu();
21 | setJMenuBar(menuBar);
22 |
23 | // 设置内容面板
24 | SortPanel sortPanel = new SortPanel();
25 | setContentPane(sortPanel);
26 | setLocation(200, 200);
27 | pack();
28 | }
29 |
30 | /**
31 | * 设置外观 :获取当前系统的默认外观
32 | */
33 | private static void selectUI() {
34 | try {
35 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
36 | } catch (IllegalAccessException | InstantiationException | UnsupportedLookAndFeelException | ClassNotFoundException e) {
37 | e.printStackTrace();
38 | }
39 | }
40 |
41 | /**
42 | * 初始化JMenuBar菜单栏
43 | */
44 | private static void initMenu() {
45 | menuBar = new JMenuBar();
46 |
47 | // 一级菜单
48 | JMenu filemenu = new JMenu("File");
49 | JMenu editmenu = new JMenu("Edit");
50 | JMenu aboutmenu = new JMenu("About");
51 |
52 | // 二级菜单
53 | JMenuItem newitem = new JMenuItem("New...");
54 | JMenuItem closeitem = new JMenuItem("Close...");
55 | JMenuItem setitem = new JMenuItem("Setting...");
56 |
57 | // 添加二级菜单
58 | filemenu.add(newitem);
59 | filemenu.addSeparator();
60 | filemenu.add(closeitem);
61 | filemenu.addSeparator();
62 | editmenu.add(setitem);
63 | editmenu.addSeparator();
64 |
65 | // 添加一级菜单
66 | menuBar.add(filemenu);
67 | menuBar.add(editmenu);
68 | menuBar.add(aboutmenu);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/com/ten/sort/SortPanel.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 |
6 | /**
7 | * Panel
8 | *
9 | * @author wshten
10 | * @date 2018/11/11
11 | * @see SortFrame
12 | */
13 | class SortPanel extends JPanel {
14 | /**
15 | * 一个主程序对应一个面板内容,所以用静态域
16 | */
17 | private static JPanel jpanelMenu;
18 | private static JPanel jpanelSort;
19 | private static JPanel jpanelResult;
20 | private static JPanel jpanelCheckBox;
21 |
22 | private static JLabel jlableSort;
23 | private static JLabel jlabelResult;
24 |
25 | private static JScrollPane jtextSort;
26 | private static JScrollPane jtextResult;
27 |
28 | private static JComboBox jcomboSelect;
29 |
30 | private static JButton jbuttonSort;
31 | private static JButton jbuttonInput;
32 | private static JButton jbuttonOutput;
33 | private static JButton jbuttonMapping;
34 |
35 | private static JProgressBar jprogressSort;
36 |
37 | public SortPanel() {
38 | // 按钮初始化
39 | jbuttonSort = ButtonComponent.getSortButton();
40 | jbuttonMapping = ButtonComponent.getMappingButton();
41 | jbuttonInput = ButtonComponent.getInputButton();
42 | jbuttonOutput = ButtonComponent.getOutputButton();
43 |
44 | // 选择项初始化
45 | jcomboSelect = SelectComponent.getComboBox();
46 | jpanelCheckBox = SelectComponent.getCheckBox();
47 |
48 | // 标签初始化
49 | jlableSort = new JLabel("排序进程:");
50 | jlabelResult = new JLabel("排序结果:");
51 |
52 | // 文本框初始化
53 | jtextSort = TextComponent.getSortTextPanel();
54 | jtextResult = TextComponent.getResultTextPanel();
55 |
56 | // 进度条初始化
57 | jprogressSort = ProgressComponent.getProgressBar();
58 |
59 | // 设置面板
60 | init_panel();
61 | init_frame();
62 | }
63 |
64 | //JPanel面板初始化
65 | private static void init_panel() {
66 | jpanelMenu = new JPanel();
67 | jpanelSort = new JPanel();
68 | jpanelResult = new JPanel();
69 |
70 | //设置面板边框
71 | jpanelSort.setBorder(BorderFactory.createEtchedBorder());
72 | jpanelResult.setBorder(BorderFactory.createEtchedBorder());
73 | jpanelMenu.setBorder(BorderFactory.createEtchedBorder());
74 | }
75 |
76 | //frame初始化
77 | private void init_frame() {
78 | //添加布局
79 | setLayout(new GridBagLayout());
80 | add(jpanelMenu, setConstraints(0, 0, 1, 3, 1, 1));
81 | add(jpanelSort, setConstraints(0, 1, 2, 3, 1, 1));
82 | add(jpanelResult, setConstraints(0, 3, 2, 3, 1, 1));
83 | //面板布局
84 | //菜单面板
85 | jpanelMenu.setLayout(new GridBagLayout());
86 | jpanelMenu.add(jcomboSelect, setConstraints(0, 0, 1, 1, 1, 1));
87 | jpanelMenu.add(jbuttonSort, setConstraints(1, 0, 1, 1, 1, 1));
88 | jpanelMenu.add(jbuttonMapping, setConstraints(2, 0, 1, 1, 1, 1));
89 | jpanelMenu.add(jpanelCheckBox, setConstraints(0, 1, 1, 3, 1, 1));
90 | jpanelMenu.add(jprogressSort, setConstraints(0, 2, 1, 3, 1, 1));
91 | //排序面板
92 | jpanelSort.setLayout(new GridBagLayout());
93 | jpanelSort.add(jlableSort, setConstraints(0, 0, 1, 2, 1, 1));
94 | jpanelSort.add(jbuttonInput, setConstraints(2, 0, 1, 2, 1, 1));
95 | jpanelSort.add(jtextSort, setConstraints(0, 2, 2, 4, 0, 2));
96 | //结果面板
97 | jpanelResult.setLayout(new GridBagLayout());
98 | jpanelResult.add(jlabelResult, setConstraints(0, 0, 1, 2, 1, 1));
99 | jpanelResult.add(jbuttonOutput, setConstraints(2, 0, 1, 2, 1, 1));
100 | jpanelResult.add(jtextResult, setConstraints(0, 2, 2, 4, 0, 2));
101 | }
102 |
103 | //设置布局管理器
104 | private static GridBagConstraints setConstraints(int gx, int gy, int gh, int gw, int wx, int wy) {
105 | GridBagConstraints constraints = new GridBagConstraints();
106 | constraints.gridx = gx;
107 | constraints.gridy = gy;
108 | constraints.gridheight = gh;
109 | constraints.gridwidth = gw;
110 | constraints.weightx = wx;
111 | constraints.weighty = wy;
112 | constraints.fill = GridBagConstraints.BOTH;
113 | return constraints;
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/com/ten/sort/TextComponent.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 |
6 | /**
7 | * 获取文本框组件,并添加事件
8 | */
9 | public class TextComponent {
10 | //定义文本框
11 | public static JTextArea sortText;
12 | public static JTextArea resultText;
13 |
14 | //定义文本属性
15 | private static final int TEXT_ROWS = 10;
16 | private static final int TEXT_COLUMNS = 100;
17 | private static final Font songFont = new Font("宋体", Font.PLAIN, 16);
18 |
19 | //JText文本框 属性初始化
20 | public TextComponent() {
21 | }
22 |
23 | //设置排序显示内容——线程安全
24 | public static void setSortText(String text) {
25 | SwingUtilities.invokeLater(new Runnable() {
26 | @Override
27 | public void run() {
28 | sortText.append(text);
29 | sortText.append("\r\n");
30 | }
31 | });
32 | }
33 |
34 | //设置结果显示内容——线程安全
35 | public static void setResultText(String text) {
36 | SwingUtilities.invokeLater(new Runnable() {
37 | @Override
38 | public void run() {
39 | resultText.append(text);
40 | resultText.append("\r\n");
41 | }
42 | });
43 | }
44 |
45 | //获取排序文本框-滚动窗格
46 | public static JScrollPane getSortTextPanel() {
47 | sortText = setText(sortText);
48 | setSortText("等待排序........");
49 | return new JScrollPane(sortText);
50 | }
51 |
52 | //获取排结果文本框-滚动窗格
53 | public static JScrollPane getResultTextPanel() {
54 | resultText = setText(resultText);
55 | setResultText("等待排序........");
56 | return new JScrollPane(resultText);
57 | }
58 |
59 | //设置文本框属性
60 | public static JTextArea setText(JTextArea textArea) {
61 | //初始化文本框
62 | textArea = new JTextArea(TEXT_ROWS, TEXT_COLUMNS);
63 |
64 | //设置字体格式
65 | textArea.setFont(songFont);
66 |
67 | //设置自动换行
68 | textArea.setLineWrap(true);
69 |
70 | return textArea;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/com/ten/sort/dialogFrame/ExDialog.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.dialogFrame;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 |
6 | //自定义弹出对话框
7 | public class ExDialog extends JDialog {
8 | //第一个参数为拥有者,第二个参数为显示的String内容
9 | public ExDialog(JFrame owner, String content) {
10 | super(owner, "Dialog", true);
11 | add(new JLabel("Sort Panel
" + content + ""), BorderLayout.CENTER);
12 |
13 | JPanel panel = new JPanel();
14 | JButton ok = new JButton("OK");
15 | //点击ok时,关闭对话框
16 | ok.addActionListener(e -> setVisible(false));
17 | panel.add(ok);
18 | add(panel, BorderLayout.SOUTH);
19 | setSize(150, 250);
20 | setLocation(500, 500);
21 | setVisible(true);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/com/ten/sort/dialogFrame/TooBarFrame.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.dialogFrame;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 | import java.awt.event.ActionEvent;
6 |
7 | //工具条
8 | public class TooBarFrame {
9 | //JToolBar工具条
10 | public TooBarFrame() {
11 | JToolBar toolBar = new JToolBar();
12 | Action colorAction = new ToolAction("颜色", Color.RED, "更换背景颜色");
13 | Action functionAction = new ToolAction("功能", Color.BLUE, "功能按钮");
14 | }
15 |
16 | //工具条对应的内部类
17 | class ToolAction extends AbstractAction {
18 | //初始化构造函数
19 | public ToolAction(String name, Color color, String function) {
20 | //putValue方法赋值键值对
21 | putValue(Action.NAME, name);
22 | putValue(Action.SHORT_DESCRIPTION, name + "按钮");
23 | putValue("color", color);
24 | putValue("function", function);
25 | }
26 |
27 | //事件响应
28 | @Override
29 | public void actionPerformed(ActionEvent e) {
30 | Color c = (Color) getValue("color");
31 | String fun = (String) getValue("function");
32 | System.out.println("颜色" + c + " 功能" + fun);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/com/ten/sort/doSort.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort;
2 |
3 | import com.ten.sort.dialogFrame.ExDialog;
4 | import com.ten.sort.sortmethod.*;
5 |
6 | /**
7 | * 每次排序都生成一个doSort对象
8 | * 选择具体的排序方法
9 | * 计算排序的时间
10 | */
11 | public class doSort {
12 | //记录排序用时
13 | private long startTime;
14 | private long endTime;
15 |
16 | //数组开始时初始排序的数组大小
17 | private int length = 0;
18 |
19 | //每次排序都重新生成对应大小的随机数组
20 | private int[] array;
21 |
22 | //每个对象对应的排序用时数组
23 | private int[] times;
24 |
25 | //每个doSort对象对应的排序方式
26 | private String sortType;
27 |
28 | //文本框对象的操作
29 | private TextComponent textArea;
30 |
31 | public doSort(String sortType) {
32 | this.sortType = sortType;
33 | times = new int[21];
34 |
35 | //对文本框对象的操作初始化
36 | textArea = new TextComponent();
37 | textArea.setSortText(sortType + "---------------已经开始---------------");
38 |
39 | this.sort();
40 |
41 | textArea.setSortText(sortType + "---------------排序完成---------------");
42 |
43 | //弹出对话框提示
44 | new ExDialog(null, sortType + " 排序完成");
45 | }
46 |
47 | private void sort() {
48 | //从0开始,每次五万,直到100万
49 | for (int i = 0; i < 21; i++) {
50 | //重新定义随机数组array
51 | array = new int[length];
52 | new RandomArray(array, length);
53 | length += 50000;
54 |
55 | //记录一次排序的开始时间
56 | startTime = System.currentTimeMillis();
57 |
58 | if (i > 0) {
59 | //排序选择器
60 | switch (sortType) {
61 | case "选择排序":
62 | Select_Sort.sort(array);
63 | break;
64 | case "冒泡排序":
65 | Bubble_Sort.sort(array);
66 | break;
67 | case "快速排序":
68 | Quick_Sort.quick(array);
69 | break;
70 | case "希尔排序":
71 | Shell_Sort.sort(array);
72 | break;
73 | case "插入排序":
74 | Insert_Sort.sort(array);
75 | break;
76 | case "堆排序":
77 | Heap_Sort.sort(array);
78 | break;
79 | case "基数排序":
80 | Radix_Sort.sort(array);
81 | break;
82 | case "合并排序":
83 | Merge_Sort.sort(array);
84 | break;
85 | default:
86 | break;
87 | }
88 | }
89 |
90 | //记录一次排序的结束时间
91 | endTime = System.currentTimeMillis();
92 |
93 | //记录本次排序所用时间
94 | this.setTimes(i, (int) (endTime - startTime));
95 | }
96 | }
97 |
98 | //记录每次排序所用时间
99 | private void setTimes(int index, int sorttime) {
100 | times[index] = sorttime;
101 |
102 | //将一次的排序时间打印在排序文本框
103 | textArea.setSortText(sortType + "-------数组大小:" + (index * 50000) + "-------用时:" + (endTime - startTime) + "ms" + " -> " + (endTime - startTime) + "ms");
104 | }
105 |
106 | //获取排序用时的记录
107 | public int[] getTimes() {
108 | return times;
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/com/ten/sort/sortmethod/Bubble_Sort.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.sortmethod;
2 |
3 | /**
4 | * 冒泡排序
5 | */
6 | public class Bubble_Sort extends Example {
7 | public static void sort(int[] array) {
8 | int tmp;
9 | for (int i = 1; i < array.length; i++) {
10 | // 判断相邻两个数据的大小,并把较大的数往后冒泡
11 | for (int j = 0; j < array.length - 1; j++) {
12 | if (array[j] > array[j + 1]) {
13 | tmp = array[j];
14 | array[j] = array[j + 1];
15 | array[j + 1] = tmp;
16 | }
17 | }
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/com/ten/sort/sortmethod/Example.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.sortmethod;
2 |
3 | //排序模板类:升序 从小到大
4 | public abstract class Example {
5 | public static void sort(int[] array) {
6 | //具体排序方法
7 | }
8 |
9 | //less判断是否小于
10 | public static boolean less(int x, int y) {
11 | return x < y;
12 | }
13 |
14 | //swap交换两元素
15 | public static void swap(int[] array, int i, int j) {
16 | int temp = array[i];
17 | array[i] = array[j];
18 | array[j] = temp;
19 | }
20 |
21 | //show打印数组
22 | public static void show(int[] array) {
23 | for (int i = 0; i < array.length; i++) {
24 | System.out.print(array[i] + " ");
25 | }
26 | System.out.println();
27 | }
28 |
29 | //isSorted是否排序:从小到大
30 | public static boolean isSorted(int[] array) {
31 | for (int i = 1; i < array.length; i++) {
32 | if (less(array[i], array[i - 1])) return false;
33 | }
34 | return true;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/com/ten/sort/sortmethod/Heap_Sort.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.sortmethod;
2 |
3 | public class Heap_Sort extends Example {
4 | public static void sort(int[] arr) {
5 | // 堆排序
6 | heapSort(arr);
7 | }
8 |
9 | /**
10 | * 堆排序
11 | */
12 | private static void heapSort(int[] arr) {
13 | // 将待排序的序列构建成一个大顶堆
14 | for (int i = arr.length / 2; i >= 0; i--) {
15 | heapAdjust(arr, i, arr.length);
16 | }
17 |
18 | // 逐步将每个最大值的根节点与末尾元素交换,并且再调整二叉树,使其成为大顶堆
19 | for (int i = arr.length - 1; i > 0; i--) {
20 | swap(arr, 0, i); // 将堆顶记录和当前未经排序子序列的最后一个记录交换
21 | heapAdjust(arr, 0, i); // 交换之后,需要重新检查堆是否符合大顶堆,不符合则要调整
22 | }
23 | }
24 |
25 | /**
26 | * 构建堆的过程
27 | *
28 | * @param arr 需要排序的数组
29 | * @param i 需要构建堆的根节点的序号
30 | * @param n 数组的长度
31 | */
32 | private static void heapAdjust(int[] arr, int i, int n) {
33 | int child;
34 | int father;
35 | for (father = arr[i]; leftChild(i) < n; i = child) {
36 | child = leftChild(i);
37 |
38 | // 如果左子树小于右子树,则需要比较右子树和父节点
39 | if (child != n - 1 && arr[child] < arr[child + 1]) {
40 | child++; // 序号增1,指向右子树
41 | }
42 |
43 | // 如果父节点小于孩子结点,则需要交换
44 | if (father < arr[child]) {
45 | arr[i] = arr[child];
46 | } else {
47 | break; // 大顶堆结构未被破坏,不需要调整
48 | }
49 | }
50 | arr[i] = father;
51 | }
52 |
53 | // 获取到左孩子结点
54 | private static int leftChild(int i) {
55 | return 2 * i + 1;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/com/ten/sort/sortmethod/Insert_Sort.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.sortmethod;
2 |
3 | //插入排序
4 | public class Insert_Sort extends Example {
5 | public static void sort(int[] array) {
6 | int N = array.length;
7 | for (int i = 1; i < N; i++) {
8 | for (int j = i; j > 0 && less(array[j], array[j - 1]); j--)
9 | swap(array, j, j - 1);
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/com/ten/sort/sortmethod/Merge_Sort.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.sortmethod;
2 |
3 | public class Merge_Sort extends Example {
4 | public static void sort(int[] a) {
5 | Sort(a, 0, a.length - 1);
6 | }
7 |
8 | private static void Sort(int[] a, int left, int right) {
9 | if (left >= right)
10 | return;
11 |
12 | int mid = (left + right) / 2;
13 | //二路归并排序里面有两个Sort,多路归并排序里面写多个Sort就可以了
14 | Sort(a, left, mid);
15 | Sort(a, mid + 1, right);
16 | merge(a, left, mid, right);
17 |
18 | }
19 |
20 | private static void merge(int[] a, int left, int mid, int right) {
21 |
22 | int[] tmp = new int[a.length];
23 | int r1 = mid + 1;
24 | int tIndex = left;
25 | int cIndex = left;
26 | // 逐个归并
27 | while (left <= mid && r1 <= right) {
28 | if (a[left] <= a[r1])
29 | tmp[tIndex++] = a[left++];
30 | else
31 | tmp[tIndex++] = a[r1++];
32 | }
33 | // 将左边剩余的归并
34 | while (left <= mid) {
35 | tmp[tIndex++] = a[left++];
36 | }
37 | // 将右边剩余的归并
38 | while (r1 <= right) {
39 | tmp[tIndex++] = a[r1++];
40 | }
41 |
42 | //从临时数组拷贝到原数组
43 | while (cIndex <= right) {
44 | a[cIndex] = tmp[cIndex];
45 | cIndex++;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/com/ten/sort/sortmethod/Quick_Sort.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.sortmethod;
2 |
3 | public class Quick_Sort extends Example {
4 | /**
5 | * 快速排序
6 | *
7 | * @param numbers 带排序数组
8 | */
9 | public static void quick(int[] numbers) {
10 | quickSort(numbers, 0, numbers.length - 1);
11 | }
12 |
13 | /**
14 | * @param numbers 带排序数组
15 | * @param low 开始位置
16 | * @param high 结束位置
17 | */
18 | public static void quickSort(int[] numbers, int low, int high) {
19 | if (low < high) {
20 | int middle = getMiddle(numbers, low, high); //将numbers数组进行一分为二
21 | quickSort(numbers, low, middle - 1); //对低字段表进行递归排序
22 | quickSort(numbers, middle + 1, high); //对高字段表进行递归排序
23 | }
24 | }
25 |
26 | /**
27 | * 查找出中轴(默认是最低位low)的在numbers数组排序后所在位置
28 | *
29 | * @param numbers 带查找数组
30 | * @param low 开始位置
31 | * @param high 结束位置
32 | * @return 中轴所在位置
33 | */
34 | public static int getMiddle(int[] numbers, int low, int high) {
35 | int temp = numbers[low]; //数组的第一个作为中轴
36 | while (low < high) {
37 | while (low < high && numbers[high] >= temp) {
38 | high--;
39 | }
40 | numbers[low] = numbers[high];//比中轴小的记录移到低端
41 | while (low < high && numbers[low] < temp) {
42 | low++;
43 | }
44 | numbers[high] = numbers[low]; //比中轴大的记录移到高端
45 | }
46 | numbers[low] = temp; //中轴记录到尾
47 | return low; // 返回中轴的位置
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/com/ten/sort/sortmethod/Radix_Sort.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.sortmethod;
2 |
3 | public class Radix_Sort extends Example {
4 | public static void sort(int[] num) {
5 | if (isEmpty(num))
6 | return;
7 | int tmp = getMax(num);
8 | // get loop count
9 | int loop = 0;
10 | do {
11 | loop++;
12 | } while ((tmp = tmp / 10) > 0);
13 | int count = 1, k, lsd;
14 | int[][] bubble = new int[10][num.length];
15 | int[] order = new int[10];
16 | tmp = 1;
17 | while (count <= loop) {
18 | for (int i = 0; i < num.length; i++) {
19 | lsd = (num[i] / tmp) % 10;
20 | bubble[lsd][order[lsd]] = num[i];
21 | order[lsd]++;
22 | }
23 | k = 0;
24 | for (int i = 0; i < 10; i++) {
25 | if (order[i] != 0) {
26 | for (int j = 0; j < order[i]; j++) {
27 | num[k] = bubble[i][j];
28 | k++;
29 | }
30 | }
31 | order[i] = 0;
32 | }
33 | tmp *= 10;
34 | count++;
35 | }
36 | }
37 |
38 | private static int getMax(int[] num) {
39 | if (isEmpty(num)) {
40 | throw new IllegalArgumentException();
41 | }
42 | int max = num[0];
43 | for (int i = 1; i < num.length; i++) {
44 | if (max < num[i])
45 | max = num[i];
46 | }
47 | return max;
48 | }
49 |
50 | private static boolean isEmpty(int[] num) {
51 | return num == null || num.length == 0;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/com/ten/sort/sortmethod/Select_Sort.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.sortmethod;
2 |
3 | //选择排序
4 | public class Select_Sort extends Example {
5 | public static void sort(int[] array) {
6 | int N = array.length;
7 | for (int i = 0; i < N; i++) {
8 | int min = i;
9 | for (int j = i + 1; j < N; j++)
10 | if (less(array[j], array[min])) min = j;
11 | swap(array, i, min);
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/com/ten/sort/sortmethod/Shell_Sort.java:
--------------------------------------------------------------------------------
1 | package com.ten.sort.sortmethod;
2 |
3 | public class Shell_Sort extends Example {
4 |
5 | public static void sort(int[] array) {
6 | int temp;
7 | int j;
8 | int x = 0;
9 |
10 | for (int r = array.length / 2; r >= 1; r /= 2) {
11 | for (int i = r; i < array.length; i++) {
12 | temp = array[i];
13 | j = i - r;
14 | while (j >= 0 && temp < array[j]) {
15 | array[j + r] = array[j];
16 | j -= r;
17 | }
18 | array[j + r] = temp;
19 | }
20 | x++;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/.idea/Java-Swing-Projects.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/.idea/sbt.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 | true
142 | DEFINITION_ORDER
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 | 1541933801471
262 |
263 |
264 | 1541933801471
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/README.md:
--------------------------------------------------------------------------------
1 | # Sort-Swing
2 |
3 | > 这是一个使用JavaSwing组件实现的桌面应用,它能够进行八种排序的时间复杂度计算,并将结果绘制图线或持久化到文件,最后对比八种算法的性能。
4 |
5 | ## 部署运行
6 | ```txt
7 | # Clone Project
8 | git clone https://github.com/kevinten10/Sort-Swing
9 |
10 | # 启动
11 | com.ten.sort: 运行Sort.java的main方法
12 | ```
13 |
14 | ## 其他DEMO
15 |
16 | > com.ten.domo文件下为基于Swing编程的实例应用,用于学习相关的方法
17 |
18 | ## 功能概述
19 | * 八大排序算法
20 | * 进度检测
21 | * 执行结果文件的保存和读取
22 | * 曲线的绘制
23 | * 曲线导数计算 绘制
24 | * 曲线拟合计算 绘制
25 | * 多线程操作
26 |
27 | ## 操作流程
28 | * 选择排序方式 或 导入文件
29 | * 点击按钮
30 | * 排序完成-->点击 绘制曲线
31 | * 三种功能 和 生成文件
32 |
33 | ## 主界面
34 |
35 | 
36 |
37 | 
38 |
39 | ### 绘图界面
40 |
41 | 
42 |
43 | 
44 |
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/ButtonComponent.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/ButtonComponent.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/Mapping/ButtonPanel$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/Mapping/ButtonPanel$1.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/Mapping/ButtonPanel$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/Mapping/ButtonPanel$2.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/Mapping/ButtonPanel$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/Mapping/ButtonPanel$3.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/Mapping/ButtonPanel.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/Mapping/ButtonPanel.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/Mapping/CommonCanvas.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/Mapping/CommonCanvas.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/Mapping/DerivativeCanvas.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/Mapping/DerivativeCanvas.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/Mapping/FittingCanvas.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/Mapping/FittingCanvas.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/Mapping/LinePanel$LineCanve.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/Mapping/LinePanel$LineCanve.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/Mapping/LinePanel.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/Mapping/LinePanel.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/Mapping/MyCanvas.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/Mapping/MyCanvas.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/Mapping/doMapping.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/Mapping/doMapping.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/ProgressComponent.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/ProgressComponent.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/RandomArray.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/RandomArray.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/SelectComponent.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/SelectComponent.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/Sort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/Sort.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/SortExecutors.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/SortExecutors.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/SortFile/ReadSortArray.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/SortFile/ReadSortArray.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/SortFile/SaveSortArray.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/SortFile/SaveSortArray.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/SortFile/SortFile.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/SortFile/SortFile.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/SortFrame.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/SortFrame.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/SortPanel.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/SortPanel.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/TextComponent$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/TextComponent$1.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/TextComponent$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/TextComponent$2.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/TextComponent.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/TextComponent.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/dialogFrame/ExDialog.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/dialogFrame/ExDialog.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/dialogFrame/TooBarFrame$ToolAction.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/dialogFrame/TooBarFrame$ToolAction.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/dialogFrame/TooBarFrame.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/dialogFrame/TooBarFrame.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/doSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/doSort.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Bubble_Sort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Bubble_Sort.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Example.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Example.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Heap_Sort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Heap_Sort.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Insert_Sort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Insert_Sort.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Merge_Sort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Merge_Sort.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Quick_Sort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Quick_Sort.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Radix_Sort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Radix_Sort.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Select_Sort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Select_Sort.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Shell_Sort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/com/ten/sort/sortMethod/Shell_Sort.class
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/主界面.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/主界面.png
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/拟合曲线.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/拟合曲线.png
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/排序曲线.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/排序曲线.png
--------------------------------------------------------------------------------
/out/production/Java-Swing-Projects/排序过程.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/out/production/Java-Swing-Projects/排序过程.png
--------------------------------------------------------------------------------
/主界面.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/主界面.png
--------------------------------------------------------------------------------
/拟合曲线.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/拟合曲线.png
--------------------------------------------------------------------------------
/排序曲线.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/排序曲线.png
--------------------------------------------------------------------------------
/排序过程.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JiangNanU-Java/Sort-Swing/1e57885f33ba2a18cea634e4926fb125a134c875/排序过程.png
--------------------------------------------------------------------------------