?? form1.java
字號(hào):
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[];//用于計(jì)算英文字母的個(gè)數(shù)
int countofthe;//用于計(jì)算“the”的個(gè)數(shù)
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;
}
//判斷輸入是否為數(shù)字
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("你已經(jīng)輸入了"+l.length +"個(gè)數(shù)");
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 ()+",");
//最后一個(gè)即為最大值
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("你已經(jīng)輸入了0個(gè)數(shù)");
label5.setText("最小值:");
label6.setText("最大值:");
label7.setText("第 個(gè)最小值是:");
label8.setText("第 個(gè)最大值是:");
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個(gè)最值
if(s.equals("0"))
{
Win32.MessageBox (0,"輸入不合法!","警告",0);
edit3.setText("");
edit3.focus();
return;
}
//判斷輸入是否為數(shù)字
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;
}
}
//判斷所給的數(shù)是不是超出了所有數(shù)字的個(gè)數(shù)
if(Integer.parseInt(edit3.getText())>l.length)
{
Win32.MessageBox (0,"給的數(shù)字超過(guò)了數(shù)的個(gè)數(shù)!","警告",0);
edit3.setText("");
edit3.focus();
return;
}
//聲明兩個(gè)double型的數(shù)來(lái)記錄兩個(gè)最值
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();
//輸出結(jié)果
label7.setText("第"+edit3.getText()+"個(gè)最小值是:"+nmin);
label8.setText("第"+edit3.getText()+"個(gè)最大值是:"+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="該文件中(不分大小寫)字母的個(gè)數(shù):\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文件中\(zhòng)"the\"的個(gè)數(shù)為:"+countofthe;
//用對(duì)話框顯示結(jié)果
Win32.MessageBox (0,out,"結(jié)果如下",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())
{
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -