可以帮我看一个小applet吗?
import java.awt.Graphics ;import javax.swing.JApplet ;
import javax.swing.JOptionPane;
public class Float extends JApplet{
public void paint(Graphics g)
{
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");
// number1 = Integer.parseInt(firstNumber);//把String转换成int
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 ;
JOptionPane.showMessageDialog(null,"max = " + max ,"\nmin = "+ min "\naverage = "+average "\nmul = "+ mul,"VC++.NET",JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
}
//firstNumber = JOptionPane.showInputDialog("Enter first number"); 编译器指示这里出错
// number1 = Integer.parseInt(firstNumber);//把String转换成int //这是书上的对的例子
[此贴子已经被作者于2005-9-19 9:45:08编辑过]
搜索更多相关的解决方案:
applet
----------------解决方案--------------------------------------------------------
将最后的显示对话框语句改为:
JOptionPane.showMessageDialog(null,"max = " + max+",\nmin = "+ min +",\naverage = "+average+ ",\nmul = "+ mul,"VC++.NET",JOptionPane.PLAIN_MESSAGE);
还有类名不能用关键字Float,必须要用非关键字.
----------------解决方案--------------------------------------------------------
import java.awt.Graphics;
import javax.swing.JApplet;
import javax.swing.JOptionPane;
public class Float extends JApplet
{
private boolean isDigit(char c)
{
if(c>'9' || c<'0')
return false;
return true;
}
private boolean isFloat(String s)
{
if(s.equals(""))
return false;
int countOfDot = 0;
char [] cArray = s.toCharArray();
for(int i = 0; i<s.length(); i++)
{
if(cArray[i] == '.')
{
countOfDot++;
if(countOfDot>1)
return false;
}
else if(isDigit(cArray[i]) == false)
return false;
}
return true;
}
public void start()
{
String firstNumber = null;
String secondNumber = null;
String thirdNumber = null;
float first;
float second;
float third;
float sum,average,mul,max,min;
do
{
firstNumber = JOptionPane.showInputDialog("Enter first number");
}while(isFloat(firstNumber) == false);
do
{
secondNumber = JOptionPane.showInputDialog("Enter second number");
}while(isFloat(secondNumber) == false);
do
{
thirdNumber = JOptionPane.showInputDialog("Enter third number");
}while(isFloat(thirdNumber) == false);
first = java.lang.Float.parseFloat(firstNumber);
second = java.lang.Float.parseFloat(secondNumber);
third = java.lang.Float.parseFloat(thirdNumber);
sum = first + second + third;
average = sum/3;
if((second>first)&&(second>third))
max = second ;
else if(third>first)
max = third ;
else
max = first ;
if((second<first)&&(second<third))
min = second ;
else if(third<first)
min = third;
else
min = first;
mul = first * second * third ;
String msg = new String("max = " + max + "\nmin = " + min + "\naverage = "+average + "\nmul = "+ mul);
String title = "VC++.NET";
JOptionPane.showMessageDialog(null, msg, title, JOptionPane.PLAIN_MESSAGE);
}
}
----------------解决方案--------------------------------------------------------
import java.awt.Graphics ;
import javax.swing.JApplet ;
import javax.swing.JOptionPane;
public class Float1 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);
System.exit(0);
}
}
//这样行, 不过修改后的用html打开,还是原来的那个
----------------解决方案--------------------------------------------------------