You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
J-WatchList/src/main/ui/guicomp/AddButt.java

39 lines
1.3 KiB

package ui.guicomp;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;
import data.WatchList;
public class AddButt extends JButton {
private WatchList wlist;
public AddButt(WatchList wlist) {
super("Add Stock...");
//https://coderanch.com/t/580497/java/JButton-clicked-action
if (getActionListeners().length < 1) {
addActionListener(new AddButtList());
}
this.wlist = wlist;
}
private class AddButtList implements ActionListener {
public void actionPerformed(ActionEvent e) {
//https://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#input
//https://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html
System.out.println("Count of listeners: " + ((JButton) e.getSource()).getActionListeners().length);
String userin = (String)JOptionPane.showInputDialog("Enter the identifier:");
if ((userin != null) && (userin.length() > 0)) {
new Thread(new Runnable() {
@Override
public void run() {
wlist.addStock(userin);
wlist.updateList();
}
}).start();
}
}
}
}