Results 1 to 2 of 2
  1. #1
    xalebo is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Default TextField loading

    Hello everyone :)

    So I have this program :

    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Scanner;
    import javax.swing.*;

    public class StrikerFrame extends Frame implements ActionListener{

    Button btnGo, btnBack;
    List lstStrikers;
    Label lblName;
    TextField txtPlayer;

    public StrikerFrame(){

    setLayout(null);

    btnBack = new Button ("BACK <");
    btnBack.addActionListener(this);
    btnGo = new Button("GO >");
    btnGo.addActionListener(this);
    lstStrikers = new List(19);
    lstStrikers.addActionListener(this);
    lblName = new Label("NOW CHOOSE YOUR FAVOURITE STRIKER:::");
    txtPlayer = new TextField();
    txtPlayer.setEditable(false);

    try{

    FileReader fr = new FileReader("Strikers.txt");
    Scanner s = new Scanner(fr);

    while(s.hasNext()){
    String line = s.nextLine();
    lstStrikers.add(line);
    }
    s.close();
    }catch(Exception e){
    System.out.println("FAILED");
    }

    lstStrikers.setBounds(100,100,600,325);
    btnBack.setBounds(500,525,100,50);
    btnGo.setBounds(200,525,100,50);
    lblName.setBounds(100,50,700,50);
    txtPlayer.setBounds(100,450,700,50);

    try{
    FileReader fread = new FileReader("Strikers.txt");
    Scanner scan = new Scanner(fread);

    char z = lstStrikers.getSelectedIndex();
    String sLine = scan.readLine(z);
    txtPlayer.add(sLine);

    scan.close();
    }catch(Exception e){
    System.out.println("FAILED");
    }



    add(lstStrikers);
    add(btnBack);
    add(btnGo);
    add(lblName);
    add(txtPlayer);

    }

    public void actionPerformed(ActionEvent ae){
    if(ae.getSource()==btnBack){
    setVisible(false);
    }else if(ae.getSource()==btnGo){
    System.exit(0);
    }
    }

    }


    And the thing I don't know is where i have the Bold text.
    The program will show a list of Players and the person will choose the player by clicking on him from the list.
    Therefore I want that the player chosen will be shown in a Textfield underneath the list and show the user which player he chose.
    I don't know exactly what to do :S
    (I use java awt :P)

    Thanks very much for this useful forum :)
    Drew

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: TextField loading

    Don't use AWT but rather use Swing as it's more powerful and flexible. Google the Swing layout manager tutorials which will show you how to place your components where you want them to be, and then the JList or JComboBox tutorials which will show you how to display a selectable list. To set the text of a JTextField, simply call setText(yourStringHere) on it.

Similar Threads

  1. TextField not displayed
    By weezy2894 in forum Java Applets
    Replies: 6
    Last Post: 04-18-2011, 03:37 AM
  2. Won't set to textfield
    By Steffers in forum New To Java
    Replies: 7
    Last Post: 11-04-2010, 03:32 PM
  3. 1 question regarding textfield
    By henry in forum New To Java
    Replies: 3
    Last Post: 06-16-2010, 04:56 AM
  4. TextField Example
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 03:21 PM
  5. JSP - getting value from a textfield
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-01-2007, 09:58 PM

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
  •