我正在开发一个使用Java set的库存管理系统,我希望系统在库存数量低于设定的阈值时显示通知。例如,当数据库中的项目数量低于数据库中的项目数量时,50..The系统应向用户显示通知。虽然我已经研究过了,但结果并不完全符合我的需要。
发布于 2014-07-04 21:32:25
如果我正确地理解了您的问题,您正在寻找一种可能性来通知用户发生的问题。Swing有两种标准的实现方式:弹出对话框消息(例如here)和system tray messages。
你也可以使用你自己的消息传递服务。例如,您可以为应用程序实现状态栏,并使用它来显示消息。Here是一个简单的例子,你可以做到这一点。
发布于 2014-07-04 23:13:33
通知用户应用程序状态的方法在很大程度上取决于应用程序的可视化结构和运行该应用程序的平台。如果您的应用程序以桌面环境为目标,并且您所投射的消息不会提醒用户某些非常重要的事情,那么一个小状态栏可能是一个很好的选择。
如果您的目标环境具有有限的屏幕空间,并且需要确保用户看到消息,那么覆盖在主应用程序上的对话框窗口可能就是为您准备的。下面是一个简单明了的例子,展示了覆盖在主应用程序框架上的对话框可能的样子。
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class DialogExample extends JFrame
{
private final static String DIALOG_TITLE = "Warning Dialog";
private final static int DIALOG_ICON = JOptionPane.WARNING_MESSAGE;
private final JButton openPopupBtn;
public DialogExample()
{
this.openPopupBtn = new JButton("Open Dialog");
this.openPopupBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(DialogExample.this, "You just opened a dialog.", DIALOG_TITLE, DIALOG_ICON);
}
});
this.setTitle("Dialog Example");
this.setSize(640,480);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.add(this.openPopupBtn);
this.setResizable(false);
}
public static void main(String[] args) {
JFrame dialogExample = new DialogExample();
dialogExample.setVisible(true);
}
}如果你喜欢第二种方法,推荐阅读How to Make Dialogs。该页面还展示了为这些对话框添加一点丰富性的能力。
https://stackoverflow.com/questions/24574456
复制相似问题