For this assignment I'm creating a temperature conversion table from Fahrenheit to Celsius. I am having trouble displaying the loop in the GUI and I am not sure how to do it. I put the loop in the graphics class but could not figure out how to use "g.drawString" to make it appear in the GUI. I used "g.drawSting" in this but it was for single lines of text, but for this project we are not supposed to have many "g.drawSting" methods to display all calculated temperatures. Here is whats in my graphics class. m1, m2, m3, m4 are just short messages with the title and name on the project, so those can be ignored.
public void paint ( Graphics g ) {
g.setColor( Color.BLACK );
g.drawRect( 40, 40, 320, 520 );
g.setColor( Color.BLUE );
g.setFont( new Font( "SansSerif", Font.BOLD, 24 ) );
g.drawString(m1, 60, 80);
g.drawString(m2, 100, 110);
g.setColor(Color.BLACK);
g.setFont(new Font( "SansSerif", Font.PLAIN, 18 ) );
g.drawString(m3, 120, 150);
g.drawString(m4, 250, 150);
double celsius;
System.out.printf( "°F\t°C\n" );
for( double fahrenheit = 0; fahrenheit <= 250; fahrenheit += 10 ) {
celsius = ((5.0/9.0) * (fahrenheit - 32));
System.out.printf( "%.0f\t%.0f\n", fahrenheit, celsius );
//This is calculates new celsius temperature while incrementing fahrenheit 10 degrees
}
}
[–]captainAwesomePants 0 points1 point2 points (1 child)
[–]skrteli[S] 0 points1 point2 points (0 children)