I am using netbeans 6.8 and the program is running in a applet.
Hi,would you know the answer to this simple question.When a user is prompted from the text area to input their name in the textfield what would make the program display the next paragraph of text in the text area following the user input.If you run the program currently the program does not wait for the user input to display the text paragraphs in the text area it shows them all.
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package paratrooper1;
//class libraries
import java.applet.Applet;
import java.awt.event.*;
import javax.swing.JScrollPane;
import java.awt.*;
import javax.swing.JProgressBar;
/**
*
* @author Paul
*/
public class Paratrooper1 extends Applet implements ActionListener{
//variables
String name;
String answer1getnumber;
String block2;
JProgressBar progresshealth;
TextField userinput;
TextArea mytextarea;
JScrollPane myscrollpane;
Button Enterbutton;
public void init() {
setLayout(null);
setBackground(Color.BLUE);
userinput = new TextField("");
userinput.setBounds(110,550,180,20);
add(userinput);
Enterbutton = new Button("Enter");
Enterbutton.setBounds(290,550,60,20);
add(Enterbutton);
mytextarea = new TextArea("",80, 50,1);
mytextarea.setBounds(60,400,350,140);
mytextarea.setEditable(false);
mytextarea.setFont(new Font("Serif", Font.BOLD, 14));
// mytextarea.setLineWrap(true);
// mytextarea.setWrapStyleWord(true);
// mytextarea.add(myscrollpane);
JScrollPane myscrollpane = new JScrollPane(mytextarea);
add(myscrollpane);
add(mytextarea);
progresshealth = new JProgressBar(500,500);
progresshealth.setValue(0);
progresshealth.setMinimum(0);
progresshealth.setMaximum(100);
//progresshealth.setStringPainted(true);
add(progresshealth);
progresshealth.setVisible(true);
//I would like to add text paragraph by paragraph but settext does not allow for this???nor insert
//append..ie.mytextarea.append("string");
//Start game
//I WOULD LIKE TO DISPLAY THIS FIRST AND WAIT FOR USER TO INPUT THERE NAME
//CURRENTLY BLOCK 1 AND 2 ARE SHOWING AS WELL
mytextarea.setText(" Paratrooper \n\nPlease enter your name");
// if false wait;
// if true continue;
//next block of code to run after enter name
//SHOW AFTER NAME INPUT
//block1
mytextarea.append("\nPlease enter the following for your personalised adventure\nEnter a number below 20");
//SHOW AFTER ENTER NUMBER.ETC.ETC.
// block2
mytextarea.append("\nNext block of code to run\nNext block of code to run\nask question");
//mytextarea.setCaretPosition(mytextarea.getDocument().getLength());
setSize(600,600);
Enterbutton.addActionListener(this);
// TODO start asynchronous download of heavy resources
}
/**
* Initialization method that will be called after the applet is loaded
* into the browser.
*/
public void actionPerformed(ActionEvent evt) {
if(evt.getSource()== Enterbutton){
// if (mytextarea.getText() == name)
mytextarea.setText(mytextarea.getText()+"\n\nWelcome to Paratrooper "+userinput.getText());
//
name=userinput.getText();
userinput.setText("");
}
else {
if(userinput.getText() == answer1getnumber)
answer1getnumber=userinput.getText();
userinput.setText("");
}
// else etc.etc
// TODO overwrite start(), stop() and destroy() methods
}
}