SlideShare a Scribd company logo
FILE AND JFILECHOOSER OBJECTS
Chapter 10.2:
The JFileChooser Class
 A javax.swing.JFileChooser object allows the
user to select a file.
 To start the listing from a specific directory:
JFileChooser chooser = new JFileChooser( );
chooser.showOpenDialog(null);
JFileChooser chooser = new JFileChooser("D:/JavaPrograms/Ch12");
chooser.showOpenDialog(null);
The JFileChooser Class
Getting Info from JFileChooser
int status = chooser.showOpenDialog(null);
if (status == JFileChooser.APPROVE_OPTION) {
JOptionPane.showMessageDialog(null, "Open is clicked");
} else { //== JFileChooser.CANCEL_OPTION
JOptionPane.showMessageDialog(null, "Cancel is clicked");
}
File selectedFile = chooser.getSelectedFile();
File currentDirectory = chooser.getCurrentDirectory();

More Related Content

Viewers also liked

Chapter 4.3
Chapter 4.3Chapter 4.3
Chapter 4.3sotlsoc
 
Chapter 6.3
Chapter 6.3Chapter 6.3
Chapter 6.3sotlsoc
 
Chapter 3.2
Chapter 3.2Chapter 3.2
Chapter 3.2sotlsoc
 
Final flipbook presentation
Final flipbook presentationFinal flipbook presentation
Final flipbook presentationTaryn Pilon
 
Chapter 9.3
Chapter 9.3Chapter 9.3
Chapter 9.3sotlsoc
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6sotlsoc
 
Chapter 8.1
Chapter 8.1Chapter 8.1
Chapter 8.1sotlsoc
 
Chapter 4.0
Chapter 4.0Chapter 4.0
Chapter 4.0sotlsoc
 
정몽준 서울시장 새누리당 후보 정책 공약 _ 33한서울88한경제
정몽준 서울시장 새누리당 후보 정책 공약 _ 33한서울88한경제 정몽준 서울시장 새누리당 후보 정책 공약 _ 33한서울88한경제
정몽준 서울시장 새누리당 후보 정책 공약 _ 33한서울88한경제 MJeNews
 
Chapter 11.1
Chapter 11.1Chapter 11.1
Chapter 11.1sotlsoc
 
Chapter 11.3
Chapter 11.3Chapter 11.3
Chapter 11.3sotlsoc
 
Cyberbullying by alex pitcher
Cyberbullying by alex pitcherCyberbullying by alex pitcher
Cyberbullying by alex pitcher
Phillip Pitcher
 
Presentacion leydi perezI
Presentacion leydi perezIPresentacion leydi perezI
Presentacion leydi perezIleydip2009
 
Dangers to social media
Dangers to social mediaDangers to social media
Dangers to social mediaRyan Ward
 
Smart phone. addiction. blindness
Smart phone. addiction. blindnessSmart phone. addiction. blindness
Smart phone. addiction. blindness
SunnyBabyBabe
 

Viewers also liked (16)

Chapter 4.3
Chapter 4.3Chapter 4.3
Chapter 4.3
 
Chapter 6.3
Chapter 6.3Chapter 6.3
Chapter 6.3
 
Chapter 3.2
Chapter 3.2Chapter 3.2
Chapter 3.2
 
Final flipbook presentation
Final flipbook presentationFinal flipbook presentation
Final flipbook presentation
 
Chapter 9.3
Chapter 9.3Chapter 9.3
Chapter 9.3
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6
 
Chapter 8.1
Chapter 8.1Chapter 8.1
Chapter 8.1
 
Chapter 4.0
Chapter 4.0Chapter 4.0
Chapter 4.0
 
e-Sports
e-Sportse-Sports
e-Sports
 
정몽준 서울시장 새누리당 후보 정책 공약 _ 33한서울88한경제
정몽준 서울시장 새누리당 후보 정책 공약 _ 33한서울88한경제 정몽준 서울시장 새누리당 후보 정책 공약 _ 33한서울88한경제
정몽준 서울시장 새누리당 후보 정책 공약 _ 33한서울88한경제
 
Chapter 11.1
Chapter 11.1Chapter 11.1
Chapter 11.1
 
Chapter 11.3
Chapter 11.3Chapter 11.3
Chapter 11.3
 
Cyberbullying by alex pitcher
Cyberbullying by alex pitcherCyberbullying by alex pitcher
Cyberbullying by alex pitcher
 
Presentacion leydi perezI
Presentacion leydi perezIPresentacion leydi perezI
Presentacion leydi perezI
 
Dangers to social media
Dangers to social mediaDangers to social media
Dangers to social media
 
