Java Reference
In-Depth Information
55
public int getYCoordinate() {
56
return yCoordinate;
57 }
58
59 /** Set a new yCoordinator */
60 public void setYCoordinate( int y) {
61 this .yCoordinate = y;
62 repaint();
63 }
64
65
repaint panel
/** Return centered */
66
public boolean isCentered() {
67
return centered;
68 }
69
70 /** Set true or false to tell whether the message is centered */
71 public void setCentered( boolean centered) {
72 this .centered = centered;
73 repaint();
74 }
75
76
repaint panel
/** Return interval */
77
public int getInterval() {
78
return interval;
79 }
80
81 /** Set a new interval */
82 public void setInterval( int interval) {
83 this .interval = interval;
84 repaint();
85 }
86
87 @Override /** Paint the message */
88
repaint panel
override paintComponent
protected void paintComponent(Graphics g) {
89
super .paintComponent(g);
90
91 {
92 // Get font metrics for the current font
93 FontMetrics fm = g.getFontMetrics();
94
95 // Find the center location to display
96 int stringWidth = fm.stringWidth(message);
97 int stringAscent = fm.getAscent();
98 // Get the position of the leftmost character in the baseline
99 xCoordinate = getWidth() / 2 - stringWidth / 2 ;
100 yCoordinate = getHeight() / 2 + stringAscent / 2 ;
101 }
102
103 g.drawString(message, xCoordinate, yCoordinate);
104 }
105
106 /** Move the message left */
107 public void moveLeft() {
108 xCoordinate -= interval;
109 repaint();
110 }
111
112 /** Move the message right */
113 public void moveRight() {
114 xCoordinate += interval;
if (centered)
check centered
 
Search WWH ::




Custom Search