Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nownot

macrumors regular
Original poster
ok heres my code what ive been trying to do is make it where when a textbox is click or tabbed to the text inside will be highlighted and editable. like selectall but i cant work it out, any ideas or help, thanks.

// A program to demonstrate the use of JTextFields's

//Import Statements
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.applet.*;
import java.util.Random;
import javax.swing.event.*;
import java.util.Vector;



public class done extends JFrame {
run now = new run();
JTextField field1, field2, field3, field4, field5, field6;
String disp;
JButton pick = new JButton("pick for me");
ButtonPick buttonpick = new ButtonPick();

public done()
{

super("TextField Test Demo");
Container container = getContentPane();
container.setLayout(new GridLayout(10,1));
field1 = new JTextField("Put Choice Here", 15);field2 = new JTextField("Put Choice Here", 15);
field3 = new JTextField("Put Choice Here", 15);field4 = new JTextField("Put Choice Here", 15);
field5 = new JTextField("Put Choice Here", 15);field6 = new JTextField("This is what your doing today", 15);
container.add(field1);container.add(field2);container.add(field3);container.add(field4);container.add(field5);
container.add(pick);
container.add(field6);

pick.addActionListener(buttonpick);
setSize(325, 500);
setVisible(true);

}

private class ButtonPick implements ActionListener{
public void actionPerformed(ActionEvent e){
now.again(field1.getText(),field2.getText(),field3.getText(),field4.getText(),field5.getText());
field6.setText(now.back("String six"));
}
}
public static void main(String args[])
{
done test = new done();
run now = new run();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}



import java.io.*;
import java.util.Random;

public class run {
String[] now = new String[10];
int i = 0;
String here;

public void again(String one, String second, String three, String four, String five){
Random r = new Random();
now[0]=one;now[1]=second;now[2]=three;now[3]=four;now[4]=five;
int z = r.nextInt(5);

if(now[z].equals("Put Choice Here")){
here="you didnt put anything here pls choose again";
}
if(!now[z].equals("Put Choice Here")){
here=now[z];
}


}

public String back(String back){
back = here;
return back;

}


}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.