working with graphics menu images
Download
Skip this Video
Download Presentation
Working with Graphics, Menu, Images

Loading in 2 Seconds...

play fullscreen
1 / 14

Working with Graphics, Menu, Images - PowerPoint PPT Presentation


  • 100 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Working with Graphics, Menu, Images' - ami


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
slide2
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.
slide9
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.

slide10
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()

slide11
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)
slide13
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)

slide14
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

ad