java番茄钟_番茄时间管理 - java Swing版

本文介绍了如何使用Java Swing实现番茄时间管理法的应用。通过设置25分钟定时器进行工作,然后短暂休息,每4个番茄钟进行一次长时间休息。文章详细讲解了界面圆角、自定义标题栏拖动、系统托盘图标以及倒计时功能的实现,并提供了在Eclipse中解决乱码问题的方法。
摘要由CSDN通过智能技术生成

番茄时间管理法(Pomodoro Technique):一个番茄是如何让你工作更有效率的

如果你经常读一些关于提高工作效率或时间管理类的博客,一定听说过番茄时间管理法(Pomodoro Technique)。这是一种极好的帮助你集中注意力、获得更高工作效率的方法。

基本上,它的实施方法是这样的:

确定你想要做什么(例如:翻译一篇外文)。

设定一个25分钟的定时器。

工作,直到定时器时间到:这就是一个“番茄钟”。

休息5分钟,继续下一个番茄钟

每4个番茄钟做一次长时间的休息。

大多数人都会对其做一些细微调整来适应自己:例如,你可以选择每两个番茄钟——而不是四个,做一次长时间的休息。这特别是你刚开始应用这种方法时。

软件使用到的方法:

界面圆角实现代码:

//圆角

AWTUtilities.setWindowShape(this,

new RoundRectangle2D.Double( 0.0D, 0.0D,

getWidth(),

getHeight(), 26.0D, 26.0D));

隐藏Frame标题代码:

setUndecorated(true);

自己实现的标题,标题是一个panel,给标题增加了鼠标点击移动的事件:

public class MouseMoveListener extends MouseAdapter implements MouseMotionListener {

private Component parentComponent;

private Component dragCom;

private Point offset;

public synchronized void install(Component comp,Component dragCom) {

uninstall();

parentComponent = comp;

this.dragCom = dragCom;

dragCom.addMouseListener(this);

dragCom.addMouseMotionListener(this);

}

public synchronized void uninstall() {

if (dragCom != null) {

dragCom.removeMouseListener(this);

dragCom.removeMouseMotionListener(this);

dragCom = null;

}

}

@Override

public void mousePressed(MouseEvent e) {

if (e.getSource() == dragCom)

offset = e.getPoint();

}

@Override

public void mouseDragged(MouseEvent e) {

if (e.getSource() != dragCom)

return;

final int x = parentComponent.getX();

final int y = parentComponent.getY();

final Point lastAt = e.getPoint();

parentComponent.setLocation(x + lastAt.x - offset.x, y + lastAt.y - offset.y);

}

}

上面代码使用方法如下:

MouseMoveListener mouseMoveListener = new MouseMoveListener();

mouseMoveListener.install(this, titlePanel);

install参数第一个是当前的窗体,第二个是可以点击移动的对象。

系统托盘图标实现如下:

private void initTrayIcon() {

PopupMenu popup = new PopupMenu();

MenuItem showItem = new MenuItem("显示窗体");

ActionListener listener = new ActionListener() {

public void actionPerformed(ActionEvent e) {

setVisible(true);

setExtendedState(Frame.NORMAL);

SystemTray.getSystemTray().remove(trayIcon);

}

};

showItem.addActionListener(listener);

popup.add(showItem);

MenuItem exitItem = new MenuItem("退出");

exitItem.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

SystemTray.getSystemTray().remove(trayIcon);

System.exit(0);

}

});

popup.add(exitItem);

// 根据image、提示、菜单创建TrayIcon

this.trayIcon = new TrayIcon(Icon.icon16.getImage(), "\u756a\u8304\u65f6\u95f4\u7ba1\u7406", popup);

// 给TrayIcon添加事件监听器

this.trayIcon.addActionListener(listener);

}

public void minimizeToTray() {

SystemTray tray = SystemTray.getSystemTray();

try {

tray.add(this.trayIcon);

} catch (AWTException ex) {

ex.printStackTrace();

}

}

在eclipse中运行右键菜单时,如果有

乱码,可以在myeclipse中做如下修改(正常环境一般不会乱码):

在Run configration中

0818b9ca8b590ca3270a3433284dd417.png

添加:-Dfile.encoding=GB18030

倒计时:使用的timer和timertask

界面布局,多层的jpanel嵌套使用BorderLayout,3个按钮显示的panel使用了CardLayout

运行截图:

0818b9ca8b590ca3270a3433284dd417.png

使用说明:

界面中间为25分钟的番茄时间,

左侧按钮为5分钟的短时间休息,

右侧为10分钟的长时间休息。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值