| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 589 人关注过本帖
标题:可以帮我看一个小applet吗?
只看楼主 加入收藏
想你的天空
Rank: 2
等 级:新手上路
威 望:5
帖 子:610
专家分:0
注 册:2004-12-30
收藏
 问题点数:0 回复次数:3 
可以帮我看一个小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 
2005-09-19 09:34
kuixingzai
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2005-5-16
收藏
得分:0 
将最后的显示对话框语句改为:
JOptionPane.showMessageDialog(null,"max = " + max+",\nmin = "+ min +",\naverage = "+average+ ",\nmul = "+ mul,"VC++.NET",JOptionPane.PLAIN_MESSAGE);
还有类名不能用关键字Float,必须要用非关键字.

菜鸟飞,菜鸟飞,菜鸟高高飞!
2005-09-19 14:09
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
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);

  }
}

自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-09-19 14:13
想你的天空
Rank: 2
等 级:新手上路
威 望:5
帖 子:610
专家分:0
注 册:2004-12-30
收藏
得分:0 
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打开,还是原来的那个

2005-09-20 09:10
快速回复:可以帮我看一个小applet吗?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025897 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved