19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

25<br />

26 public Dimension preferredLayoutSize(Container parent) {<br />

27 return minimumLayoutSize(parent);<br />

28 }<br />

29<br />

30 public Dimension minimumLayoutSize(Container parent) {<br />

31 return new Dimension(0, 0);<br />

32 }<br />

33<br />

34 public void layoutContainer(Container parent) {<br />

35 int numberOfComponents = parent.getComponentCount();<br />

36<br />

37 Insets insets = parent.getInsets();<br />

38 int w = parent.getSize().width - insets.left - insets.right;<br />

39 int h = parent.getSize().height - insets.bot<strong>to</strong>m - insets.<strong>to</strong>p;<br />

40<br />

41 if (majorDiagonal) {<br />

42 int x = 10, y = 10;<br />

43<br />

44 for (int j = 0; j < numberOfComponents; j++) {<br />

45 Component c = parent.getComponent(j);<br />

46 Dimension d = c.getPreferredSize();<br />

47<br />

48 if (c.isVisible())<br />

49 if (lastFill && (j == numberOfComponents - 1))<br />

50 c.setBounds(x, y, w - x, h - y);<br />

51 else<br />

52 c.setBounds(x, y, d.width, d.height);<br />

53 x += d.height + gap;<br />

54 y += d.height + gap;<br />

55 }<br />

56 }<br />

57 else { // It is subdiagonal<br />

58 int x = w - 10, y = 10;<br />

59<br />

60 for (int j = 0; j < numberOfComponents; j++) {<br />

61 Component c = parent.getComponent(j);<br />

62 Dimension d = c.getPreferredSize();<br />

63<br />

64 if (c.isVisible())<br />

65 if (lastFill & (j == numberOfComponents - 1))<br />

66 c.setBounds(0, y, x, h - y);<br />

67 else<br />

68 c.setBounds(x - d.width, y, d.width, d.height);<br />

69<br />

70 x -= (d.height + gap);<br />

71 y += d.height + gap;<br />

72 }<br />

73 }<br />

74 }<br />

75<br />

76 public int getGap() {<br />

77 return gap;<br />

78 }<br />

79<br />

80 public void setGap(int gap) {<br />

81 this.gap = gap;<br />

82 }<br />

83<br />

18

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!