Az előadás letöltése folymat van. Kérjük, várjon

Az előadás letöltése folymat van. Kérjük, várjon

Fejlett Webes Technológiák II.

Hasonló előadás


Az előadások a következő témára: "Fejlett Webes Technológiák II."— Előadás másolata:

1 Fejlett Webes Technológiák II.
Bilicki Vilmos

2 A mai előadás tartalma:
MIDP (Mobile Information Device Profile) Magas szintű eseménykezelés Alacsony szintű eseménykezelés, grafika

3 Eseménykezelés Felhasználói műveletek kezelése:
Absztrakt parancsok (magas szintű grafika esetén) Alacsony szintű események (alacsony szintű grafika esetén) paint() metódus run() metódus

4 Absztrakt parancsok Parancsokat (Commands) definiálunk és ezeket absztrakt elemekhez rendeljük Displayable objektumhoz rendelhetünk ilyen parancsokat az addCommand() metódus segítségével A készülék stílusa meghatározhatja az ilyen absztrakt elemek helyét (pl.: vissza a bal oldalon) A Command objektum paraméterei: Label (a felirat) CommandType (a parancs jelentése, ha saját akkor SCREEN, egyébként megváltozhat) Priority (a parancs prioritása)

5 CommandListener A magas szintű eseménykezelés a Listener modellen alapul. Ahhoz, hogy egy objektum Listener legyen meg kell valósítania a CommandListener interfészt void commandAction(Command c, Displayable d); Akkor kapja meg az eseményeket, ha a Displayable objektumhoz: Vannak parancsok csatolva (addCommand()) Van Listener regisztrálva setCommandListener()

6 Példa alkalmazás Választó ablak (Choice) otherScreen() MIDlet
(RecSet ) otherScreen() otherScreen() Bevitel Ablak (Screen) outPut()

7 Osztályok

