- butSrcs.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- // TODO Auto-generated method stub
- fod = new FileDialog(myFrame, "open", FileDialog.LOAD);
- fod.setVisible(true);
- String dir = fod.getDirectory();
- String fileName = fod.getFile();
- if(dir==null||fileName==null)
- return;
- JTextField tf = new JTextField(30);//@1
- tf.setText(dir+fileName);
- tf.setEditable(false);
- srcs.add(tf.getText());
- JButton rm = new JButton("删除");//@2
- rm.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- // TODO Auto-generated method stub
- JTextField tf = tf;//这里的tf 如何才能引用 @1 的 tf???
- JButton rm = rm;//这里的rm 如何引用 @2
- myFrame.remove(tf);
- myFrame.remove(rm);
- srcs.remove(tf.getText());
- }
- });
- myFrame.add(tf);
- myFrame.add(rm);
- myFrame.validate();
- myFrame.repaint();
- }
- });
复制代码 |
|