txt文本文档内容提取的Java源码
发布网友
发布时间:2022-10-17 00:58
我来回答
共2个回答
热心网友
时间:2023-10-26 01:00
//看看这个能不能给你帮助
public class FormApp{
private myFrame frame;
private JTextField textField;
private JTextField textField_1;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FormApp window = new FormApp();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public FormApp() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new myFrame();
frame.setTitle("鼠标拖动文件测试");
frame.setBounds(100, 100, 352, 142);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JLabel lblNewLabel = new JLabel("源地址:");
lblNewLabel.setBounds(39, 26, 54, 15);
frame.getContentPane().add(lblNewLabel);
textField = new JTextField();
textField.setBounds(120, 23, 181, 21);
frame.getContentPane().add(textField);
textField.setColumns(10);
JLabel label = new JLabel("目标地址:");
label.setBounds(39, 62, 73, 15);
frame.getContentPane().add(label);
textField_1 = new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(120, 59, 181, 21);
frame.getContentPane().add(textField_1);
}
class myFrame extends JFrame implements DropTargetListener{
public myFrame(){
new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, this);
}
@Override
public void dragEnter(DropTargetDragEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void dragExit(DropTargetEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void dragOver(DropTargetDragEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void drop(DropTargetDropEvent dtde) {
// TODO Auto-generated method stub
System.out.println("--------------------------------------------------------");
try {
Transferable tr = dtde.getTransferable();
if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
System.out.println("file cp");
List list = (List) (dtde.getTransferable()
.getTransferData(DataFlavor.javaFileListFlavor));
File f = list.get(0);
textField.setText(ConfigUtils.getProperty(f.getAbsolutePath(),"From"));
textField_1.setText(ConfigUtils.getProperty(f.getAbsolutePath(),"To"));
dtde.dropComplete(true);
}else {
dtde.rejectDrop();
}
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (UnsupportedFlavorException ufe) {
ufe.printStackTrace();
}
}
@Override
public void dropActionChanged(DropTargetDragEvent arg0) {
// TODO Auto-generated method stub
}
}
}
/////////////////////////////////////////
config.ini
#Update 'To' value
#Wed Jul 16 10:18:07 CST 2014
To=C\:\\\u65B0\u5EFA\u6587\u4EF6\u5939
From=C\:\\NewErp
热心网友
时间:2023-10-26 01:01
拖进窗口?是类似html文件直接拖到ie然后运行的那种?追问是的,即 JFrame窗体实现DropTargetListener接口
public class TestResultView extends JFrame implements ActionListener,DropTargetListener{...}.
如果麻烦,就不用做窗体界面,直接能在控制台输出结果也行