Welcome to Dream.In.Code
Become a Java Expert!

Join 149,478 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,725 people online right now. Registration is fast and FREE... Join Now!




Bulding a FileChoser in GUI project

 
Reply to this topicStart new topic

Bulding a FileChoser in GUI project, How do you get the stupid thing to work?

Storm8
23 Apr, 2007 - 07:05 AM
Post #1

New D.I.C Head
*

Joined: 9 Apr, 2007
Posts: 11


My Contributions
I have started a project a long time ago and now i am stuck.
i need to get a JFileChooser to find all the files and open them ethier in a showMessageDialog or in a text pane. This is the last thing i have to do but i am stuck please help. Bacicly i have to get this to work or else my friends will kill me. i dont know how to attach multiple files so iam just going to put them in a compressed and attach that. don't any attension to the fisrt page click Send/Recive Message button. the hatchet man is the exit button.
first page

CODE

/*
* GUIExamples.java
*
* Created on March 8, 2007, 9:37 AM
*/

/**
*
* @author  cwilliams
*/
import java.awt.*;
import javax.swing.*;
import java.math.*;

public class Doom extends javax.swing.JFrame {
    int i;
    
    /** Creates new form GUIExamples */
    public Doom() {
        initComponents();
        
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
    private void initComponents() {
        coolGui = new javax.swing.JPanel();
        mail = new javax.swing.JToggleButton();
        exit = new javax.swing.JButton();
        voulumeCalc = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        band = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        song = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        repeat = new javax.swing.JTextField();
        playSong = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(0, 0, 0));
        setCursor(new java.awt.Cursor(java.awt.Cursor.CROSSHAIR_CURSOR));
        setForeground(new java.awt.Color(0, 0, 0));
        setName("FirstFrame");
        coolGui.setBackground(new java.awt.Color(0, 0, 0));
        mail.setText("Recive/Send Mail");
        mail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mailActionPerformed(evt);
            }
        });

        exit.setBackground(new java.awt.Color(0, 0, 0));
        exit.setIcon(new javax.swing.ImageIcon("X:\\Exit Logo.gif"));
        exit.setToolTipText("Exit the Program");
        exit.setBorder(null);
        exit.setBorderPainted(false);
        exit.setContentAreaFilled(false);
        exit.setDebugGraphicsOptions(javax.swing.DebugGraphics.FLASH_OPTION);
        exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitActionPerformed(evt);
            }
        });

        voulumeCalc.setBackground(new java.awt.Color(0, 0, 0));
        voulumeCalc.setForeground(new java.awt.Color(255, 255, 255));
        voulumeCalc.setText("Volume Calculation Of A Pyrimid");
        voulumeCalc.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED, null, new java.awt.Color(153, 153, 153), null, new java.awt.Color(51, 51, 51)));
        voulumeCalc.setContentAreaFilled(false);
        voulumeCalc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                voulumeCalcActionPerformed(evt);
            }
        });

        jLabel1.setText("Name of the band:");

        jLabel2.setText("Name of the song:");

        jLabel3.setText("Number of times you want to play the song:");

        repeat.setText("0");

        playSong.setText("Play Song");
        playSong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                playSongActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jLabel2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(song, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 183, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jLabel1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(band, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 182, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(playSong)
                            .add(jLabel3))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(repeat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 61, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(312, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(band, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(song, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(repeat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(playSong)
                .addContainerGap(146, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout coolGuiLayout = new org.jdesktop.layout.GroupLayout(coolGui);
        coolGui.setLayout(coolGuiLayout);
        coolGuiLayout.setHorizontalGroup(
            coolGuiLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(coolGuiLayout.createSequentialGroup()
                .add(coolGuiLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(coolGuiLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(voulumeCalc))
                    .add(exit, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(coolGuiLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(mail)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        coolGuiLayout.setVerticalGroup(
            coolGuiLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(coolGuiLayout.createSequentialGroup()
                .addContainerGap()
                .add(voulumeCalc)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 71, Short.MAX_VALUE)
                .add(mail)
                .add(44, 44, 44)
                .add(exit))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(coolGui, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, coolGui, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        pack();
    }// </editor-fold>                        

    private void playSongActionPerformed(java.awt.event.ActionEvent evt) {                                        

int r;
int i;
String songName;
String bandName;

bandName = band.getText();
songName = song.getText();
r = Integer.parseInt(repeat.getText());

for(i=1;i<=r;i++)
{
    JOptionPane.showMessageDialog(null,songName+" by "+bandName+" repeated "+i);
}
    }                                        

    private void voulumeCalcActionPerformed(java.awt.event.ActionEvent evt) {                                            
dispose();
        boolean repeat=true;
        String doAgain;
        JOptionPane.showMessageDialog(null,"Welcome Cheater");
do{
repeat=false;
        String ahight = JOptionPane.showInputDialog("Enter the value for the height.");
        String abase = JOptionPane.showInputDialog("Enter the value for the base.");
             double hight = Double.parseDouble(ahight);
             double base = Double.parseDouble(abase);
                    if(hight<1000){
                                          JOptionPane.showMessageDialog(null,"Height is "+hight);
                                         }
                    if(base<1000){
                                          JOptionPane.showMessageDialog(null,"Base is "+base);
                                        }
                    else{
                           JOptionPane.showMessageDialog(null,"Values to great."+'\n'+"please enter again.");
                           }
                               JOptionPane.showMessageDialog(null,"1/3*"+base+"^2*"+hight);
         double aPower=2;
        double aFraction=.3333;
        double pVolume =  (aFraction*base*Math.pow(base,aPower)*hight);
        JOptionPane.showMessageDialog(null,pVolume);  
        JOptionPane.showMessageDialog(null,"Made By: Storm Williams"+
                                                                   '\n'+
                                                                   "Helped By: Entire Advaned Programing Class"+
                                                                   '\n'+
                                                                   "Started  On: January 17, 2007"+
                                                                   '\n'+
                                                                   "Finished On: January 19, 2007"+
                                                                   '\n'+
                                                                  "Made to calcuelatulate the volume of a Pyramid"+
                                                                  '\n'+
                                                                  "Program name: Project.java");
        
        doAgain = JOptionPane.showInputDialog("Would you like to start again or quit?");
        if(doAgain.equals("yes") || doAgain.equals("Yes")){
                    repeat=true;
            }
        else{
                 repeat=false;
                 new Doom().setVisible(true);
              }
    }while(repeat);
    }                                          

    private void mailActionPerformed(java.awt.event.ActionEvent evt) {                                    
    new part2().setVisible(true);
    dispose();
    }                                    

    private void exitActionPerformed(java.awt.event.ActionEvent evt) {                                    
System.exit(0);
    }                                    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Doom().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify                    
    private javax.swing.JTextField band;
    private javax.swing.JPanel coolGui;
    private javax.swing.JButton exit;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JToggleButton mail;
    private javax.swing.JButton playSong;
    private javax.swing.JTextField repeat;
    private javax.swing.JTextField song;
    private javax.swing.JButton voulumeCalc;
    // End of variables declaration                  
    
}


Second page

CODE

/*
* part2.java
*
* Created on March 9, 2007, 9:02 AM
*/
import javax.swing.*;
import java.io.*;

/**
*
* @author  cwilliams
*/
public class part2 extends javax.swing.JFrame {
    /** Creates new form part2 */
    public part2() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
    private void initComponents() {
        messagePane = new javax.swing.JPanel();
        exit2 = new javax.swing.JButton();
        message = new javax.swing.JTextArea();
        send = new javax.swing.JButton();
        getMessage = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(0, 0, 0));
        setCursor(new java.awt.Cursor(java.awt.Cursor.CROSSHAIR_CURSOR));
        setForeground(new java.awt.Color(0, 0, 0));
        messagePane.setBackground(new java.awt.Color(0, 0, 0));
        exit2.setText("Exit");
        exit2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exit2ActionPerformed(evt);
            }
        });

        message.setColumns(20);
        message.setRows(5);
        message.setText("Type your message here. hit enter at the end of this\nframe.");

        send.setText("Send");
        send.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sendActionPerformed(evt);
            }
        });

        getMessage.setText("Recive");
        getMessage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                getMessageActionPerformed(evt);
            }
        });

        jButton1.setText("Find Message");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout messagePaneLayout = new org.jdesktop.layout.GroupLayout(messagePane);
        messagePane.setLayout(messagePaneLayout);
        messagePaneLayout.setHorizontalGroup(
            messagePaneLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, messagePaneLayout.createSequentialGroup()
                .addContainerGap()
                .add(messagePaneLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, message, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE)
                    .add(messagePaneLayout.createSequentialGroup()
                        .add(send)
                        .add(61, 61, 61)
                        .add(jButton1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 48, Short.MAX_VALUE)
                        .add(getMessage)
                        .add(43, 43, 43)
                        .add(exit2)))
                .addContainerGap())
        );
        messagePaneLayout.setVerticalGroup(
            messagePaneLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(messagePaneLayout.createSequentialGroup()
                .addContainerGap()
                .add(messagePaneLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(exit2)
                    .add(send)
                    .add(getMessage)
                    .add(jButton1))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(message, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 171, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, messagePane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(messagePane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );
        pack();
    }// </editor-fold>                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        new recive_mail().setVisible(true);
        dispose();
    }                                        

    private void getMessageActionPerformed(java.awt.event.ActionEvent evt) {                                          
    String fileNam;
    fileNam=JOptionPane.showInputDialog("What is the name of the file you want to load?");
    String fileName="Q:\\Computer Programming\\messages\\"+fileNam+".txt";
        try {
      FileReader fr = new FileReader(fileName);
      BufferedReader br = new BufferedReader(fr);

      String s;
      while((s = br.readLine()) != null)
      JOptionPane.showMessageDialog(null,"Email Message"+'\n'+s);
      fr.close();
    }
    catch(Exception e) {
      System.out.println("Exception: " + e);
    }
    }                                          

    private void sendActionPerformed(java.awt.event.ActionEvent evt) {                                    
    String fileNam;
    fileNam=JOptionPane.showInputDialog("Who Do You Want To Send This To and What it is about?");
    String fileName="x:\\"+fileNam+".txt\\";
        try
    {  
      String contents=message.getText();
      FileWriter writer = new FileWriter( fileName, true );
      writer.write(contents);
      writer.close();
    }
        catch ( IOException io )
    {
      JOptionPane.showMessageDialog(null,"Sorry, Problem sending " + fileNam+" to "+fileName);
    }
    }                                    

    private void exit2ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        new Doom().setVisible(true);
        dispose();
    }                                    
       public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Doom().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                    
    private javax.swing.JButton exit2;
    private javax.swing.JButton getMessage;
    private javax.swing.JButton jButton1;
    private javax.swing.JTextArea message;
    private javax.swing.JPanel messagePane;
    private javax.swing.JButton send;
    // End of variables declaration                  
    
}


