package structure; import java.util.*; import java.awt.*; import java.awt.geom.*; import javax.swing.*; public class Bubble { String[] text; //dexcription Color clr; int w,h,x,y; boolean firstTime = true; public Bubble (){ firstTime = true; } //draws the hint for the Node on the screen public void paintComponent(Graphics g,int xval, int yval){ Graphics2D g2=(Graphics2D)g; Font f = g2.getFont(); FontMetrics fm = g2.getFontMetrics(); BasicStroke stroke = new BasicStroke(2.0f); int height = fm.getHeight(), x1=0,y1=0; if(firstTime){ //int ascent = fm.getAscent(); int maxwidth=0,maxheight=0; for (int j = 0; j < text.length; j ++) { int width = fm.stringWidth(text[j]); if(maxwidth < width) maxwidth = width; maxheight = maxheight + (int)(1.3*height); } maxheight=maxheight + height; maxwidth= maxwidth +6; w = maxwidth; h = maxheight; x = xval; y = yval; firstTime = false; } //draw rectangle and its border GradientPaint clrtogreen = new GradientPaint((int)x,(int)y,clr,(int)x,(int)y+(int)h,Color.green); g2.setPaint(clrtogreen ); // g2.fill(new Rectangle2D.Double((int)x, (int)y, (int)w, (int)h)); g2.fill(new RoundRectangle2D.Double((int)x,(int)y,(int)w,(int)h,15,15)); g2.setStroke(stroke); g2.setPaint(Color.black); // g2.draw(new RoundRectangle2D.Double((int)x,(int)y,(int)w,(int)h,15,15)); //draw text for (int j = 0; j < text.length; j ++) { x1 = x + (w - fm.stringWidth(text[j]))/2; y1 = y + (int)(1.3*(j+1)*height); g.drawString(text[j], x1, y1); } } public void setColor(Color c){ clr = c; } }