Working with graphics menu images
This presentation is the property of its rightful owner.
Sponsored Links
1 / 14

Working with Graphics, Menu, Images PowerPoint PPT Presentation


  • 68 Views
  • Uploaded on
  • Presentation posted in: General

Working with Graphics, Menu, Images. All graphics are drawn relative to a window Origin of each window is at top left corner 0,0 coordinates in pixel. Graphics class is obtained in two ways Passed to an applet when one of its various methods such as paint() or update() is called.

Download Presentation

Working with Graphics, Menu, Images

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Working with graphics menu images

Working with Graphics, Menu, Images


Working with graphics menu images

  • All graphics are drawn relative to a window

  • Origin of each window is at top left corner 0,0 coordinates in pixel.

  • Graphics class is obtained in two ways

    • Passed to an applet when one of its various methods such as paint() or update() is called.

    • It is returned by getGraphics() method of Component.


Drawing lines

Drawing Lines

  • void drawLine(int startX, int startY,int endX, int endY)

  • Example


Drawing rectangles

Drawing Rectangles

  • void drawRect(int top,int left, int width, int height)

  • void fillRect(int top,int left,int width,int height)

  • void drawRoundRect(int top,int left,int width,int height,int xDiam,int yDiam)

  • void fillRoundRect(int top,int left,int width,int height,int xDiam, int yDiam)

  • Example


Drawing ellipses and circles

Drawing Ellipses and Circles

  • void drawOval(int top,int left,int width,int height)

  • void fillOval(int top,int left,int width,int height)

  • Example


Drawing arcs

Drawing Arcs

  • void drawArc(int top,int left,int width,int height,int startAngle, int sweepAngle)

  • void fillArc(int top,int left,int width,int height,int startAngle, int sweepAngle)

  • Start angle tells the angle from where arc is to be drawn and sweep angle tells the angle upto where the arc is to be drawn.

  • The arc is bounded by rectangle.

  • Angles are in degree

  • The arc is drawn counterclockwise if sweepAngle is +ve and clockwise is sweep angle is –ve.

  • Example


Drawing polygon

Drawing Polygon

  • void drawPolygon(int x[], int y[], int numPoints)

  • void fillPolygon(int x[],int y[], int numPoints)

  • Example


Menu bars and menus

Menu Bars and Menus

  • Classes:

    • MenuBar

    • Menu

    • MenuItem

    • A menu bar contains one or more Menu objects.

    • Each Menu objects contains a list of MenuItem objects.

    • Each MenuItem object represent something that can be selected by the user.

    • Menu is a subclass of MenuItem, so sub menus can be created.

    • CheckboxMenuItem is used for checkable menu item.


Working with graphics menu images

  • First create instance of MenuBar by using default constructor.

  • Then create instance of Menu:

    • Menu()

    • Menu(String optionName)

    • Menu(String optionName, boolean removable)

      If removable is true – menu can be removed.


Working with graphics menu images

  • Create MenuItem:

    • MenuItem()

    • MenuItem(String itemName)

    • MenuItem(String itemName,MenuShortcut key)

      Disable [ false ] / Enable [ true ] menu item by void setEnabled(boolean enabledFlag)

      To know item’s status use

      boolean isEnabled()


Working with graphics menu images

  • More on menu item:

  • void setLabel(String newName)

  • String getLabel()


Checkable menu item

Checkable menu item

  • CheckboxMenuItem()

  • CheckboxMenuItem(String itemName)

  • CheckboxMenuItem(String itemName, boolean on)

  • To obtain status :

  • boolean getState()[ checked=true ]

  • void setState(boolean checked)


Working with graphics menu images

  • After creating menu item, add the item to Menu object by:

    • MenuItem add(MenuItem item)

    • Then add Menu object to MenuBar by :

      Menu add(Menu menu)


Working with graphics menu images

  • Each time a menu item is selected, an ActionEvent object is generated.

  • Each time a check box menu item is checked or unchecked, an ItemEvent object is generated.

  • So implement ActionListener and ItemListener interfaces to handle these menu events.

  • The getItem() method of ItemEvent returns a reference to the item that generated this event.

    • Object getItem()

      Example


  • Login