code_junkie

Help with annotations

Nov 13th, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. @TopMenu("File,Edit")
  2. @Menu(name="File","Save,Load,Print,Preview,Quit")
  3. @Menu(name="Print","Preview,Print")
  4. @Menu(name="Edit","Copy,Paste")
  5.  
  6. public class TestMenu {
  7. @MenuItem ("Save")
  8. public void save() {
  9. System.out.println("saved");
  10. }
  11. @MenuItem ("Load")
  12. public void load() {
  13. System.out.println("loaded");
  14. }
  15. ...
  16.  
  17. @Retention(RetentionPolicy.RUNTIME)
  18. public @interface Menu {
  19. String name();
  20. String[] children();
  21. }
  22.  
  23. @Retention(RetentionPolicy.RUNTIME)
  24. public @interface MenuBar {
  25. Menu[] value();
  26. }
  27.  
  28. @Retention(RetentionPolicy.RUNTIME)
  29. public @interface MenuItem {
  30. String value();
  31. }
  32.  
  33. @MenuBar(
  34. {
  35. @Menu(name="File", children= {"Save","Load","Print","Preview","Quit"}),
  36. @Menu(name="Print", children= {"Preview","Print"}),
  37. @Menu(name="Edit", children= {"Copy","Paste"})
  38. }
  39. )
  40. public class TestMenu {
  41. @MenuItem ("Save")
  42. public void save() {
  43. System.out.println("saved");
  44. }
  45.  
  46. @MenuItem ("Load")
  47. public void load() {
  48. System.out.println("loaded");
  49. }
  50. }
Add Comment
Please, Sign In to add comment