babyone
学会思考,学会做人
发贴: 49
积分: 0
|
于 2004-09-22 21:34
呵呵 。。。 好久没上网了,主要是我的显示器坏了 ,现向各位大侠报个到!
import java.awt.*; import java.awt.event.*;
public class FormatMonth implements TextListener,ActionListener extends MouseAdapter { Frame f; Label lb; TextField tf; Button b1,b2,b3; String sInput; public static void main(String[] args){ new FormatMonth(); } public FormatMonth(){ f=new Frame("年月日转换小程序"); lb=new Label("输入简写的年月日如(07/12/2004),(按enter键清除)"); b1=new Button("开始"); b1.setActionCommand("b1"); b1.addActionListener(this); b2=new Button("转换"); b2.setActionCommand("b2"); b2.addActionListener(this); b3=new Button("退出"); b3.setActionCommand("b3"); b3.addActionListener(this); tf=new TextField("",20); tf.addTextListener(this); tf.addActionListener(this); f.add(tf,BorderLayout.NORTH); f.add(b1,BorderLayout.WEST); f.add(b2,BorderLayout.CENTER); f.add(b3,BorderLayout.EAST); f.add(lb,BorderLayout.SOUTH); f.pack(); f.setVisible(true); } public void textValueChanged(TextEvent e){ la.setText(change(tf.getText())); } public void actionPerformed(ActionEvent e){ String cmd=e.getActionCommand(); b1.setEnabled(true); b2.setEnabled(true); b3.setEnabled(true); if(cmd.equals("b1")){ tf.setText(""); b2.setEnabled(false); b3.setEnabled(false); } else if(cmd.equals("b2")){ lb.setText(change(tf.getText())); b1.setEnabled(false); b3.setEnabled(false); } else(cmd.equals("b3")){ System.exit(0); } tf.setText(""); } public String change(sInput){ int x,y; String str1,str2; x=sInput.indexof("/"); str1=sInput.subString(0,x); switch(str1){ case "01":str2="January"; break; case "02":str2="February"; break; case "03":str2="March"; break; case "04":str2="April"; break; case "05":str2="May"; break; case "06":str2="june"; break; case "07":str2="july"; break; case "08":str2="August"; break; case "09":str2="September"; break; case "10":str2="Octorber"; break; case "11":str2="November"; break; case "12":str2="December"; break; default: break; } y=sInput.lastIndexof("/"); str3=sInput.subString(s,y); str4=sInput.subSring(y); return str2+str3+sr4; } }
程序调试的时候显示:
---------------- JDK Debug Build ------------------ Compiling C:\Documents and Settings\user\My Documents\Modelworks\MyProjects\FormatMonth.java Command line: "C:\j2sdk1.4.1\bin\javac.exe" -deprecation -g -classpath C:\DOCUME~1\user\MYDOCU~1\MODELW~1\MYPROJ~1 "C:\Documents and Settings\user\My Documents\Modelworks\MyProjects\FormatMonth.java" The current directory is: C:\Documents and Settings\user\My Documents\Modelworks\MyProjects C:\Documents and Settings\user\My Documents\Modelworks\MyProjects\FormatMonth.java:4: '{' expected public class FormatMonth implements TextListener,ActionListener extends MouseAdapter ^ C:\Documents and Settings\user\My Documents\Modelworks\MyProjects\FormatMonth.java:106: '}' expected } ^ C:\Documents and Settings\user\My Documents\Modelworks\MyProjects\FormatMonth.java:4: FormatMonth should be declared abstract; it does not define actionPerformed(java.awt.event.ActionEvent) in FormatMonth public class FormatMonth implements TextListener,ActionListener extends MouseAdapter ^ 3 errors Finished
小虾我不怎么明白 ,请教!
babyone edited on 2004-09-22 21:36
|