|
|
Исходный текст программы FileInfo.java
|
Оглавление |
Назад
// ==========================================
// FileInfo.java
// (C) Alexandr Frolov, 1998
// E-mail: frolov@glasnet.ru
// Web: http://www.glasnet.ru/~frolov
// ==========================================
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class FileInfo
{
public static void main(String args[])
{
FrameWindow frame;
frame = new FrameWindow(
"Show File Information");
frame.setVisible(true);
}
}
// =======================================
// Class FrameWindow
// =======================================
class FrameWindow extends Frame
implements ActionListener, WindowListener
{
TextArea ta;
MenuBar mb;
Menu mFile;
MenuItem miOpen;
MenuItem miExit;
FileDialog fdlg;
// ============================================
// FrameWindow
// ============================================
public FrameWindow(String szTitle)
{
super(szTitle);
setSize(400, 300);
mb = new MenuBar();
mFile = new Menu("File");
miOpen = new MenuItem("Open...");
mFile.add(miOpen);
mFile.add("-");
miExit = new MenuItem("Exit");
mFile.add(miExit);
mb.add(mFile);
miOpen.addActionListener(this);
miExit.addActionListener(this);
setMenuBar(mb);
this.addWindowListener(this);
ta = new TextArea(10, 30);
setLayout(new BorderLayout());
add("Center", ta);
}
// ============================================
// actionPerformed
// ============================================
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals(miOpen))
{
fdlg = new FileDialog(this, "Select file",
FileDialog.LOAD);
fdlg.show();
if(fdlg.getFile() == null)
return;
File f = new File(fdlg.getDirectory(),
fdlg.getFile());
if(f.exists())
{
ta.append(
"---------------------------\n");
ta.append("Absolute path: " +
f.getAbsolutePath() + "\n");
try
{
ta.append("Canonical path: " +
f.getCanonicalPath() + "\n");
}
catch(IOException ex) {}
ta.append("Path: " +
f.getPath() + "\n");
ta.append("Name: " +
f.getName() + "\n");
ta.append("Parent: " +
f.getParent() + "\n");
ta.append("Lenth: " +
f.length() + " bytes\n");
if(f.canRead())
{
ta.append("Can read from file\n");
}
if(f.canWrite())
{
ta.append("Can write to file\n");
}
}
}
else if(e.getSource().equals(miExit))
{
setVisible(false);
System.exit(0);
}
}
// ============================================
// windowClosing
// ============================================
public void windowClosing(WindowEvent e)
{
setVisible(false);
System.exit(0);
}
public void windowOpened(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
}
|
|
|