Java JFrame ChooserDemo(JFrame jf, Component comp)

Here you can find the source of ChooserDemo(JFrame jf, Component comp)

Description

Chooser Demo

License

Open Source License

Declaration

public static void ChooserDemo(JFrame jf, Component comp) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Component;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class Main {
    public static void ChooserDemo(JFrame jf, Component comp) {
        JMenuItem itemOpen, itemSave, itemDir, itemColor;
        JMenuBar mnuBar = new JMenuBar();
        jf.setJMenuBar(mnuBar);//ww w  . jav  a 2 s  . co  m
        JMenu mnu = new JMenu("File");
        mnuBar.add(mnu);

        itemOpen = new JMenuItem("Buka File");
        mnu.add(itemOpen);
        // Menangani aksi buka file.
        itemOpen.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                JFileChooser chooser = new JFileChooser();
                // File chooser untuk membuka file
                //int opt = chooser.showOpenDialog(ChooserDemo.this);
                // Periksa apakah jadi atau batal
                //if (opt == JFileChooser.APPROVE_OPTION) {
                //  File sf = chooser.getSelectedFile();
                //  area.append("Buka File: " + sf.getName() + CRLF);
                //} else {
                //  area.append("Batal Buka File: " + CRLF);
                //}
            }
        });

        itemSave = new JMenuItem("Simpan File");
        mnu.add(itemSave);
        // Menangani aksi penyimpanan.
        itemSave.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JFileChooser chooser = new JFileChooser();
                // File chooser untuk penyimpanan file
                //int opt = chooser.showSaveDialog(ChooserDemo.this);
                //if (opt == JFileChooser.APPROVE_OPTION) {
                //  area.append("Simpan File: " +
                //  ((chooser.getSelectedFile() != null) ?
                //  chooser.getSelectedFile().getName() :
                //  "nothing") + CRLF);
                //}
            }
        });

        itemDir = new JMenuItem("Buka Direktori");
        mnu.add(itemDir);
        itemDir.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                //JFileChooser chooser = new JFileChooser();
                // Mode seleksi: hanya direktori
                //chooser.setFileSelectionMode(
                //  JFileChooser.DIRECTORIES_ONLY);
                //int opt = chooser.showOpenDialog(ChooserDemo.this);
                //if (opt == JFileChooser.APPROVE_OPTION) {
                //  area.append("Buka Direktori: " +
                //  ((chooser.getSelectedFile() != null)?
                //  chooser.getSelectedFile().getName() :
                //  "nothing") + CRLF);
                //}
            }
        });

        mnu.addSeparator();
        itemColor = new JMenuItem("Color Chooser");
        mnu.add(itemColor);
        // Menangani aksi seleksi warna
        itemColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // Menampilkan dialog warna
                //Color c = JColorChooser.showDialog(ChooserDemo.this,
                //  "Pilih warna", area.getBackground());
                // Menetapkan warna text area
                //if (c != null) area.setBackground(c);
            }
        });

        //area = new JTextArea(5, 20);
        //add(new JScrollPane(area), "Center");

        //   setDefaultCloseOperation(EXIT_ON_CLOSE);
        //   setSize(400, 250);
        //   setVisible(true);
    }
}

Related

  1. centre(JFrame frame)
  2. centreJustifyFrame(final JFrame frame, final int y_position)
  3. centreWindow(Window c, JFrame frame)
  4. changeLookAndFeel(final String lookName, final JFrame frame)
  5. chooseFile(String directoryPath, String dialogTitle, String selectedFileName, boolean saveDialog, String[] extensions, JFrame parentFrame)
  6. closeFrame(JFrame frame, JProgressBar progressBar)
  7. closeOnEsc(JFrame frame)
  8. closeOnEscape(final JFrame frame)
  9. closeOnEscape(final JFrame frame)