Results 1 to 2 of 2
Thread: TextField loading
- 07-16-2012, 09:59 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 5
- Rep Power
- 0
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
-
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
-
TextField not displayed
By weezy2894 in forum Java AppletsReplies: 6Last Post: 04-18-2011, 02:37 AM -
Won't set to textfield
By Steffers in forum New To JavaReplies: 7Last Post: 11-04-2010, 02:32 PM -
1 question regarding textfield
By henry in forum New To JavaReplies: 3Last Post: 06-16-2010, 03:56 AM -
TextField Example
By Java Tip in forum SWTReplies: 0Last Post: 07-25-2008, 02:21 PM -
JSP - getting value from a textfield
By Java Tip in forum Java TipReplies: 0Last Post: 12-01-2007, 08:58 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks