GUI graphical user interface - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

GUI graphical user interface

Description:

??? ???? (??? ??-????) ????? ?? ???? ?-html. ... HTML ????? ?-DataStructure. ????? ????? ?????? ???? ?????. ... public void paint(Graphics page) LineCanvas.java ... – PowerPoint PPT presentation

Number of Views:137
Avg rating:3.0/5.0
Slides: 24
Provided by: Rot7
Category:

less

Transcript and Presenter's Notes

Title: GUI graphical user interface


1
GUI graphical user interface
2
Ex6
3
Applets
  • ?-java ???? ????? applications ??? ??????? ??????
    ??? ???? ?????, ?? applets ??? ???? ??????
    ???????? ?????? ??? ?-web.
  • ???? ????? applets ?? ??? Jcreator.
  • ?-applet ????? ????? ?? ?????? ??????? ?? ?? ??.

4
?????? ???? (mouse events)
???? (applet)
???? ???? (canvas)
???? (Data structure)
??????? (Buttons)
5
?????? ???????? ????? ??????
  • 2 ?????? ?????????? Ex6Applet.java
    ?-Ex6Canvas.java ??????? ??? ???? ?????? ???? ??
    ??-???? ????.
  • LineApplet.java ?-LineCanvas.java?????? ??
    ??????? ??????????? ?????? ?? ?????? ???????????
    ???? ?????? ?????.
  • ?????? DataStructure.java ????? ?? ???? ??????
    ??????? ??? ????? ???? ??????.
  • ???? html ??? RunEx6.html

6
??? ??????? ??? ???????
  • ????? ??????? ???????? ??? ??????? ??????.
  • ???????(????) ??? main( ) ?????? ?????? ????? ???
    ???? ?????? ????? (LineApplet.java).
  • ?? ??? ????? ?? ????? ?? ????? ???? ?Jcreator- ??
    ???? ?-html ??????, ?????? ???? ????? ??????,
    ?????? Execute File (????? ?? ??? ??????).
  • ??? ???? (??? ??-????) ????? ?? ???? ?-html.
  • ???? ???? ?????? ??? ?????, ??? ????? ????
    ??????? ???? ?????? ?? LineApplet !!!

7
???? ?-html
  • lt! Lines.htmlgt
  • ltHTMLgt
  • ltHEADgt
  • ltTITLEgtThe Lines Appletlt/TITLEgt
  • lt/HEADgt
  • ltBODYgt
  • ltH3gtThe Lines Appletlt/H3gt
  • ltAPPLET CODELineApplet.class" WIDTH300
    HEIGHT300gt
  • lt/APPLETgt
  • ltHRgt
  • lt/BODYgt
  • lt/HTMLgt

8
????? ?-DataStructure
  • ????? ????? ?????? ???? ?????.
  • ?????? ???? ????? private ??? arN2
  • X1 Y1
  • X2 Y2
  • .
  • XN YN
  • ???? ??? ??? ?? ????? (??????, ???? clear ?? ????
    ???? undo) ??? ????? ????? ?? null.

9
????? ?-DataStructure
  • ????? ??????
  • public void clear( )
  • public void undo( )
  • public void addPoint(int x , int y)
  • public int pointX(int index)
  • public int pointY(int index)
  • public int length( )

10
Ex6Applet.java
  • ????? ????????? ??????? ????? ???? ???? ??
    ??????? ??? ???? ???. ????? ?? ?????? ???????????
    ?????
  • public abstract String setTitle()
  • public abstract int setAppletWidth()
  • public abstract int setAppletHeight()
  • public abstract Ex6Canvas setCanvas()
  • public abstract void addButtons()
  • public abstract void actionPerformed (Object
    obj)

11
Ex6Applet.java
  • ????? ????? ?????? ?? ????? ???????? (???
    ?????????) ????, ??????? ??? ????? ????????
    ?????-???? ?? ?????
  • protected Ex6Canvas getCanvas( )

12
LineApplet.java
  • ????? ?? Ex6Applet ?"? ????? ?????? ???????????
  • public String setTitle()
  • return "Drawing Lines!"
  • public int setAppletWidth()
  • return APPLET_WIDTH
  • public Ex6Canvas setCanvas()
  • return new LineCanvas()
  • "????" ???? ???????????? ????? ???????.

13
LineApplet.java
  • ????? ??????? (?"? ????? ?????)
  • // Buttons are fields
  • private Button undoButton
  • private Button clearButton
  • public void addButtons()
  • undoButton new Button("Undo")
  • undoButton.addActionListener (this)
  • add (undoButton)
  • clearButton new Button("Clear")
  • clearButton.addActionListener (this)
  • add (clearButton)

14
LineApplet.java
  • ????? ????? ???????
  • public void actionPerformed (Object obj)
  • if (obj clearButton)
  • ((LineCanvas) getCanvas()).clearAll()
  • if (obj undoButton)
  • ((LineCanvas) getCanvas()).undo()

15
Ex6Canvas.java
  • ????? ????????? ?????? ?????? ?????? ?? ?????.
    ????? ?? ?????? ??????????? ????? ???? ?????
    ????
  • public abstract int setCanvasWidth()
  • public abstract int setCanvasHeight()
  • public abstract void mousePressed

  • (int x , int y)

16
Ex6Canvas.java
  • ????? ????? ?????? ???? ????? ????? ?? ??????????
    ????????
  • public void repaint( ) //refreshes the canvas
  • public void clear( ) //clear the canvas
  • ??? ???? ???? ???? ??? ?????? ????? ?? ???
    ???????? ????? ???? ?????? ?? ???
  • public void paint(Graphics page)

17
LineCanvas.java
  • ????? ?? Ex6Canvas, ?????? ?? ??????? ?-canvas
    ?????. ????? ?? ????? ?????
  • private final int CANVAS_WIDTH 400
  • private final int CANVAS_HEIGHT 400
  • private DataStructure ds

18
LineCanvas.java
  • ????
  • public LineCanvas()
  • super()
  • ds new DataStructure()

19
LineCanvas.java
  • ????? ?????? ???????????
  • public int setCanvasWidth()
  • return CANVAS_WIDTH
  • public void mousePressed (int x , int y)
  • ds.addPoint(x,y)
  • repaint()

20
LineCanvas.java
  • ????? ??????
  • public void clearAll( )
  • ds.clear()
  • clear()
  • public void undo( )
  • ds.undo()
  • clear()
  • repaint()

21
LineCanvas.java
  • ????? ????? paint
  • public void paint(Graphics page)
  • for (int c0 cltds.length()-1 c)
  • page.drawLine(ds.pointX(c),
    ds.pointY(c), ds.pointX(c1),
  • ds.pointY(c1))

22
Ex6
23
????? ??????
  • ??????? Ex6Canvas ?-Ex6Applet ?????? ?????
    ??????? ?????? ????????. ?? ????? ???? ?? ???
    ?????? ?? ???? ??????? ??? ???????, ??? ?????
    ????? ???? ?? ????. ??? ?????? ?????? ??????? ???
    ?? ??? ?????? ??????.
  • ???? ?? ????? ????? (?? ???? DataStructure.java)
    ???????? ????? ?????? ??? ?? ???? ?-50 ????? ???.
  • ???? ???? ???? ?? ?? ??? ???? ?????? ????????? ??
    ?? ??.
  • ?? ????? ????? ???? ?? LineApplet ?? ??? ????? ??
    ??? ??????? ???? ????? ?????? ????? ?????.
Write a Comment
User Comments (0)
About PowerShow.com