Package jltk
Class App
- java.lang.Object
-
- jltk.App
-
- Direct Known Subclasses:
AppTester
,GuiTest
,ShapeTests
,TabellenTest
public class App extends Object
The class App is a prototype of an eventhandler, which handles basic mouse and keyboard events. It also provides a window (object of class Window), on which you can draw with an Pen or where you can place gui components like button, textfields, ...
To use this class you have to create a subclass of it, likepublic class myClass extends App{ ...}
For each event (mouse moved, mouse pressed, et cetera) there is an method (eventhandler), which will be called, if this event occurs. E.g. the method onMouseMoved(int pX, int pY) is called, if the mouse moved. The Parameter will be set to the current x- and y-coordinates. In your subclass you have to overwrite this method and fit it to your needs.
To use gui-components like buttons or textfields, you only have to create an object of the corresponding class and pass the coordinates and size to the constructor. Remember, the origin of the coorinate system is the upper left corner of the window. The x-axis points to the right, the y-axis points down.
For example:btn = new Button(60,80,100,25,"Hello World")
creates a button with width 100 and height 25. The upper left corner of the button has the coordinates (60/80). The button is labled with "Hello World". Dont forget to import jltk.gui.*. To handle a button pressed event, you can define a method, which will be called, if the button is pressed. For example: If you add
btn.onButtonClicked("doSomething");
the method doSomething() is called, every time the button is clicked. Of course, you have to implement the method doSomething() in your subclass of App.
There are a lot of gui components, check the package jltk.gui for all components.
Mention: The can be only on subclass of App in each project.- Version:
- 12.06.2022
- Author:
- ms
-
-
Constructor Summary
Constructors Constructor Description App(int pWidth, int pHeight)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
act()
This method is called, every time no other eventhandler is called (on idle).void
delay(int pMilliseconds)
Delays the execution by the specified amount of milliseconds.Window
getWindow()
Return the window object which belongs to this app instance.void
onFocusGained()
This method is called if the window of this app get the focus.void
onFocusLost()
This method is called if the window of this app lost the focus.void
onKeyPressed(String pKey)
Will be called, if a key on the keyboard was pressed.void
onKeyReleased(String pKey)
Will be called, if a key on the keyboard was released.void
onMouseClicked(int pX, int pY)
Will be called, if the mouse was clicked.void
onMouseDoubleClicked(int pX, int pY)
Will be called, if the mouse was double clicked.void
onMouseDragged(int pX, int pY)
Will be called, if the mouse was dragged (pressed and moved).void
onMouseMoved(int pX, int pY)
Will be called, if the mouse was moved.void
onMousePressed(int pX, int pY)
Will be called, if the mouse was pressed.void
onMouseReleased(int pX, int pY)
Will be called, if the mouse was released.
-
-
-
Method Detail
-
getWindow
public Window getWindow()
Return the window object which belongs to this app instance. You also can use this.window to get this object.- Returns:
- The window object.
-
onMouseMoved
public void onMouseMoved(int pX, int pY)
Will be called, if the mouse was moved. You have to overwrite this method in your subclass- Parameters:
pX
- The x-coordinate of the mouse positionpY
- The y-coordinate of the mouse position
-
onMouseClicked
public void onMouseClicked(int pX, int pY)
Will be called, if the mouse was clicked. You have to overwrite this method in your subclass- Parameters:
pX
- The x-coordinate of the mouse positionpY
- The y-coordinate of the mouse position
-
onMousePressed
public void onMousePressed(int pX, int pY)
Will be called, if the mouse was pressed. You have to overwrite this method in your subclass- Parameters:
pX
- The x-coordinate of the mouse positionpY
- The y-coordinate of the mouse position
-
onMouseReleased
public void onMouseReleased(int pX, int pY)
Will be called, if the mouse was released. You have to overwrite this method in your subclass- Parameters:
pX
- The x-coordinate of the mouse positionpY
- The y-coordinate of the mouse position
-
onMouseDragged
public void onMouseDragged(int pX, int pY)
Will be called, if the mouse was dragged (pressed and moved). You have to overwrite this method in your subclass- Parameters:
pX
- The x-coordinate of the mouse positionpY
- The y-coordinate of the mouse position
-
onMouseDoubleClicked
public void onMouseDoubleClicked(int pX, int pY)
Will be called, if the mouse was double clicked. You have to overwrite this method in your subclass- Parameters:
pX
- The x-coordinate of the mouse positionpY
- The y-coordinate of the mouse position
-
onKeyPressed
public void onKeyPressed(String pKey)
Will be called, if a key on the keyboard was pressed. The parameter pKey is the corresponding key name.The following key names are recognized:
- a-z
- 0-1
- up, down, left, right (cursor keys)
- enter, space, tab, escape, backspace
- F1-F12 (function keys)
You have to overwrite this method in your subclass.
- Parameters:
pKey
- The name of the pressed key
-
onKeyReleased
public void onKeyReleased(String pKey)
Will be called, if a key on the keyboard was released. The parameter pKey is the corresponding key nameThe following key names are recognized:
- a-z
- 0-1
- up, down, left, right (cursor keys)
- enter, space, tab, escape, backspace
- F1-F12 (function keys)
You have to overwrite this method in your subclass.
- Parameters:
pKey
- The name of the pressed key
-
act
public void act()
This method is called, every time no other eventhandler is called (on idle). You have to overwrite this method in your subclass.
-
onFocusGained
public void onFocusGained()
This method is called if the window of this app get the focus. You have to overwrite this method in your subclass.
-
onFocusLost
public void onFocusLost()
This method is called if the window of this app lost the focus. You have to overwrite this method in your subclass.
-
delay
public void delay(int pMilliseconds)
Delays the execution by the specified amount of milliseconds.- Parameters:
pMilliseconds
- The duration of delay in milliseconds
-
-