Java 从字符串数组到块图
我制作了一个程序,通过Jena获取一些SPARQL查询的结果,并将它们保存在二维字符串中(即,二维字符串数组)。我只想取第一列的值,然后设计一个块图,其中每个块包含第一列的每个值,并将它们依次链接起来 从我所读到的,似乎是非常有帮助的,但我下载了它,并试图这样做,但我失败了 我怎样才能用JGraph实现这一点,或者还有其他方法吗Java 从字符串数组到块图,java,user-interface,jgraph,Java,User Interface,Jgraph,我制作了一个程序,通过Jena获取一些SPARQL查询的结果,并将它们保存在二维字符串中(即,二维字符串数组)。我只想取第一列的值,然后设计一个块图,其中每个块包含第一列的每个值,并将它们依次链接起来 从我所读到的,似乎是非常有帮助的,但我下载了它,并试图这样做,但我失败了 我怎样才能用JGraph实现这一点,或者还有其他方法吗 这里有一个我组合起来的方法,它将绘制一个矩形,用颜色填充它,并在矩形的中心放置一个字符串 /** * <p>This method will draw a
这里有一个我组合起来的方法,它将绘制一个矩形,用颜色填充它,并在矩形的中心放置一个字符串
/**
* <p>This method will draw a rectangle and place the text in the center
* of the rectangle.</p>
* @param g - Graphics instance from a JPanel paintComponent method
* @param r - Rectangle (origin and dimension) of the rectangle.
* @param c - Fill color of the rectangle.
* @param s - String to place at the center of the rectangle.
*/
public void drawBox(Graphics g, Rectangle r, Color c, String s) {
g.setColor(c);
g.fillRect(r.x, r.y, r.width, r.height);
Graphics2D g2d = (Graphics2D) g;
FontRenderContext frc = g2d.getFontRenderContext();
TextLayout layout = new TextLayout(s, g.getFont(), frc);
Rectangle2D bounds = layout.getBounds();
int width = (int) Math.round(bounds.getWidth());
int height = (int) Math.round(bounds.getHeight());
int x = r.x + (r.width - width) / 2;
int y = r.y + height + (r.height - height) / 2;
g.setColor(Color.BLACK);
layout.draw(g2d, (float) x, (float) y);
}
/**
*此方法将绘制一个矩形,并将文本置于中心
*矩形的一部分
/**
* <p>This method will draw a rectangle and place the text in the center
* of the rectangle.</p>
* @param g - Graphics instance from a JPanel paintComponent method
* @param r - Rectangle (origin and dimension) of the rectangle.
* @param c - Fill color of the rectangle.
* @param s - String to place at the center of the rectangle.
*/
public void drawBox(Graphics g, Rectangle r, Color c, String s) {
g.setColor(c);
g.fillRect(r.x, r.y, r.width, r.height);
Graphics2D g2d = (Graphics2D) g;
FontRenderContext frc = g2d.getFontRenderContext();
TextLayout layout = new TextLayout(s, g.getFont(), frc);
Rectangle2D bounds = layout.getBounds();
int width = (int) Math.round(bounds.getWidth());
int height = (int) Math.round(bounds.getHeight());
int x = r.x + (r.width - width) / 2;
int y = r.y + height + (r.height - height) / 2;
g.setColor(Color.BLACK);
layout.draw(g2d, (float) x, (float) y);
}
*@param g-来自JPanel paintComponent方法的图形实例
*@param r-矩形的矩形(原点和尺寸)。
*@param c-矩形的填充颜色。
*@param s-要放置在矩形中心的字符串。
*/
公共空白绘图框(图形g、矩形r、颜色c、字符串s){
g、 setColor(c);
g、 fillRect(r.x,r.y,r.宽度,r.高度);
Graphics2D g2d=(Graphics2D)g;
FontRenderContext frc=g2d.getFontRenderContext();
TextLayout=新的TextLayout(s,g.getFont(),frc);
矩形2D边界=layout.getBounds();
int width=(int)Math.round(bounds.getWidth());
int height=(int)Math.round(bounds.getHeight());
intx=r.x+(r.width-width)/2;
int y=r.y+高度+(r.height-高度)/2;
g、 设置颜色(颜色为黑色);
布局图(g2d,(浮动)x,(浮动)y);
}
您必须找出矩形的位置以及如何将它们与瘦矩形连接。元素1是否始终连接到元素2,依此类推,或者字符串结果的顺序是否取决于字符串的值?元素1始终连接到元素2@吉尔伯特布朗