Click here to Skip to main content
15,908,166 members
Home / Discussions / Java
   

Java

 
QuestionDelimiters Pin
Member 107286679-Aug-15 10:58
Member 107286679-Aug-15 10:58 
AnswerRe: Delimiters Pin
Richard MacCutchan10-Aug-15 0:56
mveRichard MacCutchan10-Aug-15 0:56 
QuestionJava Bubble Sort Pin
Frankie12457-Aug-15 5:00
Frankie12457-Aug-15 5:00 
QuestionRe: Java Bubble Sort Pin
Richard MacCutchan7-Aug-15 6:21
mveRichard MacCutchan7-Aug-15 6:21 
AnswerRe: Java Bubble Sort Pin
Frankie12457-Aug-15 6:37
Frankie12457-Aug-15 6:37 
GeneralRe: Java Bubble Sort Pin
Richard MacCutchan7-Aug-15 21:09
mveRichard MacCutchan7-Aug-15 21:09 
GeneralRe: Java Bubble Sort Pin
Frankie12459-Aug-15 9:33
Frankie12459-Aug-15 9:33 
GeneralRe: Java Bubble Sort Pin
Richard MacCutchan10-Aug-15 0:54
mveRichard MacCutchan10-Aug-15 0:54 
GeneralRe: Java Bubble Sort Pin
Frankie124510-Aug-15 3:22
Frankie124510-Aug-15 3:22 
GeneralRe: Java Bubble Sort Pin
Richard MacCutchan10-Aug-15 3:34
mveRichard MacCutchan10-Aug-15 3:34 
Questioncennect unicenta with a phone problem Pin
Member 116403425-Aug-15 4:56
Member 116403425-Aug-15 4:56 
AnswerRe: cennect unicenta with a phone Pin
Richard MacCutchan5-Aug-15 5:23
mveRichard MacCutchan5-Aug-15 5:23 
QuestionJava Application Help - Inner Class? Pin
Member 1072866731-Jul-15 21:43
Member 1072866731-Jul-15 21:43 
AnswerRe: Java Application Help - Inner Class? Pin
Afzaal Ahmad Zeeshan2-Aug-15 1:55
professionalAfzaal Ahmad Zeeshan2-Aug-15 1:55 
QuestionJAVA SERVLETS and PHP Pin
anaQata31-Jul-15 5:10
professionalanaQata31-Jul-15 5:10 
AnswerRe: JAVA SERVLETS and PHP Pin
Richard MacCutchan1-Aug-15 22:10
mveRichard MacCutchan1-Aug-15 22:10 
GeneralRe: JAVA SERVLETS and PHP Pin
anaQata1-Aug-15 23:21
professionalanaQata1-Aug-15 23:21 
GeneralRe: JAVA SERVLETS and PHP Pin
Richard MacCutchan2-Aug-15 1:12
mveRichard MacCutchan2-Aug-15 1:12 
AnswerRe: JAVA SERVLETS and PHP Pin
Member 119648056-Sep-15 22:58
Member 119648056-Sep-15 22:58 
QuestionJava Pin
jubayer30-Jul-15 0:29
jubayer30-Jul-15 0:29 
AnswerRe: Java Pin
Pete O'Hanlon30-Jul-15 0:45
mvePete O'Hanlon30-Jul-15 0:45 
QuestionJava Set Game Pin
Member 1186286325-Jul-15 6:58
Member 1186286325-Jul-15 6:58 
AnswerRe: Java Set Game Pin
Richard MacCutchan25-Jul-15 8:17
mveRichard MacCutchan25-Jul-15 8:17 
QuestionJava Applet Help Pin
Member 1072866723-Jul-15 0:38
Member 1072866723-Jul-15 0:38 
I am having trouble in only the last line of code. (I think!) The first label prompts the user for their name. If they click the button, then it will change the second label to read "Hello, (username)!" Can anyone give me some pointers?
Java
import java.applet.Applet;
import java.awt.Button;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class Greeting extends Applet implements ActionListener {

    JLabel labelName = new JLabel("Please enter your name.");
    JTextField textField = new JTextField(20);
    Button button = new Button("GREET");
    JLabel labelResult = new JLabel("Result goes here.");

    String userResult = "";

    public void init() {
        setSize(500, 500);
        setBackground(Color.yellow);
        add(labelName);
        add(textField);
        add(button);
        add(labelResult);

        button.addActionListener(this);
    }

    public String getText() {
        return userResult;
    }

    public void setName(String result){
        userResult = result;
    }

    public void actionPerformed(ActionEvent event) {
        if (event.getSource() == button) {
            labelResult.setText("Hello, " + userResult);
        }

    }
}

AnswerRe: Java Applet Help Pin
Richard MacCutchan23-Jul-15 21:12
mveRichard MacCutchan23-Jul-15 21:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.