/* * MainForm.java * * Created on esmaspäev, 18, Detsember 2000, 12:36 */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.filechooser.*; import javax.swing.event.*; import java.io.File; import java.util.*; /** * * @author tonu * @version */ public class MainForm extends javax.swing.JFrame { private javax.swing.JFileChooser jFileChooser; private javax.swing.JLabel jLabel; private javax.swing.JSlider jSlider1; private DistPanel distPanel; /** Creates new form MainForm */ public MainForm() { initComponents (); this.setSize(500, 400); //pack (); } /** This method is called from within the constructor to * initialize the form. */ private void initComponents () { jButtonFileDialog = new javax.swing.JButton (); addWindowListener (new java.awt.event.WindowAdapter () { public void windowClosing (java.awt.event.WindowEvent evt) { exitForm (evt); } } ); jButtonFileDialog.setLabel ("Sirvi..."); jButtonFileDialog.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { jButtonFileDialogActionPerformed (evt); } } ); getContentPane ().add (jButtonFileDialog, java.awt.BorderLayout.NORTH); jLabel = new JLabel(); jLabel.setText (""); getContentPane ().add (jLabel, java.awt.BorderLayout.SOUTH); jFileChooser = new javax.swing.JFileChooser (); jFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); distPanel = new DistPanel(); getContentPane ().add (distPanel, java.awt.BorderLayout.CENTER); jSlider1 = new javax.swing.JSlider (JSlider.VERTICAL,1, 10, 2); jSlider1.addChangeListener (new SliderListener()); getContentPane ().add (jSlider1, java.awt.BorderLayout.EAST); } // inner class class SliderListener implements ChangeListener { public void stateChanged (ChangeEvent evt) { distPanel.setVahem(jSlider1.getValue()); distPanel.repaint(); } } private void jButtonFileDialogActionPerformed (java.awt.event.ActionEvent evt) { int returnVal = jFileChooser.showOpenDialog(this); if(returnVal == JFileChooser.APPROVE_OPTION) { File f = jFileChooser.getSelectedFile(); File[] files = f.listFiles(); Vector punktid = new Vector(); int maxvahe = 0; for (int i = 0; i < files.length; i++) { File fi = files[i]; if (!fi.isDirectory()) { punktid.add(new Double(fi.length())); } } jLabel.setText(f.getAbsolutePath()+" (sisaldab "+punktid.size()+" faili)"); distPanel.setPoints(punktid); distPanel.repaint(); } } private void jFileChooserActionPerformed (java.awt.event.ActionEvent evt) { } /** Exit the Application */ private void exitForm(java.awt.event.WindowEvent evt) { System.exit (0); } /** * @param args the command line arguments */ public static void main (String args[]) { new MainForm ().show (); } private javax.swing.JButton jButtonFileDialog; }