First of all yes I know I have not used a layout manager in order to create my buttons and I am not using swing, as I am only a beginner so I did it a different way. However, I basically created 6 buttons, the first button (b1)allows the user to add their inputted word into a stored list which cannot be seen, but now I want to display that inputted word on the java applet screen when they press the second button (b2).
public class Ex2 extends Applet implements ActionListener {
List<String> wordList = new ArrayList <String>();
Font fonttext;
TextField textf;
String x;
Button b1;
Button b2;
Button b3;
Button b4;
Button b5;
Button b6;
public void init(){
setBackground(Color.lightGray);
fonttext = new Font("Times New Roman", Font.BOLD, 24);
textf = new TextField("", 40);
add(textf);
b1 = new Button ("Add word to list");
b2 = new Button ("Display words from list");
b3 = new Button ("Search list for this word(show occurence)");
b4 = new Button ("Remove first occurence of this word");
b5 = new Button ("Remove all occurence of this word");
b6 = new Button ("Clear the list ");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
}
public void paint(Graphics g){
this.b1.setLocation(20,600);
this.b2.setLocation(150,600);
this.b3.setLocation(400,600);
this.b4.setLocation(680,600);
this.b5.setLocation(930,600);
this.b6.setLocation(1170,600);
}
public void actionPerformed(ActionEvent e){
if (e.getSource() == b1 ){
x = textf.getText();
wordList.add(x);
textf.setText(null);
}
if (e.getSource() == b2 ){
}}}