51,397
社区成员




package com.java24hours;
import javax.swing.*;
import java.awt.*;
import java.io.*;
public class Directory extends JFrame{
static File path;
public Directory(){
super("Please Select Directory:");
setLookAndFeel();
setSize(225,80);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FlowLayout flo=new FlowLayout();
setLayout(flo);
JFileChooser directory=new JFileChooser();
directory.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
directory.showOpenDialog(Directory.this);
path=directory.getSelectedFile();
add(directory);
setVisible(true);
}
private void setLookAndFeel(){
try{
UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.nimbus.NImbusLookAndFeel"
);
}catch (Exception exc){
//ignore error
}
}
public static void main(String[] arugments){
int i=1;
new Directory();
File[] contents = path.listFiles();
for(File content:contents){
String name=content.getName();
StringBuilder newName=new StringBuilder();
newName.append(Integer.toString(i));
newName.append("_").append(name);
File newFile=new File(path.toString()+"/"+newName.toString());
content.renameTo(newFile);
i++;
}
System.exit(0);
}
}
package com.java24hours;
import javax.swing.*;
import java.awt.*;
import java.io.*;
public class Directory extends JFrame{
static File path;
JFileChooser directory=new JFileChooser();
public Directory(){
super("Document number");
setLookAndFeel();
setSize(225,80);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FlowLayout flo=new FlowLayout();
setLayout(flo);
directory.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
directory.showOpenDialog(Directory.this);
path=directory.getSelectedFile(); //important
add(directory);
setVisible(true);
}
private void setLookAndFeel(){
try{
UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.nimbus.NImbusLookAndFeel"
);
}catch (Exception exc){
//ignore error
}
}
public static void main(String[] arugments){
int i=1;
new Directory();
File[] contents = path.listFiles();
for(File content:contents){
if(content.isHidden()){
continue;}else{
String name=content.getName();
StringBuilder newName=new StringBuilder();
String strnumber=""+i;
newName.append(strnumber);
newName.append("_").append(name);
File newFile=new File(path.toString()+"/"+newName.toString());
content.renameTo(newFile);
i++;
}
}
System.exit(0);
}
}
剩下最后一个疑问:运行程序后界面没有任何动作提示,只是显示一个下拉列表,让用户不清楚该如何操作。加了JLabel组件仍然无显示。该如何处理?