Page i need help with

CODE

// recive_mail.java
//Created on March 20, 2007, 9:30 AM
//@author  cwilliams
import javax.swing.*;
import java.io.*;

public class recive_mail extends javax.swing.JFrame {
    public recive_mail() {
        initComponents();
    }
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
        jFileChooser1 = new javax.swing.JFileChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jFileChooser1.setApproveButtonText("Open");
        jFileChooser1.setApproveButtonToolTipText("Opens File Selected");
        jFileChooser1.setBackground(new java.awt.Color(0, 0, 0));
        jFileChooser1.setCurrentDirectory(new java.io.File("Q:\\Computer Programming\\messages"));
        jFileChooser1.setForeground(new java.awt.Color(255, 255, 255));
        jFileChooser1.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 10, 10, 10));
        jFileChooser1.setName("Message Finder");
        jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFileChooser1ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jFileChooser1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jFileChooser1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );
        pack();
    }// </editor-fold>

    private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {

    }
        
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new recive_mail().setVisible(true);
                }
            });
        }
        
    // Variables declaration - do not modify
    private javax.swing.JFileChooser jFileChooser1;
    // End of variables declaration
        
    }


sory i can't do it as an attachment i'll try tommrow.

This post has been edited by Storm8: 23 Apr, 2007 - 07:17 AM
User is offlineProfile CardPM
+Quote Post

