Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Introduction to Java Interface Event-Handling : Page 2

Java is an event-driven language. This means that program flow usually varies dependent upon what actions a user performs, and differs from traditional procedural-based languages where program execution was very linear. Here's what you need to know to make your Java programs respond to events such as the user moving the mouse or clicking a button.


advertisement
Listing 1 contains the code for a simple Java applet that displays a button. When a user clicks the button the code changes the background color of the button in a round-robin fashion based on a index into the private strColors[] array. Because it's an applet, you cannot run it directly as a Windows application—it must be embedded into an HTML page. Listing 2 gives the HTML tags for such a page.

Figure 1 and Figure 2 show the sample applet in action.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Thanks for your registration, follow us on our social networks to keep up-to-date