comparison game/IDMButton.java @ 198:b88440f4431a

Allow no-text (null text) buttons.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 24 Apr 2019 14:53:27 +0300
parents 8dbaa093c562
children
comparison
equal deleted inserted replaced
197:f3302a2d7815 198:b88440f4431a
110 { 110 {
111 xoffs = yoffs = 0; 111 xoffs = yoffs = 0;
112 img = imgUnpressed; 112 img = imgUnpressed;
113 } 113 }
114 114
115 if (metrics == null) 115 g.drawImage(img, getScaledX() + xoffs, getScaledY() + yoffs, null);
116 metrics = g.getFontMetrics(font);
117 116
118 int textWidth = metrics.stringWidth(text); 117 if (text != null)
119 g.drawImage(img, getScaledX() + xoffs, getScaledY() + yoffs, null); 118 {
120 g.setFont(font); 119 if (metrics == null)
121 g.setPaint(Color.black); 120 metrics = g.getFontMetrics(font);
122 g.drawString(text, 121
123 getScaledX() + xoffs + (getScaledWidth() - textWidth) / 2, 122 int textWidth = metrics.stringWidth(text);
124 getScaledY() + yoffs + getScaledHeight() / 2); 123 g.setFont(font);
124 g.setPaint(Color.black);
125 g.drawString(text,
126 getScaledX() + xoffs + (getScaledWidth() - textWidth) / 2,
127 getScaledY() + yoffs + getScaledHeight() / 2);
128 }
125 } 129 }
126 130
127 131
128 public boolean mousePressed(MouseEvent e) 132 public boolean mousePressed(MouseEvent e)
129 { 133 {