⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.java

📁 是算术表达的计算
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.html.*;
import java .io .* ;
import java .util .* ;
/**
 * This class can take a variable number of parameters on the command
 * line. Program execution begins with the main() method. The class
 * constructor is not invoked unless an object of type 'Form1' is
 * created in the main() method.
 */
public class Form1 extends Form
{
	LinkList l=new LinkList();
	int count[];//用于计算英文字母的个数
	int countofthe;//用于计算“the”的个数
	boolean signoft=false,signofth=false,signofthe=false,betruesignofthe=false;
	public Form1()
	{
		// Required for Visual J++ Form Designer support
		initForm();		

		// TODO: Add any constructor code after initForm call
	}

	/**
	 * Form1 overrides dispose so it can clean up the
	 * component list.
	 */
	public void dispose()
	{
		super.dispose();
		components.dispose();
	}

	private void button1_click(Object source, Event e)
	{
		//判断输入是否合法
		String s;
		s=edit1.getText();
		//判断输入是否为空
		if(s.equals(""))
		{
			Win32.MessageBox (0,"输入不能为空!","警告",0);
			edit1.setText("");
			edit1.focus();
			return;
		}
		//判断输入是否为数字		
		for(int i=0;i<s.length();i++)
		{
			if(((int)s.charAt(i)>=(int)'0' && (int)s.charAt(i)<=(int)'9')||s.charAt(i)=='.')
			{
				continue;
			}
			else
			{
				Win32.MessageBox (0,"输入不合法!","警告",0);
				edit1.setText("");
				edit1.focus();
				return;
			}
		}
		l.insertinorder(Double.valueOf(edit1.getText()).doubleValue());
		label2.setText("你已经输入了"+l.length +"个数");
		edit1.setText("");
		edit1.focus();
		button2.setEnabled(true);
		button3.setEnabled(true);
	}

	private void button2_click(Object source, Event e)
	{
		edit2.setText("");
		Node currentnode=l.firstnode;
		//先输出最小值
		label5.setText("最小值:"+currentnode.getData());
		while(currentnode!=null)
		{
			edit2.setText(edit2.getText()+currentnode.getData ()+",");			
			//最后一个即为最大值
			if(currentnode.next==null)
				label6.setText("最大值:"+currentnode.getData());
			currentnode=currentnode.next;
		}		
		button4.setEnabled(true);
	}

	private void button3_click(Object source, Event e)
	{
		l=new LinkList();
		edit2.setText("");
		edit3.setText("");
		label2.setText("你已经输入了0个数");
		label5.setText("最小值:");
		label6.setText("最大值:");
		label7.setText("第  个最小值是:");
		label8.setText("第  个最大值是:");
		button2.setEnabled(false);
		button3.setEnabled(false);
		button4.setEnabled(false);
	}

	private void button4_click(Object source, Event e)
	{
		//判断输入是否合法
		String s;
		s=edit3.getText();
		//判断输入是否为空
		if(s.equals(""))
		{
			Win32.MessageBox (0,"输入不能为空!","警告",0);
			edit3.setText("");
			edit3.focus();
			return;
		}
		//不能为第0个最值
		if(s.equals("0"))
		{
			Win32.MessageBox (0,"输入不合法!","警告",0);
			edit3.setText("");
			edit3.focus();
			return;
		}		
		//判断输入是否为数字
		for(int i=0;i<s.length();i++)
		{
			if((int)s.charAt(i)>=(int)'0' && (int)s.charAt(i)<=(int)'9')
			{
				continue;
			}
			else
			{
				Win32.MessageBox (0,"输入不合法!","警告",0);
				edit3.setText("");
				edit3.focus();
				return;
			}
		}
		
		//判断所给的数是不是超出了所有数字的个数
		if(Integer.parseInt(edit3.getText())>l.length)
		{
			Win32.MessageBox (0,"给的数字超过了数的个数!","警告",0);
			edit3.setText("");
			edit3.focus();
			return;
		}
		//声明两个double型的数来记录两个最值
		double nmin,nmax;
		//得到第n最小的值
		Node currentnode=l.firstnode;
		for(int j=1;j<Integer.parseInt(edit3.getText());j++)
			currentnode=currentnode.next;
		nmin=currentnode.getData();
		//得到第n最大的值
		currentnode=l.firstnode;
		for(int j=0;j<l.length-Integer.parseInt(edit3.getText());j++)
			currentnode=currentnode.next;
		nmax=currentnode.getData();
		//输出结果
		label7.setText("第"+edit3.getText()+"个最小值是:"+nmin);
		label8.setText("第"+edit3.getText()+"个最大值是:"+nmax);
	}

