Answer the question
In order to leave comments, you need to log in
Could someone help with java sving?
Hello everyone, I am writing a term paper on java swing. The essence of coursework is to read an image from a pgm file and display it in a separate window. The image must be scalable, i.e. automatically enlarge when the window is enlarged. (There were no problems with this) You also need to point with the arrows to the brightest and darkest and lightest pixel of the picture (the arrows should not under any circumstances climb out of the picture borders) This is also done. The problem arose in the last part: you need to display captions for the arrows, which also should not crawl out of the image. In my case, for some reason, the characteristics of the inscription are displayed incorrectly, i.e. width and height, and when scaling, the inscription does not go where it should. I'm attaching the code, maybe someone can tell me what's wrong. Thanks in advance for your reply.
private void popisBodu (double x1, double y1, double x2, double y2, String nadpis, Graphics2D g2, double font, double scale) {
FontMetrics fm = g2.getFontMetrics();
g2.setColor(Color.BLACK);
g2.setFont(new Font ("Calibri", Font.PLAIN, (int)font));
double vyska = fm.getLineMetrics(nadpis, g2).getHeight();
double delka = fm.stringWidth(nadpis);
System.out.println(delka + ": delka");
System.out.println(vyska + ": vyska");
double sourPopisX = 0;
double sourPopisY = 0;
if(y1 == y2) {
if(x1 > x2) {
sourPopisY = y1;
sourPopisX = x1 + 5;
}
else if(x1 < x2) {
sourPopisY = y1;
sourPopisX = x1 - (5 + delka);
}
}
else if(y1 > y2) {
if(x1 == x2) {
sourPopisX = ((x1 - 30) - x_min) * scale ;
sourPopisY = (((y1 ) - y_min) * scale) + vyska ;
}
else if(x1 > x2) {
sourPopisX = x1 + 5;
sourPopisY = y1;
}
else if(x1 < x2) {
sourPopisY = y1;
sourPopisX = x1 - (5 + delka * font);
}
}
else if(y1 < y2) {
}
g2.drawString(nadpis, (int)sourPopisX, (int)sourPopisY);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question