package delnopdir;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.File;public class delNopDir extends JFrame{
private JLabel JLTargetDir=new JLabel("目标文件夹:");
private JTextField JTFTargetDir=new JTextField("");
private JButton JBSearch=new JButton("...");
public delNopDir() {
Container con=getContentPane();
con.setLayout(null);
setSize(400,200);
setTitle("删除空目录:");
JLTargetDir.setBounds(20,20,80,30);
con.add(JLTargetDir);
JTFTargetDir.setBounds(100,20,220,30);
con.add(JTFTargetDir);
JBSearch.setBounds(330,20,30,30);
con.add(JBSearch);
JBSearch.addActionListener(new search());
setVisible(true);
}
public JTextField getJTFTargetDir(){
return JTFTargetDir;
}
public static void main(String[] args)
{
delNopDir dnp=new delNopDir();
dnp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}class search implements ActionListener
{
JFileChooser fc;
public void actionPerformed(ActionEvent e)
{
fc=new JFileChooser();
if(JFileChooser.APPROVE_OPTION==fc.showOpenDialog(null))
{
File f=fc.getSelectedFile();
(new delNopDir()).getJTFTargetDir().setText(f.getAbsolutePath());//此处我创建的对象和在主程序创建的对象应该是两个对象,可我用这个对象却能设置那个对象的变量的值,求大侠解释下,万分感激
}
}
}
import javax.swing.*;
import java.awt.event.*;
import java.io.File;public class delNopDir extends JFrame{
private JLabel JLTargetDir=new JLabel("目标文件夹:");
private JTextField JTFTargetDir=new JTextField("");
private JButton JBSearch=new JButton("...");
public delNopDir() {
Container con=getContentPane();
con.setLayout(null);
setSize(400,200);
setTitle("删除空目录:");
JLTargetDir.setBounds(20,20,80,30);
con.add(JLTargetDir);
JTFTargetDir.setBounds(100,20,220,30);
con.add(JTFTargetDir);
JBSearch.setBounds(330,20,30,30);
con.add(JBSearch);
JBSearch.addActionListener(new search());
setVisible(true);
}
public JTextField getJTFTargetDir(){
return JTFTargetDir;
}
public static void main(String[] args)
{
delNopDir dnp=new delNopDir();
dnp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class search implements ActionListener
{
JFileChooser fc;
public void actionPerformed(ActionEvent e)
{
fc=new JFileChooser();
if(JFileChooser.APPROVE_OPTION==fc.showOpenDialog(null))
{
File f=fc.getSelectedFile();
JTFTargetDir.setText(f.getAbsolutePath());
}
}
}
}