Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
- public class project3 extends Frame implements ActionListener, WindowListener
- { // start of class project 3
- private static final long serialVersionUID = 1L;
- File curDir;
- Button OKButton = new Button("OK");
- Button TargetButton = new Button("Target");
- Label TargetLabel = new Label("Select a Target Directory");
- Label sourceSelected = new Label("MAN THIS PROJECT MIGHT BE HARD");
- Label sourceLabel = new Label("Source: ");
- Label FilenameLabel = new Label("File Name: ");
- TextField Filename = new TextField(70);
- List contentsList = new List(12);
- boolean targ_file = false;
- boolean source_file = false;
- boolean output = false;
- project3(String dir)
- {
- /***********************************************************
- * THIS IS ALL GUI DESIGN
- ************************************************************/
- int[] column_width = { 1, 1, 1,
- 1, 1, 1,
- 1, 1 };
- int[] row_height = { 1, 1, 1,
- 1, 1, 1,
- 1, 1, 1,
- 1, 1, 1,
- 1, 1, 1,
- 1, 1, 1 };
- double[] column_weight = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
- double[] row_weight = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
- GridBagLayout gbLayout = new GridBagLayout();
- GridBagConstraints gbc = new GridBagConstraints();
- gbLayout.rowWeights = row_weight;
- gbLayout.rowHeights = row_height;
- gbLayout.columnWidths = column_width;
- gbLayout.columnWeights = column_weight;
- this.setLayout(gbLayout);
- this.setSize(640, 320);
- gbc.weightx = 1.0D;
- gbc.weighty = 1.0D;
- gbc.gridx = 0;
- gbc.gridy = 0;
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gbc.fill = GridBagConstraints.BOTH;
- gbLayout.setConstraints(this.contentsList, gbc);
- add(contentsList);
- gbc = new GridBagConstraints();
- gbc.anchor = GridBagConstraints.EAST;
- gbLayout.setConstraints(sourceLabel, gbc);
- add(sourceLabel);
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gbc.anchor = GridBagConstraints.WEST;
- gbLayout.setConstraints(sourceSelected, gbc);
- add(sourceSelected);
- gbc = new GridBagConstraints();
- gbc.anchor = GridBagConstraints.EAST;
- gbLayout.setConstraints(TargetButton, gbc);
- add(TargetButton);
- gbc.fill = GridBagConstraints.BOTH;
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gbLayout.setConstraints(TargetLabel, gbc);
- add(TargetLabel);
- gbc = new GridBagConstraints();
- gbLayout.setConstraints(Filename, gbc);
- gbc.anchor = GridBagConstraints.EAST;
- gbLayout.setConstraints(FilenameLabel, gbc);
- gbc.fill = GridBagConstraints.BOTH;
- gbLayout.setConstraints(OKButton, gbc);
- add(FilenameLabel);
- add(Filename);
- add(OKButton);
- pack();
- setVisible(true);
- /****************************************************
- * END GUI DESIGN!!
- *****************************************************/
- addWindowListener(this);
- this.Filename.addActionListener(this);
- this.TargetButton.addActionListener(this);
- this.OKButton.addActionListener(this);
- this.contentsList.addActionListener(this);
- setFont(new Font("Monospaced", 0, 12));
- display(dir);
- } // end of Main constructor
- public void display(String dir)
- {
- boolean flag = false;
- if(dir != null) // if not initilization call
- {
- if(dir.equals("..")) // if looking for the parent directory
- {
- curDir = new File(curDir.getParent()); // get it
- }
- else // otherwise
- {
- File temp = new File(curDir, dir); // make temp file for manip of the passed string.
- if (temp.isDirectory()) // if the passed in string is a directory
- {
- curDir = new File(curDir, dir); //
- }
- if ((targ_file==true) && (source_file==true)) // if the sequential machiene has got the target and the source file
- {
- FilenameLabel.setText(dir); // set the file name label to the passed string
- output=true; // set the output flag to true
- flag = true; // set the boolean variable flag to true so we do not execute the next if
- }
- if(flag==false) // if the above loop didn't execute get the absolute path name and make it the source lable,
- {
- sourceLabel.setText(curDir.getAbsolutePath() + "\\" + dir); // setting the text in the source label
- source_file = true; // and setting the flag
- }
- }
- }
- String [] names = null;
- try {
- names = curDir.list(); // making the string array
- }
- catch (NullPointerException e) {
- System.out.println("It's likely that it's not a directory.");
- }
- System.out.println("curDir list: " + names);
- if(names==null)
- {
- //curDir.list() says null if there is an I/O error or if it is not a directory.
- // says empty array if there is nothing in the array, in which case the only thing shown should be ..
- //names = new String[0];
- }
- else // begin else A
- {
- setTitle(curDir.getAbsolutePath()); // set the title of the window to the current directory with full absolute path
- for (int i=0; i < names.length; i++)
- {
- File temp = new File(names[i]); // temp file for storage of current string for manipulation
- if(temp.isDirectory()==false) // if the current file isn't a directory, contune to next iteration of the for loop...
- {
- continue;
- //shouldnt this add to the contentsList component?
- }
- else // otherwise append a + sign to the filename cause it's a directory...
- {
- names[i] = names[i] + " +";
- //use the list() method to determine if it is not a directory and if it is, if it has anything in it
- }
- }
- }
- contentsList.removeAll(); // clear the display contentlist
- if(curDir.getParent()!=null) // if current directory has a parent, add the double dots to the list
- contentsList.add("..");
- // output the list to the screen
- int count=0;
- int length=0;
- length=names.length;
- while (count<=length)
- {
- contentsList.add(names[count]);
- }
- } // end of display
- public static void main(String[] args)
- {
- if (args.length > 0) {
- new project3(args[0]);
- } else {
- new project3(null);
- }
- } // end of main
- public void windowClosing(WindowEvent e)
- {
- }
- public void windowClosed(WindowEvent e)
- {
- }
- public void windowOpened(WindowEvent e)
- {
- }
- public void windowActivated(WindowEvent e)
- {
- }
- public void windowDeactivated(WindowEvent e)
- {
- }
- public void windowIconified(WindowEvent e)
- {
- }
- public void windowDeiconified(WindowEvent e)
- {
- }
- public void actionPerformed(ActionEvent e)
- {
- Object o = e.getSource();
- if (o == OKButton) {
- handleOKButton();
- }
- System.out.println("o: " + o);
- }
- void handleOKButton() {
- }
- } // end of class project 3
Add Comment
Please, Sign In to add comment