You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

birosys

Trainee

  • "birosys" is male
  • "birosys" started this thread

Posts: 48

Date of registration: Feb 9th 2009

Location: Mladenovac, Serbia

Occupation: Programming

Hobbies: Programming

  • Send private message

1

Thursday, August 13th 2009, 10:12pm

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

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

birosys

Trainee

  • "birosys" is male
  • "birosys" started this thread

Posts: 48

Date of registration: Feb 9th 2009

Location: Mladenovac, Serbia

Occupation: Programming

Hobbies: Programming

  • Send private message

2

Thursday, August 13th 2009, 11:02pm

Ok, with little thinking i got answer.
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

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

3

Thursday, August 13th 2009, 11:14pm

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

birosys

Trainee

  • "birosys" is male
  • "birosys" started this thread

Posts: 48

Date of registration: Feb 9th 2009

Location: Mladenovac, Serbia

Occupation: Programming

Hobbies: Programming

  • Send private message

4

Thursday, August 13th 2009, 11:23pm

Hi OlimilO

Let to say that i want to use some swing usercontrol, like grid, or anyone, and i want to add some EventHandler for that control, like click on cell...

is there any other way to create class for that event, or i must add every time new class file?

Thanks

Milan

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

5

Thursday, August 13th 2009, 11:45pm

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.

birosys

Trainee

  • "birosys" is male
  • "birosys" started this thread

Posts: 48

Date of registration: Feb 9th 2009

Location: Mladenovac, Serbia

Occupation: Programming

Hobbies: Programming

  • Send private message

6

Thursday, August 13th 2009, 11:47pm

Can i get little sample how to do it? :S

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

7

Thursday, August 13th 2009, 11:51pm

Quoted

little sample how to do it
Yes of course what kind of event do you miss?

birosys

Trainee

  • "birosys" is male
  • "birosys" started this thread

Posts: 48

Date of registration: Feb 9th 2009

Location: Mladenovac, Serbia

Occupation: Programming

Hobbies: Programming

  • Send private message

8

Friday, August 14th 2009, 12:00am

OlimilO, i do not have currently any. :)
I just investigate how to use events with swing and jabaco.
I hope that you understand me.

Sorry for my poor english.

birosys

Trainee

  • "birosys" is male
  • "birosys" started this thread

Posts: 48

Date of registration: Feb 9th 2009

Location: Mladenovac, Serbia

Occupation: Programming

Hobbies: Programming

  • Send private message

9

Saturday, August 15th 2009, 10:33pm

OlimilO, can you post example for ActionListener of JButton?

Thanks

Milan

birosys

Trainee

  • "birosys" is male
  • "birosys" started this thread

Posts: 48

Date of registration: Feb 9th 2009

Location: Mladenovac, Serbia

Occupation: Programming

Hobbies: Programming

  • Send private message

10

Saturday, August 15th 2009, 10:40pm

Ok, i found solution

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 :P

Milan

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

11

Sunday, August 16th 2009, 11:01am

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:

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

birosys

Trainee

  • "birosys" is male
  • "birosys" started this thread

Posts: 48

Date of registration: Feb 9th 2009

Location: Mladenovac, Serbia

Occupation: Programming

Hobbies: Programming

  • Send private message

12

Sunday, August 16th 2009, 9:22pm

Cool OlimilO.

Now, when we know how to implement custom events for swing controls, only imagination is limit.
There are very big collection of great swing custom controls on sourceforge.net
Take a look.

Milan

Rate this thread
WoltLab Burning Board