Purchase Solution

Java Programming ActionEvents

Not what you're looking for?

Ask Custom Question

I have a question about something that has puzzled me. I did this
on my program because it was how I saw it done. I was wondering if
someone could explain why it is done this way and if I would do this for
all ActionEvents.

I used the following code. What does the ".getSource()" do? Is that
what registers when someone clicks the button? How would this format
change if I was adding data entered into a text field? Any help is much
appreciated!! :)

********

public void actionPerformed(ActionEvent e)
{
if (e.getSource() == b)
{
b.setText("Clicked");
click++;
if (click == 1)
b.setText("I've been clicked!");
else
b.setText("I've been clicked " + click + " times!");
}
}

********

Purchase this Solution

Solution Summary

The expert examines Java programming for ActionEvents.

Solution Preview

e.getResource() method is to capture the resource which invokes actionPerformed method.
We can consider the following situation to understand why e.getResource method is useful.
Suppose I have 4 buttons, the actions of each button when pressed are ...

Purchase this Solution


Free BrainMass Quizzes
Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Javscript Basics

Quiz on basics of javascript programming language.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Basic Networking Questions

This quiz consists of some basic networking questions.