菜单栏怎么添加监听器代码
我写了一下代码:
JMenu mt = new JMenu("堆栈");
Monitor bh = new Monitor(s1);
mt.addActionListener(bh);
class Monitor implements ActionListener, ListSelectionListener {
private String s1;
public Monitor(String s) {
s1 = s;
}
public void valueChanged(ListSelectionEvent e) {
System.out.println("sdfa");
}
public void actionPerformed(ActionEvent e) {
try {
System.out.println("asdfasd");
BufferedReader br = new BufferedReader(new FileReader("D:\\java\\Test1\\45678.txt")); //读取字符流
String s = null;
while((s = br.readLine()) != null) { //一行一行的读取br的文件
s1 = s1 + s +"\n";
}
br.close();
} catch (IOException e1) {