Home www.python.org
Download Documentation
Home
Overview
License
Jython 2.0
Jython 2.1
Installing
JVM Compatibility
 
Applets
Demos
ButtonDemo
CheckboxDemo
ChoiceDemo
LabelDemo
ListDemo
CoordinatesDemo
ConvertDemo
 
Applet Problems
Here's what to do
Other applet issues
 
Email Us
jython-dev@lists.sourceforge.net
 
 
SourceForge Logo
  

Using Buttons

This example shows how to use Buttons from Jython. Three buttons should be displayed in the applet below.

Something has gone wrong loading this applet.

The complete source code for this example is included below.


from java import awt, applet class ButtonDemo(applet.Applet): def init(self): self.b1 = awt.Button('Disable middle button', actionPerformed=self.disable) self.b2 = awt.Button('Middle button') self.b3 = awt.Button('Enable middle button', enabled=0, actionPerformed=self.enable) self.add(self.b1) self.add(self.b2) self.add(self.b3) def enable(self, event): self.b1.enabled = self.b2.enabled = 1 self.b3.enabled = 0 def disable(self, event): self.b1.enabled = self.b2.enabled = 0 self.b3.enabled = 1
The init method creates three buttons with the appropriate labels. It also specifies the actions to be performed when the first and third buttons are clicked. These actions are specified using event properties. Finally, this method adds these three buttons to the applet (which is using the default FlowLayout).

The enable and disable methods change the states of the buttons as appropriate. Notice that this is done using the enabled property of the Buttons.