当数据库中的数据(股票名称和价格)与雅虎财经的数据(股票名称和价格)匹配时,我的程序会提醒用户。在HarryJoy的帮助下,我能够实现弹出通知。
现在的问题是,所有功能仅适用于最后一帧(YHOO)。5 秒后或当我单击 closeButton 时,它不会 dispose()。谢谢!
if (stockPriceDB == popStockValue)
{
String header = "Stock: " + stock.getTicker() + " is now @ " + stock.getPrice();
String message = "";
popUpFrame = new JFrame();
popUpFrame.setSize(320,90);
popUpFrame.setUndecorated(true);
popUpFrame.getContentPane().setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
constraints.weightx = 1.0f;
constraints.weighty = 1.0f;
constraints.insets = new Insets(5, 5, 5, 5);
constraints.fill = GridBagConstraints.BOTH;
JLabel headingLabel = new JLabel(header);
ImageIcon headingIcon = new ImageIcon("images/alert.gif");
headingLabel.setIcon(headingIcon);
popUpFrame.getContentPane().add(headingLabel, constraints);
constraints.gridx++;
constraints.weightx = 0f;
constraints.weighty = 0f;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.NORTH;
closeButton = new JButton();
closeButton = new JButton(new AbstractAction("x")
{
private static final long serialVersionUID = 1L;
public void actionPerformed(final ActionEvent e)
{
popUpFrame.dispose();
}
});
closeButton.setMargin(new Insets(1, 4, 1, 4));
closeButton.setFocusable(false);
popUpFrame.getContentPane().add(closeButton, constraints);
constraints.gridx = 0;
constraints.gridy++;
constraints.weightx = 1.0f;
constraints.weighty = 1.0f;
constraints.insets = new Insets(5, 5, 5, 5);
constraints.fill = GridBagConstraints.BOTH;
JLabel messageLabel = new JLabel(message);
popUpFrame.getContentPane().add(messageLabel, constraints);
popUpFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
popUpFrame.setVisible(true);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Insets toolHeight = Toolkit.getDefaultToolkit().getScreenInsets(popUpFrame.getGraphicsConfiguration());
popUpFrame.setLocation(screenSize.width - popUpFrame.getWidth(), screenSize.height - toolHeight.bottom - (popUpFrame.getHeight() * (x+1)));
new Thread()
{
public void run()
{
try
{
Thread.sleep(5000);
popUpFrame.dispose();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
};
}.start();
}
}