记账本,C,Github,util
package util; import java.awt.Component;
import java.awt.Dimension; import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UnsupportedLookAndFeelException; import gui.panel.WorkingPanel; /**
* 居中面板
*
* @author 于修彦
*
*/
public class CenterPanel extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
private double rate; // 比例
private JComponent c; // 面板上将要居中的组件
private boolean stretch;// 是否缩放 public CenterPanel(double rate, boolean stretch) {
this.setLayout(null);
this.rate = rate;
this.stretch = stretch;
} public CenterPanel(double rate) {
this(rate, true);
} /**
* 重写重绘方法,在面板居中显示组件
*/
public void repaint() {
if (this.c != null) {
Dimension containerSize = this.getSize();// 面板大小
Dimension componentSize = this.c.getPreferredSize();// 获取组件调整之后的大小 if (this.stretch) {
// 设置这个组件大小
this.c.setSize((int) (containerSize.width * this.rate), (int) (containerSize.height * this.rate));
} else {
this.c.setSize(componentSize);// 保持原来大小不变
}
// 将组件放到居中位置
this.c.setLocation(containerSize.width / 2 - this.c.getWidth() / 2,
containerSize.height / 2 - this.c.getHeight() / 2); }
super.repaint();
} /**
* 显示组件
*
* @param p
* 组件
*/
public void show(JComponent p) {
this.c = p;
Component[] cs = this.getComponents();
Component[] arrayOfComponent1;
int j = (arrayOfComponent1 = cs).length;
for (int i = 0; i < j; i++) { // 清除面板上原来的组件
Component c = arrayOfComponent1[i];
remove(c);
}
add(p); if ((p instanceof WorkingPanel)) {
((WorkingPanel) p).updateData();
}
updateUI();
}
}
util1
package util; import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.util.List; import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel; import com.objectplanet.chart.BarChart;
import com.objectplanet.chart.Chart; import entity.Record; /**
* 生成柱状图
*
* @author 于修彦
*
*/
public class ChartUtil {
/**
* 横轴下面的文字
*
* @param rs
* 数据集
* @return 依据数据集生成的文字数组
*/
private static String[] sampleLabels(List<Record> rs) {
String[] sampleLabels = new String[rs.size()];
for (int i = 0; i < sampleLabels.length; i++) {
if (0 == i % 5)
sampleLabels[i] = String.valueOf(i + 1 + "日");
} return sampleLabels; } /**
* 柱状图的柱的数据高度
*
* @param rs
* 数据集
* @return 依据数据集生成的数据数组
*/
public static double[] sampleValues(List<Record> rs) {
double[] sampleValues = new double[rs.size()];
for (int i = 0; i < sampleValues.length; i++) {
sampleValues[i] = rs.get(i).getSpend();
} return sampleValues;
} /**
* 获取柱状图的图片
*
* @param rs
* 数据集
* @param width
* 宽度
* @param height
* 高度
* @return 结果图
*/
public static Image getImage(List<Record> rs, int width, int height) {
// 根据消费记录得到的样本数据
double[] sampleValues = sampleValues(rs);
// 根据消费记录得到的下方日期文本
String[] sampleLabels = sampleLabels(rs);
// 样本中的最大值
int max = max(sampleValues); // 数据颜色
Color[] sampleColors = new Color[] { ColorUtil.blueColor }; // 柱状图
BarChart chart = new BarChart(); // 设置样本个数
chart.setSampleCount(sampleValues.length);
// 设置样本数据
chart.setSampleValues(0, sampleValues);
// 设置文字
chart.setSampleLabels(sampleLabels);
// 设置样本颜色
chart.setSampleColors(sampleColors);
// 设置取值范围
chart.setRange(0, max * 1.2);
// 显示背景横线
chart.setValueLinesOn(true);
// 显示文字
chart.setSampleLabelsOn(true);
// 把文字显示在下方
chart.setSampleLabelStyle(Chart.BELOW); // 样本值的字体
chart.setFont("rangeLabelFont", new Font("Arial", Font.BOLD, 12));
// 显示图例说明
chart.setLegendOn(true);
// 把图例说明放在左侧
chart.setLegendPosition(Chart.LEFT);
// 图例说明中的文字
chart.setLegendLabels(new String[] { "月消费报表" });
// 图例说明的字体
chart.setFont("legendFont", new Font("Dialog", Font.BOLD, 13));
// 下方文字的字体
chart.setFont("sampleLabelFont", new Font("Dialog", Font.BOLD, 13));
// 图表中间背景颜色
chart.setChartBackground(Color.white);
// 图表整体背景颜色
chart.setBackground(ColorUtil.backgroundColor);
// 把图表转换为Image类型
Image im = chart.getImage(width, height);
return im;
} public static int max(double[] sampleValues) {
int max = 0;
for (double v : sampleValues) {
if (v > max)
max = (int) v;
}
return max; } private static String[] sampleLabels() {
String[] sampleLabels = new String[30]; for (int i = 0; i < sampleLabels.length; i++) {
if (0 == i % 5)
sampleLabels[i] = String.valueOf(i + 1 + "日");
}
return sampleLabels;
} public static Image getImage(int width, int height) {
// 模拟样本数据
double[] sampleValues = sampleValues();
// 下方显示的文字
String[] sampleLabels = sampleLabels();
// 样本中的最大值
int max = max(sampleValues); // 数据颜色
Color[] sampleColors = new Color[] { ColorUtil.blueColor }; // 柱状图
BarChart chart = new BarChart(); // 设置样本个数
chart.setSampleCount(sampleValues.length);
// 设置样本数据
chart.setSampleValues(0, sampleValues);
// 设置文字
chart.setSampleLabels(sampleLabels);
// 设置样本颜色
chart.setSampleColors(sampleColors);
// 设置取值范围
chart.setRange(0, max * 1.2);
// 显示背景横线
chart.setValueLinesOn(true);
// 显示文字
chart.setSampleLabelsOn(true);
// 把文字显示在下方
chart.setSampleLabelStyle(Chart.BELOW); // 样本值的字体
chart.setFont("rangeLabelFont", new Font("Arial", Font.BOLD, 12));
// 显示图例说明
chart.setLegendOn(true);
// 把图例说明放在左侧
chart.setLegendPosition(Chart.LEFT);
// 图例说明中的文字
chart.setLegendLabels(new String[] { "月消费报表" });
// 图例说明的字体
chart.setFont("legendFont", new Font("Dialog", Font.BOLD, 13));
// 下方文字的字体
chart.setFont("sampleLabelFont", new Font("Dialog", Font.BOLD, 13));
// 图表中间背景颜色
chart.setChartBackground(Color.white);
// 图表整体背景颜色
chart.setBackground(ColorUtil.backgroundColor);
// 把图表转换为Image类型
Image im = chart.getImage(width, height);
return im;
} private static double[] sampleValues() { double[] result = new double[30];
for (int i = 0; i < result.length; i++) {
result[i] = (int) (Math.random() * 300);
}
return result; } // public static void main(String[] args) {
// JPanel p = new JPanel();
// JLabel l = new JLabel();
// Image img = ChartUtil.getImage(400, 300);
// Icon icon = new ImageIcon(img);
// l.setIcon(icon);
// p.add(l);
// GUIUtil.showPanel(p);
// } }
util2
package util; import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.SwingWorker; public class CircleProgressBar extends JPanel { private int minimumProgress; private int maximumProgress; private int progress; private String progressText; private Color backgroundColor; private Color foregroundColor; public CircleProgressBar() {
minimumProgress = 0;
maximumProgress = 100;
progressText = "0%";
} public void paint(Graphics g) {
super.paint(g);
Graphics2D graphics2d = (Graphics2D) g;
// 开启抗锯齿
graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
int x = 0;
int y = 0;
int width = 0;
int height = 0;
int fontSize = 0;
if (getWidth() >= getHeight()) {
x = (getWidth() - getHeight()) / 2 + 25;
y = 25;
width = getHeight() - 50;
height = getHeight() - 50;
fontSize = getWidth() / 8;
} else {
x = 25;
y = (getHeight() - getWidth()) / 2 + 25;
width = getWidth() - 50;
height = getWidth() - 50;
fontSize = getHeight() / 8;
}
graphics2d.setStroke(new BasicStroke(20.0f));
graphics2d.setColor(backgroundColor);
graphics2d.drawArc(x, y, width, height, 0, 360);
graphics2d.setColor(foregroundColor);
graphics2d.drawArc(x, y, width, height, 90,
-(int) (360 * ((progress * 1.0) / (maximumProgress - minimumProgress))));
graphics2d.setFont(new Font("黑体", Font.BOLD, fontSize));
FontMetrics fontMetrics = graphics2d.getFontMetrics();
int digitalWidth = fontMetrics.stringWidth(progressText);
int digitalAscent = fontMetrics.getAscent();
graphics2d.setColor(foregroundColor);
graphics2d.drawString(progressText, getWidth() / 2 - digitalWidth / 2, getHeight() / 2 + digitalAscent / 2);
} public int getProgress() {
return progress;
} public void setProgress(int progress) {
if (progress >= minimumProgress && progress <= maximumProgress)
this.progress = progress;
if (progress > maximumProgress)
this.progress = maximumProgress; this.progressText = String.valueOf(progress + "%"); this.repaint();
} public Color getBackgroundColor() {
return backgroundColor;
} public void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor;
this.repaint();
} public Color getForegroundColor() {
return foregroundColor;
} public void setForegroundColor(Color foregroundColor) {
this.foregroundColor = foregroundColor;
this.repaint();
} }
util3
记账本,C,Github,util的更多相关文章
- 家庭记账本之Github账号注册与安装(二)
好多程序猿都在使用github用来存放自己的代码:但是如果仅仅用github的web版本的话:有一些功能还是需要使用git客户端工具才能操作的: 那么今天将指导大家如何安装GitHub for win ...
- 家庭记账本之GitHub账号注册与安装(一)
账号注册 1.github是世纪上最大的开源代码托管网站.因为是国外网站,很多人在注册的时候因为不熟悉英语而犯了难. 2.百度搜索github进入官网.如果你已经有账号密码,那么点击右上角的sign ...
- 安卓开发实战-记账本APP(六)
记账本APP开发---终结篇 昨天的动态数字录屏奉上:在抖音上拍了一个(ps:欢迎点赞) https://v.douyin.com/poEjmG/ 今天将图表的内容进行了制作,我用的是MPChart的 ...
- 家庭版记账本app开发完成
经过这几天关于android的相关学习,对于家庭版记账本app以及开发结束. 实现的功能为:用户的注册.登录.添加支出账单.添加收入账单.显示所有的该用户的账单情况(收入和支出).生产图表(直观的显示 ...
- 记账本NABCD分析
学生记账本NABCD分析 N(Need,需求) 随着我们进入大学开始逐步的扩大自己的消费水平,而我们每天无法准确的记住一笔一笔的消费记录.常常,每一个月末时我们在宿舍楼道听到不少学生抱怨这个月怎么花钱 ...
- 记账本APP(2)
今天下载了Hbuiler,生成了一个记账本APP,目前里面只可以 输入今日消费 明天将会做出来记录以及计算总额于月消费.
- 简单记账本APP开发一
在对Android的一些基础的知识有了一定了解,以及对于AndroidStudio的如何使用有了 一定的熟悉后,决定做一个简单的记账本APP 开发流程 1.记账本的页面 2.可以添加新的账目 (一)页 ...
- Android开发实战——记账本(2)
开发日志(2)——Bean目录以及数据库 首先编写一些自己生成的数据进行测试,看一下能否显示在模拟器上.那前提就是先写出bean目录,这和之前学的Javaweb步骤差不多.bean目录有三个变量事件. ...
- 进度1_家庭记账本App
今天完成了昨天的初步构想,详细介绍见上一篇博客,具体项目结构和案例如下: MainActivity.java: package com.example.familybooks; import andr ...
随机推荐
- Js/对数组的认识。
1.是对数组的声明: var auditTaskIds = []; 我一般的写法. var auditTaskIds1 = []; 2.向数组中添加元素: auditTaskIds.pu ...
- Linux命令学习之路——内容剪切:cut
使用者:所有角色 用法:cut [ -bcdfn ] [ --complement ] filename 作用:截取文件中的部分字段用于展示或存储到新文件中 应用场景: 1.内容展示 : 截取一个或多 ...
- selenium-java,selenium版本和火狐浏览器版本对应关系
selenium3.5.0,firefox57,geckodriver-v0.19.1
- html走马灯效果
实现跑马灯的方法很多,其中最简单的是采用一句Html代码来实现,我们在需要出现跑马灯效果的地方插入“<marquee>滚动的文字</marquee>”语句,它的效果如下所示: ...
- uip移植telnetd并加入自己定义命令
版权声明: https://blog.csdn.net/cp1300/article/details/30541507 刚刚移植了一下uip的telnetd,还是比較简单方便的. 首先加入文件,注意u ...
- mysql 远程备份
#远程备份./innobackupex --defaults-file=/etc/my.cnf --no-timestamp --user xxx --host 192.168.1.123 \--pa ...
- Maven项目构建过程练习
转载于:http://www.cnblogs.com/xdp-gacl/p/4051690.html 上一篇只是简单介绍了一下maven入门的一些相关知识,这一篇主要是体验一下Maven高度自动化构建 ...
- Node核心模块
在Node中,模块主要分两大类:核心模块和文件模块.核心模块部分在 Node 源代码的编译过程中,编译进了二进制执行文件.在 Node 进启动时,部分核心模块就被直接加载进内存中,所以这部分核心模块引 ...
- django模型系统(三)
1,自定义主键字段的创建 AutoFiled(pirmary_key=True) # 一般不会自定义 2,order_by asc desc 表关系 OneToOne student = mod ...
- percona-toolkit(pt-online-schema-change)工具包的安装和使用
1.下载和安装percona toolkit的包 #yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/ ...