Java select a file 🔎

Поделиться
HTML-код
  • Опубликовано: 11 сен 2024
  • Java jfilechooser file select GUI swing tutorial for beginners
    #Java #jfilechooser #file #select #GUI #swing #tutorial #beginners

Комментарии • 79

  • @BroCodez
    @BroCodez  4 года назад +35

    public class Main{
    public static void main(String[] args) {

    // JFileChooser = A GUI mechanism that let's a user choose a file (helpful for opening or saving files)

    new MyFrame();
    }
    }
    import java.awt.FlowLayout;
    import java.awt.event.*;
    import java.io.File;
    import javax.swing.*;
    public class MyFrame extends JFrame implements ActionListener{
    JButton button;

    MyFrame(){
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLayout(new FlowLayout());

    button = new JButton("Select File");
    button.addActionListener(this);

    this.add(button);
    this.pack();
    this.setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {

    if(e.getSource()==button) {

    JFileChooser fileChooser = new JFileChooser();

    fileChooser.setCurrentDirectory(new File(".")); //sets current directory

    int response = fileChooser.showOpenDialog(null); //select file to open
    //int response = fileChooser.showSaveDialog(null); //select file to save

    if(response == JFileChooser.APPROVE_OPTION) {
    File file = new File(fileChooser.getSelectedFile().getAbsolutePath());
    System.out.println(file);
    }
    }
    }
    }

    • @joyceasante8292
      @joyceasante8292 Год назад

      Practicing...
      public class Main{
      public static void main(String[]args){
      new MyFrame();
      }
      }
      *****************************
      import java.awt.FlowLayout;
      import java.awt.event.*;
      import java.io.File;
      import javax.swing.*;
      public class MyFrame extends JFrame implements ActionListener{
      JButton button;
      MyFrame(){
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      this.setLayout(new FlowLayout());
      button = new JButton("Choose a file");
      button.addActionListener(this);
      this.add(button);
      this.pack();
      this.setVisible(true);
      }
      @Override
      public void actionPerformed(ActionEvent e){
      if(e.getSource()==button){
      JFileChooser fileChooser = new JFileChooser();
      // fileChooser.setCurrentDirectory(new File(""));
      fileChooser.setCurrentDirectory(new File("C:\\Users\\Yaa\\Desktop"));

      //System.out.println(fileChooser.showOpenDialog(null));
      //int response = fileChooser.showOpenDialog(null);
      int response = fileChooser.showSaveDialog(null);
      if(response ==JFileChooser.APPROVE_OPTION){
      File file = new File(fileChooser.getSelectedFile().getAbsolutePath());
      System.out.println(file);
      }

      }
      }
      }

  • @revolutionaryfrog
    @revolutionaryfrog Год назад +7

    this channel has single handedly gotten me through all my JavaFX learning. Insane value.

  • @alexsimone5265
    @alexsimone5265 4 года назад +5

    bro this channel is so awesome. You have the most helpful vids, get straight to the point, and explain everything well. 10/10 major props to you

    • @BroCodez
      @BroCodez  4 года назад

      thanks for watching Alex

  • @pavelkvasnicka6856
    @pavelkvasnicka6856 Год назад

    This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro

  • @hisokuh2709
    @hisokuh2709 Месяц назад

    Big ups BroCodez u dun know, i was bare scared my code aint gon work but you solved it u mad lad!

  • @eugeneh5401
    @eugeneh5401 2 года назад

    Love your content, keep up the good work! Really appreciate your tutorials. You have helped me out countless of times!

  • @FukSN
    @FukSN 3 года назад +1

    Thanks Bro.
    Yet again a simple but effective tutorial.
    Even better as I added this to the menu tutorial and, I will now search out your video on actually opening a file and include that in the menu tutorial.
    Top job, please produce more, more MORE Java vids!!!

  • @eugenezuev7349
    @eugenezuev7349 3 месяца назад

    it's a really helpful tutorial, thanks

  • @speklex779
    @speklex779 10 месяцев назад

    Nice video

  • @bethgee910
    @bethgee910 3 года назад +2

    Great vid! Please could you link me to the videos you have on saving and opening the files?

  • @indrajithhettiarachchi5700
    @indrajithhettiarachchi5700 Год назад

    Keep it up bro

  • @annpadilla5638
    @annpadilla5638 8 месяцев назад

    Excellent content

  • @NatyTor
    @NatyTor 2 года назад

    hi bro, i so love your video man!!! keep going like this!!🤟🤟🤟

  • @attalaw36
    @attalaw36 3 года назад

    You're the best teacher.

  • @tristisludos
    @tristisludos 3 года назад

    Thanks for the video mate, you're a real help

  • @Mirtguitar
    @Mirtguitar 11 месяцев назад

    Good tutorial

  • @mediadimah22
    @mediadimah22 3 года назад

    Thanks for your great work! Please, maybe more explanation for each assignment.

  • @nhanthanh4493
    @nhanthanh4493 2 года назад

    nice

  • @angelcastineira2561
    @angelcastineira2561 Год назад

    Great video!

  • @mohamedoutlouhou8866
    @mohamedoutlouhou8866 3 года назад

    good job Bro

  • @augischadiegils.5109
    @augischadiegils.5109 3 года назад +1

    Very helpful :) thanks bro

  • @loaykoshak
    @loaykoshak 2 года назад

    thank you bro keep forward

  • @daniellima9370
    @daniellima9370 Год назад

    Thanks. Your video helped me a lot.

  • @rabbit_alt
    @rabbit_alt Год назад

    nice video, thanks.

  • @MrVegetox
    @MrVegetox 2 года назад

    Thanks, Brah!

  • @MrLoser-ks2xn
    @MrLoser-ks2xn Год назад

    Thanks!

  • @yazilimportali6431
    @yazilimportali6431 Год назад

    thanks that helped me

  • @guramee
    @guramee Год назад

    4:26 "Nuclear launch codes" xD

  • @user-oc1fe4dv3n
    @user-oc1fe4dv3n 2 года назад

    Thanks dude that helps a lot

  • @user-xc3di4pm7o
    @user-xc3di4pm7o 10 месяцев назад

    Thank you very much bro❤ you helped us a lot🎉

  • @shaynazoedeguzman7418
    @shaynazoedeguzman7418 2 года назад

    Excellent!

  • @sovxui3705
    @sovxui3705 3 года назад +1

    Is their a way to print it on a JTextArea when you open a file?

  • @MrSadeeq67
    @MrSadeeq67 3 года назад

    You are my Hero Bro.!

  • @fernandoribeiro4384
    @fernandoribeiro4384 2 года назад

    Love you bro! Thanks a lot for your vids, very helpful ! Comment done ehehehe enjoy and keep up! Best regards

  • @usamanadeem145
    @usamanadeem145 3 года назад

    Help ful

  • @MageHunter
    @MageHunter 2 года назад

    Thank you so mutch!!!!!!

  • @ibrahimylmaz8378
    @ibrahimylmaz8378 2 года назад

    thanks bro

  • @henriquefelinimena3693
    @henriquefelinimena3693 3 года назад

    thank you for the content

  • @muhammedkabbani6434
    @muhammedkabbani6434 2 года назад

    perfect

  • @maaahhdi
    @maaahhdi 3 года назад

    Very helpful.

  • @davidmonsalve8525
    @davidmonsalve8525 3 года назад

    bro, you're the best

  • @kagailawrence
    @kagailawrence 2 года назад

    super

  • @monwil3296
    @monwil3296 4 года назад

    Bro, 👍👌

  • @comandanteshran4123
    @comandanteshran4123 2 года назад

    thanks! it's what i need...

  • @abbasalaa2935
    @abbasalaa2935 2 месяца назад

    عاشت ايدك

  • @longkesh1971
    @longkesh1971 Год назад

    Thanks bro.

  • @alexshepel5599
    @alexshepel5599 3 года назад

    Awesome, bro :)

  • @nitindixit676
    @nitindixit676 9 месяцев назад

    thank you

  • @LISAtheNINJAA
    @LISAtheNINJAA 3 года назад

    Amazing!! :D

  • @robertofranciscoriosmorale4158
    @robertofranciscoriosmorale4158 2 года назад

    thnx dude, helped a lot

  • @gemma_sll
    @gemma_sll Год назад

    thanks man

  • @olajuwon4224
    @olajuwon4224 2 года назад

    Thank you brother. You earned a subscription from me.

  • @karimshalabi6878
    @karimshalabi6878 2 года назад

    how can you set this to open on action in a gui, for example i press a load file button and this comes up to choose a file etc...

  • @mdnadeemazam4382
    @mdnadeemazam4382 Год назад

    Instead of printing the path I want to store it in a String to use for another function, how can I get a from this function?

  • @ABC-zv1sd
    @ABC-zv1sd 2 года назад

    I am developing an android Filemanager app. I used checkbox to select files and folders(files+subfolders) . I want to add feature to copy paste the selected files and folders(files+subfolders) at same time like google Filemanager . How can i add this copy paste feature in my java android file manager??? Advance Thanks..

  • @dancing_frank_lee
    @dancing_frank_lee 3 года назад

    thank you so much

  • @javazantech
    @javazantech 8 месяцев назад

    Thanks from Brazil , how to save image path in mysql database

  • @masterofkaarsvet
    @masterofkaarsvet 2 года назад

    Is there a way to make a drag/drop interface for files?

  • @Liveafghan79
    @Liveafghan79 5 месяцев назад

  • @ROTEN31
    @ROTEN31 2 года назад

    I have a question, how can I copy the selected file?

  • @paveludovichenko9547
    @paveludovichenko9547 2 года назад

    could you add the implementation of DnD facilities for this button?

  • @zari_723
    @zari_723 2 года назад

    thanks

  • @kemann3815
    @kemann3815 2 года назад

    Perfecto

  • @ishmaelbrentuo
    @ishmaelbrentuo 2 года назад

    Pls how to u add file to read in Jframe ?
    Need help.

  • @lequangnghi194
    @lequangnghi194 2 года назад

    Hi, I've been wondering, instead of "this", what else that I can put in the addActionListener(this) that will match the parameter?

    • @programmer5834
      @programmer5834 2 года назад +1

      You can given parent component where you implement ActionListener . actually he using same class that why he use (this)
      I hope you understand

    • @spenzr6920
      @spenzr6920 2 года назад

      im assuming u asked this cz u did that in the main method
      in that case,
      you need to construct an object of your class (idk how to say it sry my eng isnt good)
      Here is my code, i hope u will get it
      import java.awt.FlowLayout;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import javax.swing.JButton;
      import javax.swing.JFrame;
      public class abc implements ActionListener {
      public static void main(String[] args) {
      JFrame frame = new JFrame("Title");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(420,420);
      frame.setLayout(null);
      //Creating the Button
      JButton button = new JButton("I am a button :D");
      button.setBounds(0, 0, 150,69);
      //creating an object of the class (idk how to say it lol sry but im sure yk of it)
      abc abcObject = new abc();
      //Using the object instead of this keyword
      button.addActionListener(abcObject);

      //There is also another way, i guess its called lambda expression
      //This has no relation to the previous button we created earlier
      JButton button2 = new JButton("2nd button");
      button2.setBounds(69,69,100,69);
      button2.addActionListener(e -> System.out.println("This action was performed using lambda expression"));


      //adding button and making frame visible
      frame.add(button);
      frame.add(button2);
      frame.setVisible(true);

      }
      @Override
      public void actionPerformed(ActionEvent e) {

      System.out.println("69420 ");

      }
      }

    • @spenzr6920
      @spenzr6920 2 года назад

      but i would recommend u doing the way he did in the tutorial. I think its simpler
      there are probably more ways to do it, this one is simplest, u just have to use 'this' and its done

  • @shawonmajid
    @shawonmajid 2 года назад

    8:34 Nuclear launch codes! :3

  • @andreasm6636
    @andreasm6636 2 года назад

    my uni project: stonks

  • @amr_badran2948
    @amr_badran2948 Год назад

    hello

  • @CptKaracho66
    @CptKaracho66 2 года назад

    A comment down below

  • @greeneggsandmushrooms9855
    @greeneggsandmushrooms9855 3 года назад

    file selects you

  • @akashsahu5716
    @akashsahu5716 Год назад

    bow down in front of bro

  • @zstar8397
    @zstar8397 10 месяцев назад

    Hey hope you are doing alright just I wanna say that
    GOD loved the world so much he sent his only begotten
    son Jesus to die a brutal death for us so that we can have eternal life and we can all accept this amazing gift this by simply trusting in Jesus, confessing that GOD raised him from the dead, turning away from your sins and forming a relationship with GOD.

  • @MZ-tz1bt
    @MZ-tz1bt 3 года назад

    super

  • @nawfalnjm5699
    @nawfalnjm5699 3 года назад

    thank you