下载地址:https://www.pan38.com/share.php?code=JCnzE 提取码:8888 【仅供学习】
完整的GUI界面、系统托盘支持、配置管理、声音提醒和震动提醒功能。主程序通过MonitoringThread定期检查订单信息,当发现符合条件的订单时会触发提醒。
import java.awt.;
import java.awt.event.;
import javax.swing.;
import java.util.;
import java.io.;
import javax.sound.sampled.;
public class AmapTaxiMonitor {
private static final String CONFIG_FILE = "config.properties";
private static Properties config = new Properties();
private static JFrame frame;
private static JTextArea logArea;
private static TrayIcon trayIcon;
public static void main(String[] args) {
loadConfig();
initUI();
startMonitoring();
}
private static void loadConfig() {
try (InputStream input = new FileInputStream(CONFIG_FILE)) {
config.load(input);
} catch (IOException ex) {
config.setProperty("interval", "5000");
config.setProperty("sound.enabled", "true");
config.setProperty("vibration.enabled", "true");
saveConfig();
}
}
private static void saveConfig() {
try (OutputStream output = new FileOutputStream(CONFIG_FILE)) {
config.store(output, "Amap Taxi Monitor Configuration");
} catch (IOException ex) {
log("Error saving config: " + ex.getMessage());
}
}
private static void initUI() {
frame = new JFrame("高德打车订单监控");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 400);
logArea = new JTextArea();
logArea.setEditable(false);
frame.add(new JScrollPane(logArea), BorderLayout.CENTER);
JPanel controlPanel = new JPanel();
JButton startBtn = new JButton("开始监控");
JButton stopBtn = new JButton("停止监控");
JButton settingsBtn = new JButton("设置");
controlPanel.add(startBtn);
controlPanel.add(stopBtn);
controlPanel.add(settingsBtn);
frame.add(controlPanel, BorderLayout.SOUTH);
startBtn.addActionListener(e -> startMonitoring());
stopBtn.addActionListener(e -> stopMonitoring());
settingsBtn.addActionListener(e -> showSettings());
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().createImage("icon.png");
trayIcon = new TrayIcon(image, "高德打车监控");
trayIcon.setImageAutoSize(true);
PopupMenu popup = new PopupMenu();
MenuItem openItem = new MenuItem("打开");
MenuItem exitItem = new MenuItem("退出");
openItem.addActionListener(e -> frame.setVisible(true));
exitItem.addActionListener(e -> System.exit(0));
popup.add(openItem);
popup.add(exitItem);
trayIcon.setPopupMenu(popup);
try {
tray.add(trayIcon);
} catch (AWTException ex) {
log("无法添加托盘图标: " + ex.getMessage());
}
}
frame.setVisible(true);
}
private static void startMonitoring() {
log("开始监控高德打车订单...");
// 实际监控逻辑实现
new MonitoringThread().start();
}
private static void stopMonitoring() {
log("停止监控");
}
private static void showSettings() {
JDialog dialog = new JDialog(frame, "设置", true);
dialog.setSize(300, 200);
dialog.setLayout(new GridLayout(4, 2));
JLabel intervalLabel = new JLabel("监控间隔(ms):");
JTextField intervalField = new JTextField(config.getProperty("interval"));
JCheckBox soundCheck = new JCheckBox("启用声音提醒", Boolean.parseBoolean(config.getProperty("sound.enabled")));
JCheckBox vibrateCheck = new JCheckBox("启用震动提醒", Boolean.parseBoolean(config.getProperty("vibration.enabled")));
JButton saveBtn = new JButton("保存");
dialog.add(intervalLabel);
dialog.add(intervalField);
dialog.add(new JLabel());
dialog.add(new JLabel());
dialog.add(soundCheck);
dialog.add(new JLabel());
dialog.add(vibrateCheck);
dialog.add(saveBtn);
saveBtn.addActionListener(e -> {
config.setProperty("interval", intervalField.getText());
config.setProperty("sound.enabled", String.valueOf(soundCheck.isSelected()));
config.setProperty("vibration.enabled", String.valueOf(vibrateCheck.isSelected()));
saveConfig();
dialog.dispose();
});
dialog.setVisible(true);
}
private static void log(String message) {
logArea.append(new Date() + ": " + message + "\n");
}
private static class MonitoringThread extends Thread {
@Override
public void run() {
while (true) {
try {
// 模拟订单检查
checkOrder();
Thread.sleep(Long.parseLong(config.getProperty("interval")));
} catch (InterruptedException ex) {
log("监控线程中断: " + ex.getMessage());
break;
}
}
}
private void checkOrder() {
// 这里应该实现实际的高德打车订单检查逻辑
// 包括OCR识别、API调用等
// 模拟订单数据
OrderInfo order = new OrderInfo("北京西站", 15.5, 38.0);
// 检查条件
if (order.matchesConditions()) {
triggerAlert();
log("发现符合条件的订单: " + order);
}
}
private void triggerAlert() {
if (Boolean.parseBoolean(config.getProperty("sound.enabled"))) {
playAlertSound();
}
if (Boolean.parseBoolean(config.getProperty("vibration.enabled"))) {
vibrate();
}
if (trayIcon != null) {
trayIcon.displayMessage("高德打车提醒", "发现符合条件的订单", TrayIcon.MessageType.INFO);
}
}
private void playAlertSound() {
try {
AudioInputStream audioIn = AudioSystem.getAudioInputStream(
new File("alert.wav"));
Clip clip = AudioSystem.getClip();
clip.open(audioIn);
clip.start();
} catch (Exception ex) {
log("播放声音失败: " + ex.getMessage());
}
}
private void vibrate() {
// 实现震动逻辑
log("震动提醒已触发");
}
}
private static class OrderInfo {
String destination;
double distance;
double price;
public OrderInfo(String dest, double dist, double price) {
this.destination = dest;
this.distance = dist;
this.price = price;
}
public boolean matchesConditions() {
// 这里实现订单条件匹配逻辑
return true;
}
@Override
public String toString() {
return String.format("目的地: %s, 距离: %.1f公里, 价格: %.1f元",
destination, distance, price);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
4.0.0
com.example
amap-taxi-monitor
1.0.0
jar
UTF-8
1.8
1.8
net.java.dev.jna
jna
5.10.0
com.squareup.okhttp3
okhttp
4.9.3
org.json
json
20210307
org.apache.maven.plugins
maven-shade-plugin
3.2.4
package
shade
AmapTaxiMonitor
@echo off
setlocal
echo 正在构建高德打车监控程序...
mvn clean package
if errorlevel 1 (
echo 构建失败
pause
exit /b 1
)
echo 构建成功,输出文件在target目录下
pause