	private void button5_click(Object source, Event e)
	{		
		OpenFileDialog fOpenDlg = new OpenFileDialog ();
		fOpenDlg.setFilter("Text files (*.txt)|*.txt|All files (*.*)|*.*");
		fOpenDlg.setCheckFileExists(true);
		fOpenDlg.setCheckPathExists(true);
		fOpenDlg.setReadOnlyChecked(true);
		fOpenDlg.setFileName ("*.txt");
		if (fOpenDlg.showDialog() == DialogResult.OK)
		{
           edit4.setText(fOpenDlg.getFileName());
		   try
		   {
				File file=new File (fOpenDlg.getFileName());
				FileInputStream fin=new FileInputStream (file);
				count=new int[26];
				countofthe=0;
				int c=fin.read(),beforec=c;								
				for(int i=0;i<file.length();i++)
				{					
					if((char)c=='T' || (char)c=='t')
					{
						if(i==0 || (!(beforec>=(int)'A' && beforec<=(int)'Z') && !(beforec>=(int)'a' && beforec<=(int)'z')))						
							signoft=true;
					}
					else if(c==(int)'H' || c==(int)'h')
					{
						if(signoft)
							signofth=true;
					}
					else if(c==(int)'E' || c==(int)'e')
					{
						if(signofth)
							signofthe=true;
					}
					else if(!(c>=(int)'A' && c<=(int)'Z') && !(c>=(int)'a' && c<=(int)'z'))
					{
						if(signofthe)
						{
							countofthe++;
							signoft=false;
							signofth=false;
							signofthe=false;
						}
						else
						{
							signoft=false;
							signofth=false;
							signofthe=false;
						}
					}
					else
					{
						signoft=false;
						signofth=false;
						signofthe=false;
					}				
					
					if(c>=(int)'A' && c<=(int)'Z')					
						count[c-(int)'A']++;				
					if(c>=(int)'a' && c<=(int)'z')					
						count[c-(int)'a']++;					
					beforec=c;
					if(i<file.length()-1)
						c=fin.read();
				}
				//生成要输出的字符串
				String out="该文件中(不分大小写)字母的个数:\r\n";
				for(int j=(int)'A';j<=(int)'Z';j++)
				{
					out=out+(char)j+"-"+count[j-(int)'A']+"  ";
					if((char)j=='I' || (char)j=='R')
						out+="\r\n";
				}
				out=out+"\r\n文件中\"the\"的个数为:"+countofthe;
				//用对话框显示结果
				Win32.MessageBox (0,out,"结果如下",0);
		   }
		   catch(IOException w){};
		}

	}

	private void button6_click(Object source, Event e)
	{
		Stack n1=new Stack (),n2=new Stack (),n3=new Stack (), n4=new Stack ();   
		String s,str,st;
		StringBuffer sb=new StringBuffer("0");
		s=edit5.getText();
		//判断输入的合法性
		if(s.equals(""))
		{
			Win32.MessageBox (0,"输入不能为空!","警告",0);
			edit5.setText("");
			edit5.focus();
			return;
		}
		for(int i=0;i<s.length();i++)
		{
			char cha=s.charAt (i);			
			if(((int)cha>=(int)'0'&&(int)cha<=(int)'9')||cha=='.'||cha=='+'||cha=='-'||cha=='*'||cha=='/'||cha=='%'||cha=='('||cha==')')
				continue;
			else
			{
				Win32.MessageBox (0,"输入不合法!","警告",0);
				edit5.setText("");
				edit5.focus();
				return;
			}			 
		 }
		for(int i=0;i<s.length();i++)
		{
			char ch=s.charAt(i);	  
			if(ch!=')'&& i==s.length()-1) 
			{
				sb.append(ch); n1.push(sb.toString());
			}
			else if(((int)ch>=(int)('0')&&(int)ch<=(int)('9'))||ch=='.')
				sb.append(ch);
			else if(ch==')')
			{ 
				n1.push(sb.toString());
				sb=new StringBuffer ("0");
				n3.push(n1.pop());
				String s1=n1.pop().toString();
				while(!s1.equals("("))
				{
					if(s1.equals("+")||s1.equals("-"))
					{   
						n4.push(s1);
						n3.push(n1.pop());
					}
					else
					{
						double d,d1=Double.valueOf(n1.pop().toString()).doubleValue(),d2=Double.valueOf(n3.pop().toString()).doubleValue();
						if(s1.equals("*")) 
						{
							d=d1*d2;n3.push(Double.toString(d));
						}
						if(s1.equals("/"))
						{
							d=d1/d2;n3.push(Double.toString(d));
						}
						if(s1.equals("%"))
							n3.push(Integer.toString((int)d1%(int)d2));
					}
					s1=n1.pop().toString();
				}
				while(!n4.empty())
				{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -