CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2009
    Location
    USA
    Posts
    49

    Talking GUI Help Java Program

    I don't know what to use, a JFileChooser, or a JTextArea?



    It's suppose to read in a social security (sample) file, if it contains anything other than the 9 digits, it will show the exception. Line by line is read into a GUI via a text file.

    I only got it to work to open an empty GUI with the appropriate heading.

    Code:
    import javax.swing.*;
    import java.awt.*;
    import java.io.*;
    
    public class GUI extends JPanel implements ActionListener{
    	protected JTextField textField;
    	protected JTextArea textArea;
    	private final static String newline = "\n";
    
    	JFrame myFrame;
    
    	//Need to display an error message for the line of error in txt 
    	//file in a text box.
    	//JFileChooser fc = new JFileChooser();
    
    	textField = new JTextField(20);
    	textField.addActionListener(this);
    	textArea = new JTextArea(10, 20);
    	textArea.setEditable(false);
    	JScrollPane scrollPane = new JScrollPane(textArea);
    	
    
    	//Main
    	public static void main(String[]args){
    		GUI gui = new GUI();
    	}
    
    	GUI(){
    		myFrame = new JFrame();
    		myFrame.setSize(500,500);
    		myFrame.setLocation(250,250);
    		myFrame.setTitle("Social Security Numbers");
    		myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		myFrame.setVisible(true);
    	}
    }

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: GUI Help Java Program

    Quote Originally Posted by coder752 View Post
    I don't know what to use, a JFileChooser, or a JTextArea?
    From the Javadocs: "A JFileChooser provides a simple mechanism for the user to choose a file". It gives a view of the file system and allows you to make a file or directory selection.

    Is that what you want to do?

    "A JTextArea is a multi-line area that displays plain text" and allows editing of that text.

    Is that what you want to do?

    They are quite different functions, you must have some idea what you want to do...? If not, you need to go back to the drawing board and decide what it is you are trying to achieve and what you need to do it.

    If you cannot describe what you are doing as a process, you don't know what you're doing...
    W. E. Deming
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured