|
||||||||||||||
. . . . . |
| Intro |
Begin |
if/else |
Loops |
Arrays |
Graphics |
Animation |
Mouse |
Game |
Real |
Methods |
Class |
Class 2 |
Applet |
MouseClick |
Thread |
Button |
Java Basic Button Action
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class ClickButton extends Applet implements ActionListener{
// declare a textfield and Button
TextField text1;
Button button1;
// initialise the applet
public void init(){
// set the textfield to 30 characters
text1 = new TextField(30);
// add the textfield to the applet
add(text1);
// initialise button and set its label
button1 = new Button(" click me");
// add button to the applet
add(button1);
// set the actionlistener to the button
button1.addActionListener(this);
}
// methods needed for actionlistener Interface
public void actionPerformed(ActionEvent e){
// declare and initialise a string to be shown
String message = " You clicked the button. woo hoo";
// if the source of the action is the button
// ie if the button is clicked
if(e.getSource() == button1){
// set the text of the textfield to our message
text1.setText(message);
}
}
}
Flash Tutorials in Video Format -
Watch them now at LearnFlash.com
And here is the html code to run it, just as a reminder. <html> <body> <applet code="ClickButton.class" width="300" height="300"> </applet> </body> </html> |
|
||||||||||||
|
. | Home | Flash MX | Actionscript 2.0 | Flash 3D | Flash 8 | Flash Database | Flash Mobile | Flash CS3 | Java For Kids | Video Course | General Video | Photoshop | Web Design | Digital Photography | Games | free backgrounds | Resume | Streaming Video | Students Work | Links | Contact me | sitemap | reviews | . . |
||||||||||||||