import java.awt.*;//得不到我想要的结果,这程序好像将空格也作为数字了,好像我写的分析器没有起作用;
import java.awt.event.*;
import java.util.*;
public class love
{public static void main(String args[])
{ WindowFrame s=new WindowFrame("计算的窗口");
}}
class WindowFrame extends Frame implements TextListener,ActionListener
{float aver,sum=0;
TextArea a,b;
Button button;
WindowFrame(String s)
{super(s);
a=new TextArea(15,16);
b=new TextArea(15,45);
button=new Button("退出");
add(button);
setLayout(new FlowLayout());
add(a);
add(b);
button.addActionListener(this);
a.addTextListener(this);
setVisible(true);
validate();
setBounds(0,0,345,600);
}
public void actionPerformed(ActionEvent e)
{System.exit(0);}public void textValueChanged(TextEvent e)
{try{String s;
s=a.getText();
StringTokenizer fenxi=new StringTokenizer(s," ,'\n'");
int n=fenxi.countTokens();
String c[]=new String[n];
for(int i=0;i<=n-1;i++)
{String temp=fenxi.nextToken();
c[i]=temp;
}
for(int j=0;j<n;j++)
{sum=sum+Float.parseFloat(c[j]);
aver=sum/n;
b.setText("你输入的数的和sum="+sum+'\n'+"你输入的数的平均数aver="+aver);
}
}catch(NumberFormatException ee){}
}
}
import java.awt.*;//我输入了正确的Email格式,为什么老是提示我不合法呢,是不是我的正则表达式写错了啊!
import java.awt.event.*;
import javax.swing.border.*;
import javax.swing.*;
public class Boy
{public static void main(String args[])
{WindowBox s=new WindowBox();
}}class WindowBox extends Frame implements ActionListener
{Box baseBox,boxv1,boxv2;
String regex="\\w{1,}@\\{1,}\56\\{1,}",s;
TextArea text;
Button button;
TextField a,b,d;WindowBox()
{boxv1=Box.createVerticalBox();
boxv2=Box.createVerticalBox();
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);}});
d=new TextField(10);
a=new TextField(10);
b=new TextField(20);
boxv1.add(new Label("姓名"));
boxv1.add(Box.createVerticalStrut(8));//是Strut,不是Struct
boxv1.add(new Label("职业"));
boxv1.add(Box.createVerticalStrut(8));
boxv1.add(new Label("email"));
boxv2.add(a);
boxv2.add(Box.createVerticalStrut(8));
boxv2.add(b);
boxv2.add(Box.createVerticalStrut(8));
boxv2.add(d);
baseBox=Box.createHorizontalBox();
baseBox.add(boxv1);
baseBox.add(Box.createHorizontalStrut(8));
baseBox.add(boxv2);
text=new TextArea(12,12);
button=new Button("确定");
add(text);
add(button);
button.addActionListener(this);
setLayout(new FlowLayout());
add(baseBox);
setBounds(120,125,500,500);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{ s=d.getText();
if(s.matches(regex))
{text.append("姓名:"+a.getText()+'\n'+"职业:"+b.getText()+'\n'+"email:"+d.getText());}
else {d.setText("你输入了不合法的Email格式");}
}}import java.awt.*;//我输入了正确的Email格式,为什么老是提示我不合法呢,是不是我的正则表达式写错了啊!
import java.awt.event.*;
import javax.swing.border.*;
import javax.swing.*;
public class Boy
{public static void main(String args[])
{WindowBox s=new WindowBox();
}}class WindowBox extends Frame implements ActionListener
{Box baseBox,boxv1,boxv2;
String regex="\\w{1,}@\\{1,}\56\\{1,}",s;
TextArea text;
Button button;
TextField a,b,d;WindowBox()
{boxv1=Box.createVerticalBox();
boxv2=Box.createVerticalBox();
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);}});
d=new TextField(10);
a=new TextField(10);
b=new TextField(20);
boxv1.add(new Label("姓名"));
boxv1.add(Box.createVerticalStrut(8));//是Strut,不是Struct
boxv1.add(new Label("职业"));
boxv1.add(Box.createVerticalStrut(8));
boxv1.add(new Label("email"));
boxv2.add(a);
boxv2.add(Box.createVerticalStrut(8));
boxv2.add(b);
boxv2.add(Box.createVerticalStrut(8));
boxv2.add(d);
baseBox=Box.createHorizontalBox();
baseBox.add(boxv1);
baseBox.add(Box.createHorizontalStrut(8));
baseBox.add(boxv2);
text=new TextArea(12,12);
button=new Button("确定");
add(text);
add(button);
button.addActionListener(this);
setLayout(new FlowLayout());
add(baseBox);
setBounds(120,125,500,500);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{ s=d.getText();
if(s.matches(regex))
{text.append("姓名:"+a.getText()+'\n'+"职业:"+b.getText()+'\n'+"email:"+d.getText());}
else {d.setText("你输入了不合法的Email格式");}
}}import java.awt.*;//我输入了正确的Email格式,为什么老是提示我不合法呢,是不是我的正则表达式写错了啊!
import java.awt.event.*;
import javax.swing.border.*;
import javax.swing.*;
public class Boy
{public static void main(String args[])
{WindowBox s=new WindowBox();
}}class WindowBox extends Frame implements ActionListener
{Box baseBox,boxv1,boxv2;
String regex="\\w{1,}@\\{1,}\56\\{1,}",s;
TextArea text;
Button button;
TextField a,b,d;WindowBox()
{boxv1=Box.createVerticalBox();
boxv2=Box.createVerticalBox();
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);}});
d=new TextField(10);
a=new TextField(10);
b=new TextField(20);
boxv1.add(new Label("姓名"));
boxv1.add(Box.createVerticalStrut(8));//是Strut,不是Struct
boxv1.add(new Label("职业"));
boxv1.add(Box.createVerticalStrut(8));
boxv1.add(new Label("email"));
boxv2.add(a);
boxv2.add(Box.createVerticalStrut(8));
boxv2.add(b);
boxv2.add(Box.createVerticalStrut(8));
boxv2.add(d);
baseBox=Box.createHorizontalBox();
baseBox.add(boxv1);
baseBox.add(Box.createHorizontalStrut(8));
baseBox.add(boxv2);
text=new TextArea(12,12);
button=new Button("确定");
add(text);
add(button);
button.addActionListener(this);
setLayout(new FlowLayout());
add(baseBox);
setBounds(120,125,500,500);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{ s=d.getText();
if(s.matches(regex))
{text.append("姓名:"+a.getText()+'\n'+"职业:"+b.getText()+'\n'+"email:"+d.getText());}
else {d.setText("你输入了不合法的Email格式");}
}}
import java.awt.*;//问题程序,不能将文本框中的内容+入按钮上,为什么?
import java.awt.event.*;
public class hua
{public static void main(String args[])
{new WindowPanel();
}}
class MyPanel extends Panel implements ActionListener
{TextField text;
Button button;
MyPanel()
{text=new TextField(8);
button=new Button("按钮");
add(text);
add(button);
setBounds(0,0,200,200);
validate();
}
public void actionPerformed(ActionEvent e)
{String s;
s=text.getText();
button.setLabel(s);
}}
class WindowPanel extends Frame
{MyPanel p1,p2;
WindowPanel()
{p1=new MyPanel();
p2=new MyPanel();
Button d=new Button("退出");
d.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent e)
{System.exit(0);}});
add(d,BorderLayout.NORTH);
add(p1,BorderLayout.EAST);
add(p2,BorderLayout.WEST);
setVisible(true);
validate();
setBounds(0,0,400,400);
}}