Smart phone. addiction. blindness
Smart phone. addiction. blindnessSmart phone. addiction. blindness
Smart phone. addiction. blindness
 

More from sotlsoc

Chapter 2.0 new
Chapter 2.0 newChapter 2.0 new
Chapter 2.0 newsotlsoc
 
Chapter 1.0 new
Chapter 1.0 newChapter 1.0 new
Chapter 1.0 newsotlsoc
 
Chapter 3.0 new
Chapter 3.0 newChapter 3.0 new
Chapter 3.0 newsotlsoc
 
Chapter 6.5 new
Chapter 6.5 newChapter 6.5 new
Chapter 6.5 newsotlsoc
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3sotlsoc
 
Chapter 11.4
Chapter 11.4Chapter 11.4
Chapter 11.4sotlsoc
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5sotlsoc
 
Chapter 11.2
Chapter 11.2Chapter 11.2
Chapter 11.2sotlsoc
 
Chapter 11.0
Chapter 11.0Chapter 11.0
Chapter 11.0sotlsoc
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1sotlsoc
 
Chapter 8.0
Chapter 8.0Chapter 8.0
Chapter 8.0sotlsoc
 
Chapter 10.0
Chapter 10.0Chapter 10.0
Chapter 10.0sotlsoc
 
Chapter 9.4
Chapter 9.4Chapter 9.4
Chapter 9.4sotlsoc
 
Chapter 9.1
Chapter 9.1Chapter 9.1
Chapter 9.1sotlsoc
 
Chapter 9.0
Chapter 9.0Chapter 9.0
Chapter 9.0sotlsoc
 
Chapter 9.2
Chapter 9.2Chapter 9.2
Chapter 9.2sotlsoc
 
Chapter 8.3
Chapter 8.3Chapter 8.3
Chapter 8.3sotlsoc
 
Chapter 8.2
Chapter 8.2Chapter 8.2
Chapter 8.2sotlsoc
 
Chapter 5.2
Chapter 5.2Chapter 5.2
Chapter 5.2sotlsoc
 
Chapter 7.4
Chapter 7.4Chapter 7.4
Chapter 7.4sotlsoc
 

More from sotlsoc (20)

Chapter 2.0 new
Chapter 2.0 newChapter 2.0 new
Chapter 2.0 new
 
Chapter 1.0 new
Chapter 1.0 newChapter 1.0 new
Chapter 1.0 new
 
Chapter 3.0 new
Chapter 3.0 newChapter 3.0 new
Chapter 3.0 new
 
Chapter 6.5 new
Chapter 6.5 newChapter 6.5 new
Chapter 6.5 new
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3
 
Chapter 11.4
Chapter 11.4Chapter 11.4
Chapter 11.4
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
 
Chapter 11.2
Chapter 11.2Chapter 11.2
Chapter 11.2
 
Chapter 11.0
Chapter 11.0Chapter 11.0
Chapter 11.0
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1
 
Chapter 8.0
Chapter 8.0Chapter 8.0
Chapter 8.0
 
Chapter 10.0
Chapter 10.0Chapter 10.0
Chapter 10.0
 
Chapter 9.4
Chapter 9.4Chapter 9.4
Chapter 9.4
 
Chapter 9.1
Chapter 9.1Chapter 9.1
Chapter 9.1
 
Chapter 9.0
Chapter 9.0Chapter 9.0
Chapter 9.0
 
Chapter 9.2
Chapter 9.2Chapter 9.2
Chapter 9.2
 
Chapter 8.3
Chapter 8.3Chapter 8.3
Chapter 8.3
 
Chapter 8.2
Chapter 8.2Chapter 8.2
Chapter 8.2
 
Chapter 5.2
Chapter 5.2Chapter 5.2
Chapter 5.2
 
Chapter 7.4
Chapter 7.4Chapter 7.4
Chapter 7.4
 

Chapter 10.2

  • 1. FILE AND JFILECHOOSER OBJECTS Chapter 10.2:
  • 2. The JFileChooser Class  A javax.swing.JFileChooser object allows the user to select a file.  To start the listing from a specific directory: JFileChooser chooser = new JFileChooser( ); chooser.showOpenDialog(null); JFileChooser chooser = new JFileChooser("D:/JavaPrograms/Ch12"); chooser.showOpenDialog(null);
  • 4. Getting Info from JFileChooser int status = chooser.showOpenDialog(null); if (status == JFileChooser.APPROVE_OPTION) { JOptionPane.showMessageDialog(null, "Open is clicked"); } else { //== JFileChooser.CANCEL_OPTION JOptionPane.showMessageDialog(null, "Cancel is clicked"); } File selectedFile = chooser.getSelectedFile(); File currentDirectory = chooser.getCurrentDirectory();