发布网友 发布时间:2022-05-14 07:31
共4个回答
热心网友 时间:2023-10-09 22:11
MARK!
编码中.......
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
* @author shy2850
* @since 2011-01-05
* @version 1.0
*/
public class FileViewer extends JFrame {
private static final long serialVersionUID = -7356603652178700622L;
String name = "(未选择文件)";
JPanel menuPanel = new JPanel();
JMenuBar mnbMain = new JMenuBar();
JLabel[] labels = new JLabel[]{
new JLabel("完整路径:"),
new JLabel("是否只读:"),
new JLabel("是否隐藏:"),
new JLabel("标准文件:"),
new JLabel("修改时间:"),
new JLabel("文件大小:"),
};
JTextField[] textFields = new JTextField[]
{
new JTextField(),
new JTextField(),
new JTextField(),
new JTextField(),
new JTextField(),
new JTextField(),
};
{
setResizable(false);
setLayout(null);
for (int i = 0; i < labels.length; i++) {
this.add(labels[i]);
labels[i].setBounds(100, 50+i*40, 100, 25);
this.add(textFields[i]);
textFields[i].setBounds(200, 50+i*40, 300, 25);
}
}
JMenu mnServer = new JMenu("选项");
JMenuItem[] mniServers = new JMenuItem[]{
new JMenuItem("打开"),
new JMenuItem("退出"),
};
{
menuPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
mnbMain.add(mnServer);
menuPanel.add(mnbMain);
mnbMain.setBounds(5, 0, 50, 30);
for (int i = 0; i < mniServers.length; i++) {
mnServer.add(mniServers[i]);
}
mniServers[0].addActionListener(new ActionListener() { //定义"打开"组件操作
public void actionPerformed(ActionEvent arg0) {
chooseToOpen();
}
});
mniServers[1].addActionListener(new ActionListener() { //定义"退出"组件操作
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
}
protected void chooseToOpen() {
File file = chooseFile();
if(null==file||!file.exists())return;
name = file.getName();
FileViewer.this.setTitle("文件查看器:"+name);
view(file);
}
private File chooseFile(){
JFileChooser chooser = new JFileChooser(); //构建文件选择器
int result = chooser.showDialog(null, "确定");
if (result==JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
System.out.println(file.getAbsolutePath());
} else {
System.out.println("未选择文件");
}
return chooser.getSelectedFile();
}
public void view(File file){ //定义浏览文件属性操作
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 hh:mm:ss");
textFields[0].setText(file.getAbsolutePath());
textFields[1].setText(file.setReadOnly()?"是":"否");
textFields[2].setText(file.isHidden()?"是":"否");
textFields[3].setText(file.isFile()?"是":"否");
textFields[4].setText(sdf.format(new Date(file.lastModified())));
textFields[5].setText(""+file.length()+"字节");
}
public FileViewer(int x,int y) {
this.setTitle("文件查看器:"+name);
this.setBounds(x, y, 600, 400);
this.setLayout(new BorderLayout());
this.add(menuPanel, BorderLayout.NORTH);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setVisible(true);
}
public FileViewer() {
this(200,200);
}
public static void main(String[] args) {
new FileViewer();
}
}
热心网友 时间:2023-10-09 22:12
写一个界面,内部去读properties文件,再将数据在界面显示出来!热心网友 时间:2023-10-09 22:12
问题说的详细点,别人好帮忙的啊热心网友 时间:2023-10-09 22:13
什么属性