8 RecSet startApp() protected void startApp() throws MIDletStateChangeException { try { recordStore = RecordStore.openRecordStore(RECORD_STORE_NAME, true); } catch (RecordStoreException rse) { screen = new Screen(this,"Bevitel","",255,0); choiceSc = new Choice(this,"Bevitel",255); Display.getDisplay(this).setCurrent(screen);

9 RecSet otherScreen(String str)
void otherScreen(String str) { if(Display.getDisplay(this).getCurrent() == choiceSc) { if(str=="") { Display.getDisplay(this).setCurrent(screen); } else Alert alert; Image source = null; try{ source = Image.createImage("/kep1.png"); } catch(Exception e){} alert = new Alert(str, "Ez egy Alert",source,null); Display.getDisplay(this).setCurrent(alert); } { Display.getDisplay(this).setCurrent(choiceSc); }

10 RecSet outPut(String str)/I
void outPut(String str) { String input; Alert alert; alert = new Alert("A beirt szoveg", str,null,null); Display.getDisplay(this).setCurrent(alert); ByteArrayOutputStream bout = null; DataOutputStream dout = null; try { bout = new ByteArrayOutputStream(); dout = new DataOutputStream(bout); dout.writeUTF(str); byte[] record = bout.toByteArray(); if (recordStore.getNumRecords() > 0) { recordStore.setRecord(1, record, 0, record.length); } else { recordStore.addRecord(record, 0, record.length); } } catch (RecordStoreException rse) {} catch (IOException ioe) {}

11 RecSet outPut(String str)/II
finally { if (dout != null) { try { dout.close(); } catch (IOException ioe) { } } if (bout != null) { try { bout.close(); }

12 RecSet outPut(String str)/III
DataInputStream din = null; try { if (recordStore.getNumRecords() > 0) { byte[] record = recordStore.getRecord(1); din = new DataInputStream(new ByteArrayInputStream(record)); input = din.readUTF(); alert = new Alert("A beolvasott",input,null,null); Display.getDisplay(this).setCurrent(alert); } else {

13 RecSet outPut(String str)/IV
catch (RecordStoreException rse) { } catch (IOException ioe) { finally { if (din != null) { try { din.close();

14 Screen/I public class Screen extends TextBox implements CommandListener { private RecSet midlet; private Command exitCommand; private Command otherScreen; private Command okCommand; public Screen(RecSet midlet, String p0, String p1, int p2, int p3) { super( p0, p1, p2, p3); this.midlet = midlet; exitCommand = new Command("Kilep", Command.EXIT, 1); otherScreen = new Command("Masik", Command.SCREEN, 1); okCommand = new Command("Kiir", Command.OK, 1); addCommand(exitCommand); addCommand(otherScreen); addCommand(okCommand); setCommandListener(this); }

15 Screen/II public void commandAction(Command c, Displayable p1) {
if (c == okCommand) { midlet.outPut(this.getString()); } if (c == exitCommand) midlet.exitRequested(); if (c == otherScreen) midlet.otherScreen(""); }}

16 Choice/I public class Choice extends List implements CommandListener {
private RecSet midlet; private Command otherScreen; private Command commandOK; public Choice(RecSet midlet,String p0, int p1) { super( "Lista", List.IMPLICIT); this.midlet = midlet; append("Elso", loadImage("/kep.png")); append("Masodik", loadImage("/kep1.png")); commandOK = new Command("OK", Command.SCREEN, 1); otherScreen = new Command("Masik", Command.SCREEN, 1); addCommand(commandOK); addCommand(otherScreen); setCommandListener(this); }

17 Choice/II public void commandAction(Command c, Displayable p1) {
if (c == otherScreen) { midlet.otherScreen(""); } if (c == commandOK) midlet.otherScreen(getString(getSelectedIndex()));

18 Choice III. private Image loadImage(String s) { Image image = null;
try{ image = Image.createImage(s); } catch(Exception e) return image;

19 Alacsony szintű események, grafika
A következő billentyűzet eseményeket kezeli: public void keyPressed(int keyCode); public void keyReleased(int keyCode); public void keyRepeated(int keyCode); GameAction: public void keyPressed(int keyCode) int action = getGameAction(keyCode); A keyReleased nincs feltétlenül megvalósítva

20 Példa class TetrisCanvas extends Canvas {
int leftKey, rightKey, downKey, rotateKey; void init () { leftKey = getKeyCode(LEFT); rightKey = getKeyCode(RIGHT); downKey = getKeyCode(DOWN); rotateKey = getKeyCode(FIRE); } public void keyPressed(int keyCode) { if (keyCode == leftKey) { moveBlockLeft(); } else if (keyCode = rightKey) { ...}}}

21 Példa GameAction public void keyPressed(int keyCode) {
int action = getGameAction(keyCode); if (action == LEFT) { moveBlockLeft(); } else if (action == RIGHT) { ... }

22 Rajzolás Canvas osztályból kell származtatni
protected abstract void paint(Graphics g) Nincs automaikus újrarajzolás: repaint(x2,y2, wid, ht) serviceRepaints(); Egyetlen rajzolási mód a pixel felülírás 24 bit színmélység (8 piros,8 kék, 8 zöld) g.setColor(WHITE); g.fillRect(0,0,95,50); g.setColor(BLACK);

23 Koordináta rendszer A képernyő bal felső sarkában 0,0
public static final int getWidth(); public static final int getHeight();

24 Példa Grafikus megjelenítő (Screen) MIDlet (GraphicsSample )

25 GraphicsSample public class GraphicsSample extends MIDlet {
Screen scr; public GraphicsSample() { } protected void startApp() throws MIDletStateChangeException { scr = new Screen(this); Display.getDisplay(this).setCurrent(scr); protected void pauseApp() { } protected void destroyApp(boolean p0) throws MIDletStateChangeException { }}

26 Screen/I import javax.microedition.lcdui.*;
import javax.microedition.midlet.*; public class Screen extends Canvas { GraphicsSample midlet; private static final int BLACK = 0x ; private static final int WHITE = 0x00FFFFFF; private static final int RED = 0x00FF0000; private static final int BLUE = 0x000000FF; int px,py; public Screen(GraphicsSample midlet) { this.midlet = midlet; px = 25; py = 25; }

27 Screen/II protected void paint(Graphics g) {
g.setColor(WHITE); g.fillRect(0,0,g.getClipWidth(),g.getClipHeight()); g.setColor(BLACK); g.drawArc(px,py,20,20,0,360); }

28 Screen/III protected void keyPressed(int keyCode) {
int gameAction = getGameAction(keyCode); switch (gameAction) case FIRE: break; case RIGHT: px++; repaint(); break; case DOWN: py++; repaint(); break; case LEFT: px--; repaint(); break; case UP: py--; repaint(); break; default: break; }

29 Rajzolás A Graphics osztály metódusai segítségével rajzolhatunk:
Szöveget Képeket Vonalakat Négyszögeket (telítettek is lehetnek) Szögeket (telítettek is lehetnek) A vonal stílusa lehet: Folyamatos (solid) Szaggatott (dotted) public void setStrokeStyle(int style)

30 Szöveg kiíratása public void drawChar(char character, int x, int y, int anchor) public void drawChars(char[] data, int offset, int length, int x, int y, int anchor) public void drawString(String str, int x, int y, int anchor) public void drawSubstring(String str, int offset, int len, int x, int y, int anchor) Szöveg irány: LEFT, HCENTER, RIGHT TOP, BASELINE, BOTTOM

31 Példa g.drawString(str, x, y, TOP|LEFT);
g.drawString(str, x + f.stringWidth(str)/2, y, TOP|HCENTER); g.drawString(str, x + f.stringWidth(str), y, TOP|RIGHT); g.drawString(str, x, y + f.getBaselinePosition(), BASELINE|LEFT); g.drawString(str, x + f.stringWidth(str)/2, y + f.getBaselinePosition(), BASELINE|HCENTER); g.drawString(str, x + f.stringWidth(str), y + f.getBaselinePosition(), BASELINE|RIGHT); drawString(str, x, y + f.getHeight(), BOTTOM|LEFT); drawString(str, x + f.stringWidth(str)/2, y + f.getHeight(), BOTTOM|HCENTER); drawString(str, x + f.stringWidth(str), y + f.getHeight(), BOTTOM|RIGHT);

32 Graphics metódusok public void drawLine(int x1, int y1, int x2, int y2) public void drawRect(int x, int y, int width, int height) public void fillRect(int x, int y, int width, int height) public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) public void drawImage(Image img, int x, int y, int anchor)


Letölteni ppt "Fejlett Webes Technológiák II."

Hasonló előadás


Google Hirdetések