panel.add(jtf,BorderLayout.CENTER)
panel.add(jbt,BorderLayout.SOUTH)
jbt.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser jfc = new JFileChooser()
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
int returnVal = jfc.showOpenDialog(jfc)
if(returnVal == JFileChooser.APPROVE_OPTION){
filePath = jfc.getSelectedFile().getAbsolutePath()
jtf.setText(filePath)
File file = new File(filePath)
try {
FindAndReplaceService.replace(file)
//d出替换成功对话框
JOptionPane.showConfirmDialog(FindAndReplaceFrame.this, "替换成功","消息",JOptionPane.CLOSED_OPTION)
//点击确定按钮推出
} catch (Exception ee) {
JOptionPane.showConfirmDialog(FindAndReplaceFrame.this, "替换失败")
ee.printStackTrace()
}
}
}
})望采纳,谢谢。
楼主这样写试试p1_lab2=new JLabel("按钮",new ImageIcon("…….gif"),0)
p1_lab2.addMouseListener(this)//监听
public void mouseClicked(MouseEvent e) {
//判断
if(e.getSource()==this.p1_lab2){
。。。
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)