Results 1 to 3 of 3
  1. #1
    gazale_m's Avatar
    gazale_m is offline Member
    Join Date
    Dec 2008
    Posts
    6
    Rep Power
    0

    Default console and JTesxtField

    I wrote a Program which as an inputtake the file path in the Console and open it.
    Java Code:
    	public void readTheFile()throws IOException{	
     
    	Start frame = new Start();// next step "open the start() class"
            InputStreamReader inStream = new InputStreamReader(System.in);
    	BufferedReader stdin = new BufferedReader(inStream);
    	String fileName;
    	System.out.println("Please give your path");
    	fileName = stdin.readLine();
            File file = new File(fileName);
    now I have tried to take the input from a window with (Swing, apt oder Gui) :

    Java Code:
    public class Start extends JFrame implements ActionListener{
    	public Start() {
                JFrame.setDefaultLookAndFeelDecorated(true);
    	    JFrame frame = new JFrame();
    	    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	    frame.setTitle("Input Window ");
    	    frame.setLayout(new GridLayout(3, 2));
    	    frame.add(new JLabel("Please give your path:"));
    	    final JTextField textfield = new JTextField(16);
    	    textfield.addActionListener(this);
    	    frame.add(textfield);
    	   JButton button1 = new JButton("GO!");
    	    frame.add(button1);
    	    button1.addActionListener(new ActionListener() {
    	    public void actionPerformed(ActionEvent e) {
    	   					String text = textfield.getText();
    	   					}
    	    });
    but it doesn't funtion !! what am I doing Wrong??:confused:

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  3. #3
    gazale_m's Avatar
    gazale_m is offline Member
    Join Date
    Dec 2008
    Posts
    6
    Rep Power
    0

    Default No error messages!

    I don't get any error messages! I just get a Box and a button with a cursor in it .
    I want it to get the input string after I press the button (String text =textfield.getText() ) !! just like the console input!
    Last edited by gazale_m; 12-10-2008 at 09:42 AM.

Similar Threads

  1. How to get input from Console
    By karma in forum New To Java
    Replies: 8
    Last Post: 08-13-2010, 10:32 PM
  2. how to take input from console in jsp
    By veena in forum New To Java
    Replies: 1
    Last Post: 05-06-2008, 05:39 AM
  3. Console Progress Bar
    By new_2_java in forum New To Java
    Replies: 1
    Last Post: 02-16-2008, 03:18 AM
  4. Console doesn't appear!
    By PeteMarsh in forum New To Java
    Replies: 2
    Last Post: 12-17-2007, 06:41 PM

Posting Permissions

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