Ellie
RE: Bulding A FileChoser In GUI Project
24 Apr, 2007 - 01:51 AM
Post #2

D.I.C Regular
Group Icon

Joined: 17 Jan, 2007
Posts: 427



Thanked: 4 times
Dream Kudos: 150
My Contributions
Hi,

I had to comment out the desktop bit because I don't have those packages, but here it is working:

CODE
//@author  cwilliams
import javax.swing.*;
import java.io.*;
import java.awt.*; //note you need this package too

public class recive_mail extends javax.swing.JFrame {
    public recive_mail() {
        initComponents();
        
    }
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
        jFileChooser1 = new javax.swing.JFileChooser();
        Container contentPane = getContentPane(); //this is new!
        contentPane.add(jFileChooser1);
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jFileChooser1.setApproveButtonText("Open");
        jFileChooser1.setApproveButtonToolTipText("Opens File Selected");
        jFileChooser1.setBackground(new java.awt.Color(0, 0, 0));
        jFileChooser1.setCurrentDirectory(new java.io.File("Q:\\Computer Programming\\messages"));
        jFileChooser1.setForeground(new java.awt.Color(255, 255, 255));
        jFileChooser1.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 10, 10, 10));
        jFileChooser1.setName("Message Finder");
        jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFileChooser1ActionPerformed(evt);
            }
        });

     //   org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
