私のプログラムは、データベース内のデータ(株名と価格)がYahoo Financeのデータ(株名と価格)と一致したときにユーザーに警告します。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();
}
}