# How to directly use the class from library in my class

**URL:** <https://discourse.processing.org/t/how-to-directly-use-the-class-from-library-in-my-class/39564>\
**Category:** Processing.py\
**Created:** [November 3, 2022, 3:09am UTC](https://discourse.processing.org/t/how-to-directly-use-the-class-from-library-in-my-class/39564 "2022-11-03T03:09:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![huxx](https://avatars.discourse-cdn.com/v4/letter/h/edb3f5/32.png) [@huxx](https://discourse.processing.org/u/huxx)\
**Post date:** [November 3, 2022, 3:09am UTC](https://discourse.processing.org/t/how-to-directly-use-the-class-from-library-in-my-class/39564/1 "2022-11-03T03:09:50Z")

</div>

```auto
//First label

add_library('box2d_processing')
add_library('jbox2d')

from gameInterface import GameInterface

def setup():
    global gameI
    box2D =Box2DProcessing(this)
    gameI=GameInterface(box2D)

```

```auto
//Second label
class GameInterface:
    def __init__ (self,b):
        self.box2d=b
        
class rectBoundary:
    bd=BodyDef()

```

If I initialize the BodyDef() in the setup() and deliver it through the **init** (),  
it can work.  
But compared to java. Why can’t I directly use the class from library in the class which created by myself?  
🥲 🤔

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/c/5c67f73fb4e4ba7f10c32ed12b9db804a2016bab.png)

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [November 3, 2022, 10:23am UTC](https://discourse.processing.org/t/how-to-directly-use-the-class-from-library-in-my-class/39564/2 "2022-11-03T10:23:22Z")

</div>

Add a (Python) import line for JBox2D to your _gameInterface.py_ file –

```python
from org.jbox2d.dynamics import *

class GameInterface:
    def __init__ (self,b):
        self.box2d=b
        
class rectBoundary:
    bd=BodyDef()

```

---

<div class="post-metadata">

**Author:** ![huxx](https://avatars.discourse-cdn.com/v4/letter/h/edb3f5/32.png) [@huxx](https://discourse.processing.org/u/huxx)\
**Post date:** [November 3, 2022, 10:43am UTC](https://discourse.processing.org/t/how-to-directly-use-the-class-from-library-in-my-class/39564/4 "2022-11-03T10:43:29Z")

</div>

Wow! It works. Thanks a lot. Could you tell me the reason, the difference between add\_library and import. Could you give me a brief explanation or some source about it. Sincerely appreciate!
