String s = "3.1415926";
int i = s.indexOf(".");
if(i<0){
//有小数点
}
int i = s.indexOf(".");
if(i<0){
//有小数点
}
解决方案 »
- j2me如何关闭自动打开的网页?
- eclipse啟動遇到如下問題,幫忙分析下都有哪些原因
- 关于代码注释 高手来帮忙下 我在线等 帮忙把代码注释一下 我是新手
- 关于时间片与线程问题,请解答...
- 从文本文件导入数据到数据库的问题
- 怎样去掉字符串里ip地址!
- SOS
- 在WEB中,如何在APPLET中调用另一个APPLET
- 在linux中为什么无论使用那种浏览器都无法显示applet中的汉字???
- 关于java的事件问题,如何在程序中使一个button被click,从而引发这个button的事件处理代码????
- 大家帮我看看怎么会抛异常能应该不会呀!
- <调查>想问问大家一般学习java除了csdn,sun,ibm.developerworks,apache都喜欢到什么网站?
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Calculater_GridLayout extends Applet implements ActionListener
{
TextField tf=new TextField(12);
Panel p1=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();
Button bt[];
String names[]={"1","2","3","+","4","5","6","-","7","8","9","*","0",".","=","/"};
Button b_c=new Button(" Clear ");
Button b_e=new Button(" Exit ");//
Color c=new Color(251,197,103 );
float a,b,result;
int type;
boolean toggle=true;
public void init()
{
p1.add(tf);
// p2.setLayout(new GridLayout(4,4,5,5));
p2.setLayout(new GridLayout(4,4,5,5));
bt=new Button[names.length];
for(int i=0;i<names.length;i++)
{
bt[i]=new Button(names[i]);
bt[i].addActionListener(this);
p2.add(bt[i]);
}
//setLayout(new GridLayout(3,1,5,5));
p3.add(b_c);
//p3.add(b_e);
add(p1);
add(p2);
add(p3);//
this.setBackground(c);
b_c.addActionListener(this);
b_e.addActionListener(this); }
public void actionPerformed(ActionEvent e)
{
for(int i=0;i<10;i++)
if(e.getActionCommand().equals(String.valueOf(i)))
if(toggle==false)
{tf.setText(String.valueOf(i));toggle=true;}
else
tf.setText(tf.getText()+i);
if(e.getActionCommand().equals("."))
if(toggle==false)
{tf.setText(".");toggle=true;}
else
tf.setText(tf.getText()+".");
if(e.getActionCommand().equals("+")||e.getActionCommand().equals("-")||e.getActionCommand().equals("*")||e.getActionCommand().equals("/"))
{
a=(Float.valueOf(tf.getText())).floatValue();
toggle=false;
//tf.setText("");
if(e.getActionCommand().equals("+"))
type=1;
if(e.getActionCommand().equals("-"))
type=2;
if(e.getActionCommand().equals("*"))
type=3;
if(e.getActionCommand().equals("/"))
type=4;
}
if(e.getActionCommand().equals("="))
{
//tf.setText("");
b=(Float.valueOf(tf.getText())).floatValue();
tf.setText("");
if(type==1)
result=a+b;
if(type==2)
result=a-b;
if(type==3)
result=a*b;
if(type==4)
result=a/b;
tf.setText(String.valueOf(result));
repaint();
type=0;/**/
toggle=false;
}
if(e.getSource()==b_c)
//if(e.getSourse(" Clear "))
tf.setText("");
if(e.getSource()==b_e)
//if(e.getActionCommand().equals(" Exit "))
System.exit(0);
}
}