关于paint方法里不能输出变量的问题
import java.awt.Graphics ;import javax.swing.JApplet ;
import javax.swing.JOptionPane;
public class Float2 extends JApplet{
public void init()
{
String firstNumber;
String secondNumber;
String thirdNumber;
float first;
float second;
float third;
float sum,average,mul,max,min;
firstNumber = JOptionPane.showInputDialog("Enter first number");
secondNumber = JOptionPane.showInputDialog("Enter second number");
thirdNumber = JOptionPane.showInputDialog("Enter third number");
first = Float.parseFloat(firstNumber);
second = Float.parseFloat(secondNumber);
third = Float.parseFloat(thirdNumber);
sum = first + second + third;
average = sum/3;
if((second>first)&&(second>third)) max = second ;
else if((second>first)&&(second<third)) max = third ;
else max = first ;
if((second<first)&&(second<third)) min = second ;
else if((second<first)&&(second>third)) min = third ;
else min = first ;
mul = first * second * third ;
String str = new String("max = " + max + "\nmin = " + min + "\naverage = "+average + "\nmul = "+ mul);
//String title = "VC++.NET";
//JOptionPane.showMessageDialog(null,str,title,JOptionPane.PLAIN_MESSAGE);
}
public void paint(Graphics g)
{
super.paint(g);
g.draw3DRect(15,10,270,60,true);
g.drawString(str,25,25); ////编译器致使 str 出错, 我改个 “ abc” 就可以运行输出
System.exit(0);
}
}