Code Monkey home page Code Monkey logo

system-monitoring's Introduction

Java简易系统监视器 system-monitoring

image

Java Swing applet, real-time monitoring system CPU usage and memory usage.

Java Swing小程序,实时监测系统CPU使用率和内存使用率。

Java简易系统监视器system-monitoring:实时显示CPU使用率、内存使用率、电脑电池剩余电量、时间(时、分、秒)。创建系统托盘,设置系统托盘菜单,窗体置顶显示。通过jna调用dll文件读取电池数据。

项目与工具

Maven、Java 8、Swing、maven-assembly-plugin(jar-with-dependencies)、jna、dll

JNA

https://github.com/java-native-access/jna

https://github.com/java-native-access/jna/blob/master/www/WindowsDevelopmentEnvironment.md

预览图

Snipaste_2021-06-13_16-24-00 image image image

v1.2.2菜单预览

图片

v2.0.0预览图

Snipaste_2022-01-18_14-37-23 Snipaste_2022-01-18_14-36-39 Snipaste_2022-01-18_14-36-42 Snipaste_2022-01-18_14-36-45

功能说明

1 Java简易系统监视器system-monitoring:实时显示CPU使用率、内存使用率、笔记本电脑电池剩余电量、时间(时、分、秒)。CPU使用率、内存使用率和时间每秒更新一次,笔记本电脑电池剩余电量每15秒更新一次。

2 创建系统托盘,设置系统托盘菜单,窗体置顶显示。

3 系统托盘按钮:

--3.1 移动(或固定):点击后可移动或固定窗体。

--3.2 刷新:点击可刷新窗体,当窗体显示异常时可使用。

--3.3 布局:可更改窗体布局,可选“单列布局”、“双列布局”。(效果图为双列布局)

--3.4 显示:可选择需要显示的参数,可勾选“CPU”、“内存”、“电量”、“时间”。

--3.5 退出程序:点击可退出程序。

4 窗体不可移动至屏幕外。

5 窗体大小可根据显示的参数个数自动适配。

6 点击系统托盘后,弹出多级菜单,当鼠标点击非菜单区域,弹出的多级菜单会自动消失。(基于JFrame+JPopupMenu实现)

7 记忆功能:当修改布局、显示标签以及移动窗体位置之后,会记录修改后的状态,以便在下次启动时恢复该状态。

项目说明

  1. 窗体使用JFrame,且自定义样式。
  2. (旧版)菜单栏使用JPopupMenu,“当菜单栏显示时,鼠标左击菜单栏之外的区域也可隐藏菜单栏”的技术点为jnativehook全局监听鼠标左击。详细说明:由于“创建点击图标时的弹出菜单方案二”中,弹出的菜单无法消失,会一直显示,所以需要根据鼠标是否悬浮于菜单上以及鼠标左键是否点击来判断是否需要隐藏菜单:若鼠标不在菜单上并且鼠标左键点击了并且菜单是显示状态,则隐藏菜单。默认设置为鼠标未悬浮于菜单之上、鼠标未点击、菜单未显示。其中,鼠标是否悬浮于菜单上的判断条件包含鼠标是否悬浮于菜单上、鼠标是否悬浮于按钮上。
  3. (旧版)菜单栏创建方案有两种,此项目使用的是方案二JPopupMenu,方案一PopupMenu的代码也保留在项目中(已注释)。简要说明采用方案二的原因:使用PopupMenu创建的菜单栏,无法添加鼠标监听,局限性太大。
  4. v2.0.0+版本采用JFrame+JPopupMenu实现系统托盘多级菜单

项目地址

https://github.com/cxzgwing/system-monitoring

相关博客

[1] 晨曦之光Wing.Java简易系统监视器.2021-06-13 18:08:36 https://blog.csdn.net/qq_36533690/article/details/117881862

[2] 晨曦之光Wing.Java简易系统监视器system-monitoring.2022-01-18 16:15:59 https://blog.csdn.net/qq_36533690/article/details/122559092

[3] 晨曦之光Wing.jar调用dll文件提示找不到指定的模块Unable to load library.2022-01-26 23:00:10 https://blog.csdn.net/qq_36533690/article/details/122709535

[4] 晨曦之光Wing.Java简易系统监视器system-monitoring系列:增加记忆功能.2022-04-05 22:22:27 https://blog.csdn.net/qq_36533690/article/details/123978313

分支说明

main:主分支。

first:最初版本分支,为防止到最后被改得“面目全非”、不便于查找,特别新建该分支,保留最初版本。

system-monitoring's People

Contributors

cxzgwing avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

system-monitoring's Issues

窗体左右两边出现白条

image
image
在长时间运行后,鼠标右击系统托盘弹出菜单,此时窗体左右两边会出现白条(开机后到达屏锁界面,等待一段时间后再输入密码,显示桌面后窗体也会该情况)。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.