//        getContentPane().setLayout(layout);
//        layout.setHorizontalGroup(
//            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
//            .add(jFileChooser1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
//        );
//        layout.setVerticalGroup(
//            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
//            .add(jFileChooser1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
//        );
        pack();
    }// </editor-fold>

    private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {

    }
        
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                   JFrame tester = new recive_mail();
                    tester.setVisible(true);
                  
                }
            });
        }
        
    // Variables declaration - do not modify
    private javax.swing.JFileChooser jFileChooser1;
    // End of variables declaration
        
    }

icon_up.gif Basically I think the problem was that you didn't use the container to add the fileChooser to, and then in your main method, you need to create a JFrame using your recive_mail class. I'm not that up on these things, so I can't really explain more than that, sorry!
User is offlineProfile CardPM
+Quote Post

Storm8
RE: Bulding A FileChoser In GUI Project
24 Apr, 2007 - 06:42 AM
Post #3

New D.I.C Head
*

Joined: 9 Apr, 2007
Posts: 11


My Contributions
the code works but when you go in and select the file it wont open the file and i have never worked with this swing. online the tutorals don't help at all.

CODE

private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt)
{            
                                  
//this is where they tell me to put the code but i can't call the
//open button or the cancel button variables.

}



User is offlineProfile CardPM
+Quote Post

Ellie
RE: Bulding A FileChoser In GUI Project
24 Apr, 2007 - 07:57 AM
Post #4

D.I.C Regular
Group Icon

Joined: 17 Jan, 2007
Posts: 427



Thanked: 4 times
Dream Kudos: 150
My Contributions

I'm afraid that bit involves the Desktop packages which I don't have. Hopefully someone else can help you with it though, sorry!
User is offlineProfile CardPM
+Quote Post

Storm8
RE: Bulding A FileChoser In GUI Project
25 Apr, 2007 - 06:17 AM
Post #5

New D.I.C Head
*

Joined: 9 Apr, 2007
Posts: 11


My Contributions
okay thanks tell everyone you can to see if they can give some help.
User is offlineProfile CardPM
+Quote Post

Storm8
RE: Bulding A FileChoser In GUI Project
26 Apr, 2007 - 06:31 AM
Post #6

New D.I.C Head
*

Joined: 9 Apr, 2007
Posts: 11


My Contributions
Hey every one i am done it was easier then what i was making it.
User is offlineProfile CardPM
+Quote Post

Storm8
RE: Bulding A FileChoser In GUI Project
26 Apr, 2007 - 06:44 AM
Post #7

New D.I.C Head
*

Joined: 9 Apr, 2007
Posts: 11


My Contributions
Oh yeah im stunin cool.gif pimp.gif wink2.gif w00t.gif i pity the fool who ever doubt me mrt.gif i would like to thank Ellie for helping me out. and everyone else that just looked and said nothing thans for looking
User is offlineProfile CardPM
+Quote Post

Ellie
RE: Bulding A FileChoser In GUI Project
26 Apr, 2007 - 02:21 PM
Post #8

D.I.C Regular
Group Icon

Joined: 17 Jan, 2007
Posts: 427



Thanked: 4 times
Dream Kudos: 150
My Contributions
Glad you got it sorted, I'd like to see your code if that's cool. I am intrigued now

This post has been edited by Ellie: 26 Apr, 2007 - 02:24 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 03:20PM