Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gui;
- import java.awt.BorderLayout;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import javax.swing.BoxLayout;
- 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.JScrollPane;
- import javax.swing.JTextArea;
- import javax.swing.JTree;
- import javax.swing.filechooser.FileSystemView;
- import javax.swing.tree.DefaultMutableTreeNode;
- import javax.swing.tree.TreeSelectionModel;
- public class GUIExplorateur extends JFrame {
- /**
- *
- */
- private static final long serialVersionUID = 2098411530562087885L;
- private JTextArea jtarea;
- private JMenu menu, menu2, menu3, submenu;
- private JMenuItem bar1, bar2, bar3, subbar, subbar2;
- private JFileChooser jfc;
- private JScrollPane scrollPaneTree, scrollPaneArea;
- private JTree tree;
- public GUIExplorateur() {
- this("Explorateur de fichiers V0.1");
- }
- public GUIExplorateur(String title) {
- super(title);
- // ************************************ ICI DEBUT DU PARAMETRAGE MENU ************************************//
- JMenuBar mb = new JMenuBar();
- menu = new JMenu("File");
- menu2 = new JMenu("Search");
- menu3 = new JMenu("More");
- submenu = new JMenu("Settings");
- bar1 = new JMenuItem("New");
- bar1.addActionListener(new ActionFileSaver());
- bar2 = new JMenuItem("Open");
- bar2.addActionListener(new ActionFileChooser());
- bar3 = new JMenuItem("HALP ME");
- subbar = new JMenuItem("HAHA");
- subbar2 = new JMenuItem("YOUHOU");
- menu.add(bar1);
- menu.add(bar2);
- menu.add(bar3);
- submenu.add(subbar);
- submenu.add(subbar2);
- menu.add(submenu);
- mb.add(menu);
- mb.add(menu2);
- mb.add(menu3);
- this.setJMenuBar(mb);
- // ************************************ ICI FIN DU PARAMETRAGE MENU ************************************//
- // ********************************** ICI DEBUT DU PARAMETRAGE JTREE *********************************//
- DefaultMutableTreeNode DossierRacine = new DefaultMutableTreeNode("DossierRacine");
- DefaultMutableTreeNode Dossier1 = new DefaultMutableTreeNode("Dossier1");
- Dossier1.add(new DefaultMutableTreeNode("Fichier.txt"));
- Dossier1.add(new DefaultMutableTreeNode("Fichier.zip"));
- Dossier1.add(new DefaultMutableTreeNode("Fichier.jpeg"));
- Dossier1.add(new DefaultMutableTreeNode("Fichier.png"));
- DefaultMutableTreeNode Dossier2 = new DefaultMutableTreeNode("Dossier2");
- Dossier2.add(new DefaultMutableTreeNode("Fichier.doc"));
- Dossier2.add(new DefaultMutableTreeNode("Fichier.csv"));
- Dossier2.add(new DefaultMutableTreeNode("Fichier.css"));
- Dossier2.add(new DefaultMutableTreeNode("Fichier.zip"));
- Dossier2.add(new DefaultMutableTreeNode("Fichier.jar"));
- DossierRacine.add(Dossier1);
- DossierRacine.add(Dossier2);
- tree = new JTree(DossierRacine);
- tree.setPreferredSize(new Dimension(150,100));
- scrollPaneTree = new JScrollPane(tree);
- this.getContentPane().add(scrollPaneTree, BorderLayout.LINE_START);
- // ************************************ ICI FIN DU PARAMETRAGE JTREE ************************************//
- // ******************************** ICI DEBUT DU PARAMETRAGE JTEXTAREA **********************************//
- String details = "Détails : - MimeType - Chemin de Répertoire - Correspondance Signatures -Extension - Nom du fichier -etc \n";
- String errors = "Erreurs liés au fichier : ..................................................................................................";
- jtarea = new JTextArea(details + errors);
- scrollPaneArea = new JScrollPane(jtarea);
- jtarea.setEditable(false);
- jtarea.setPreferredSize(new Dimension(400,100));
- this.getContentPane().add(scrollPaneArea, BorderLayout.PAGE_END);
- // ******************************** ICI FIN DU PARAMETRAGE JTEXTAREA **********************************//
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setSize(750, 500);
- this.setLocation(850, 450);
- this.setVisible(true);
- }
- class ActionFileChooser implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- jfc = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());
- int returnValue = jfc.showOpenDialog(null);
- if (returnValue == JFileChooser.APPROVE_OPTION) {
- try {
- BufferedReader selectedFile = new BufferedReader(new FileReader(jfc.getSelectedFile()));
- String str;
- while ((str = selectedFile.readLine()) != null) {
- System.out.println(str);
- }
- selectedFile.close();
- } catch (FileNotFoundException e1) {
- System.out.println("File is not found!");
- } catch (IOException e1) {
- System.out.println("IOException");
- System.err.println(e1.getMessage());
- }
- }
- }
- }
- class ActionFileSaver implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- jfc = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());
- int returnValue = jfc.showSaveDialog(null);
- try {
- if (returnValue == JFileChooser.APPROVE_OPTION) {
- PrintWriter selectedFile = new PrintWriter(new FileWriter(jfc.getSelectedFile()));
- selectedFile.println(jfc.getSelectedFile());
- selectedFile.close();
- }
- } catch (IOException e1) {
- System.out.println("IOException");
- }
- }
- }
- /*public static void main(String[] args) {
- new GUIExplorateur();
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement