Using ActionListener in Jabaco
Hi to all!
Can someone explain me how to implement ActionListener class in Jabaco?
I have little success with this code, but results are non excepted.
Thanks
Can someone explain me how to implement ActionListener class in Jabaco?
I have little success with this code, but results are non excepted.
Thanks
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 |
Function Test () As ActionListener MsgBox "proba" End Function Public Sub Command1_Click() Dim jbut As JButton=New JButton jbut.addActionListener (Test) Me.add (jbut) jbut.setBounds (10,10,30,30) End Sub |
Ok, with little thinking i got answer.
First create new class file like Class1 and add code...
Then create java component and add ActionListener...
But, new question is:
is there any other solution to create event classes for java components (simple way)?
Thanks
Milan
First create new class file like Class1 and add code...
|
|
Source code |
1 2 3 4 |
Implements ActionListener Public Sub actionPerformed(arg2 As ActionEvent) MsgBox "dd" End Sub |
Then create java component and add ActionListener...
|
|
Source code |
1 2 3 4 5 6 7 |
Public Sub Command1_Click()
Dim jb As JButton=New JButton ("test")
Dim test As New Class1
jb.addActionListener (test)
Me.add jb
jb.setBounds 10,10,60,20
End Sub
|
But, new question is:
is there any other solution to create event classes for java components (simple way)?
Thanks
Milan
Quoted
is there any other solution to create event classes for java components (simple way)?
I am not sure if i was understanding you quite well enough to give an adequate answer.
Could you please try to explain more clearly what you want to do?
Do you want to add controls during run time?
Until now, there is no Load-function for Control-arrays that's true.
OlimilO
Quoted
or i must add every time new class file
Ah ... no, you do not have to add a class file. Just implement the Listener-Interface in your Form-Class.
You must do this only for events that are not implemented in the Jabaco-Framework already.
For Button-Click just simply click on the button in the Form-designer then Jabaco creates the Click-event-procedure autoamtically. Just the way like VB does it.
Ok, i found solution
Code for Form
Thanks to OlimilO for directions
Milan
Code for Form
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 |
Implements java#awt#Event#ActionListener
Public Sub Command1_Click()
Dim jb As JButton=New JButton ("Test")
jb.addActionListener Cast(Form1,java#awt#Event#ActionListener)
Me.add jb
jb.setBounds 10,10,60,20
End Sub
Public Sub actionPerformed(arg2 As ActionEvent)
MsgBox "test"
End Sub
|
Thanks to OlimilO for directions
Milan
Hi birosys,
yes you got it!
one tipp:
if you add Code to your post in the Forum use this button: <JBC>
then your code will be colored like in the Jabaco-IDE
second:
you do not have to Cast by adding the Form (Me) as ActionListener to the Button
third: Great I have learned about ActionListener I never used it before
I used MouseListener and KeyListener instead, maybe have a look into my little Lassie-Projekt
OlimilO
yes you got it!
one tipp:
if you add Code to your post in the Forum use this button: <JBC>
then your code will be colored like in the Jabaco-IDE
second:
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Option Explicit Import java#awt#Event Implements java#awt#Event#ActionListener Public Sub Form_Load() Dim jb As JButton = New JButton("Test") Me.add(jb) jb.addActionListener(Me) jb.setBounds 10,10,60,20 End Sub Public Sub actionPerformed(arg2 As ActionEvent) ' 2 examples how to use arg2 As ActionEvent MsgBox arg2.getActionCommand Dim jb As JButton = Cast(arg2.getSource, JButton) jb.setForeground(RgbToColor(&HFF)) End Sub |
you do not have to Cast by adding the Form (Me) as ActionListener to the Button
third: Great I have learned about ActionListener I never used it before
I used MouseListener and KeyListener instead, maybe have a look into my little Lassie-Projekt
OlimilO
Similar threads
-
General topics, questions and discussions »-
A little JabacoJava
(Jul 24th 2009, 9:13pm)
-
Votings »-
Programming language
(Aug 21st 2008, 9:06pm)
-
History & News »-
RELEASE: Jabaco 1.4.0 BETA - 2008-11-18
(Nov 21st 2008, 8:52pm)
-
Tips, Tricks, Samples & Tutorials »-
Invoke Methods
(Aug 22nd 2008, 1:04am)
-
Tips, Tricks, Samples & Tutorials »-
Threads and Synchronisation
(Aug 21st 2008, 10:41pm)
