??xml version="1.0" encoding="utf-8" standalone="yes"?>久久综合免费视频影院,中文字幕一区二区三区四区,2014亚洲精品http://www.aygfsteel.com/lemon/zh-cnWed, 18 Jun 2025 15:58:41 GMTWed, 18 Jun 2025 15:58:41 GMT60一个简单日记本的源E序,功能q不完全,请高人指?/title><link>http://www.aygfsteel.com/lemon/archive/2005/12/25/25371.html</link><dc:creator>lemon</dc:creator><author>lemon</author><pubDate>Sun, 25 Dec 2005 07:35:00 GMT</pubDate><guid>http://www.aygfsteel.com/lemon/archive/2005/12/25/25371.html</guid><wfw:comment>http://www.aygfsteel.com/lemon/comments/25371.html</wfw:comment><comments>http://www.aygfsteel.com/lemon/archive/2005/12/25/25371.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/lemon/comments/commentRss/25371.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/lemon/services/trackbacks/25371.html</trackback:ping><description><![CDATA[<P>import java.awt.*; <BR>import java.awt.event.*; <BR>import javax.swing.*; <BR>import java.util.*; <BR>import java.text.*; <BR>import java.io.*; <BR>public class Note extends Frame { </P> <P>private MenuBar mb; <BR>private Menu mset_param ,mhelp; <BR>private MenuItem mibc ,miSound; <BR>private MenuItem miabout; <BR>//~省的背景颜?<BR>private static Color backgroundcolor = Color.GRAY; </P> <P>//funtction of the button on plcb is chose year andmonth <BR>//and set alarm colock and remind booking <BR>private JCheckBox remindBook ,alarmColock; <BR>private JComboBox cbyears ,cbmonths; <BR>private JPanel plcb; <BR>//日历按钮 <BR>private JPanel plbt; <BR>private JButton button[]; <BR>//add vector to contain button[],so that find it <BR>private Vector v; <BR>//save the year and month <BR>private String choseyear ,chosemonth; <BR>private int choseyearint ,chosemonthint; <BR>private boolean changed = false; <BR>private boolean fileExist = false;//the application first run to find file <BR>private static boolean needSound; </P> <P>//add text to write down what to do in the future <BR>private TextArea tanote; <BR>private JPanel plta; </P> <P>//默认的年?<BR>private final static String years[]={ <BR>"1995" ,"1996" ,"1997" ,"1998" ,"1999" ,"2000" , <BR>"2001" ,"2002" ,"2003" ,"2004" ,"2005" ,"2006" , <BR>"2007" ,"2008" ,"2009" ,"2010" ,"2011" ,"2012" , <BR>"2013" ,"2014" ,"2015" ,"2016" ,"2017" ,"2018" , <BR>"2019" ,"2020" <BR>}; </P> <P>private static final String months[] = { <BR>"January" ,"February" ,"March" ,"April" ,"May" ,"June" ,"July" ,"August" , <BR>"September" ,"October" ,"November" ,"December" <BR>}; </P> <P>private final static int dom[] = { <BR>31 ,28 ,31 ,30 ,31 ,30 ,31 ,31 ,30 ,31 ,30 ,31 <BR>}; </P> <P>//save the first day of the month to use <BR>private int start; <BR>//save the button who is entered <BR>private int btnIndex; </P> <P>public Note() { <BR>mb = new MenuBar(); <BR>mset_param = new Menu("讄"); <BR>mhelp = new Menu("帮助"); <BR>mibc = new MenuItem("背景"); <BR>miSound = new MenuItem("声音"); <BR>miabout = new MenuItem("关于..."); </P> <P>mset_param.add(mibc); <BR>mset_param.addSeparator(); <BR>mset_param.add(miSound); <BR>mhelp.add(miabout); <BR>setMenuBar(mb); <BR>mb.add(mset_param); <BR>mb.setHelpMenu(mhelp); </P> <P>MListener ml = new MListener(); <BR>mibc.addActionListener(ml); <BR>miabout.addActionListener(ml); <BR>miSound.addActionListener(ml); </P> <P>cbyears = new JComboBox(); <BR>cbmonths = new JComboBox(); <BR>plcb = new JPanel(); <BR>plcb.setLayout(new FlowLayout()); <BR>JLabel lyears = new JLabel("q䆾:"); <BR>JLabel lmonths = new JLabel("月䆾:"); <BR>plcb.add(lyears); <BR>plcb.add(cbyears); <BR>plcb.add(lmonths); <BR>plcb.add(cbmonths); <BR>remindBook = new JCheckBox("预约提示",true); <BR>alarmColock = new JCheckBox("闚w"); <BR>// Dimension d = new Dimension(); <BR>// remindBook.setSize(d); <BR>// remindBook.getSize(d); <BR>// System.out.println("W:"+d.getWidth()+" H:"+d.getHeight()); <BR>plcb.add(remindBook); <BR>plcb.add(alarmColock); <BR>remindBook.addActionListener(new RemindListener()); <BR>alarmColock.addActionListener(new RemindListener()); <BR>add(plcb ,BorderLayout.NORTH); </P> <P>//add calendar <BR>getCalendar(); </P> <P>plbt = new JPanel(); <BR>plbt.setBackground(Color.BLUE); <BR>plbt.setLayout(new GridLayout(7 ,7)); </P> <P>plbt.add(new JLabel(" 星期?)); <BR>plbt.add(new JLabel(" 星期一")); <BR>plbt.add(new JLabel(" 星期?)); <BR>plbt.add(new JLabel(" 星期?)); <BR>plbt.add(new JLabel(" 星期?)); <BR>plbt.add(new JLabel(" 星期?)); <BR>plbt.add(new JLabel(" 星期?)); </P> <P>//add calendar button to frame <BR>//add button to vector; <BR>v = new Vector(); <BR>button = new JButton[42]; <BR>for(int i=0;i<41;i++){ <BR>button[i] = new JButton(); <BR>plbt.add(button[i]); <BR>button[i].addActionListener(new ButtonListener()); <BR>v.add(button[i]); <BR>} </P> <P>button[41] = new JButton(); <BR>plbt.add(button[41]); <BR>button[41].setText("保存"); <BR>button[41].addActionListener(new SaveListener()); <BR>add(plbt ,BorderLayout.CENTER); </P> <P>//add note book <BR>// plta = new JPanel(); <BR>tanote = new TextArea(5 ,80); <BR>// tanote.addTextListener(new tanoteTextListener()); <BR>// tanote.setColumns(80); <BR>// plta.add(tanote); <BR>// tanote.SCROLLBARS_VERTICAL_ONLY; <BR>add(tanote ,BorderLayout.SOUTH); </P> <P>/* <BR>//add date to button <BR>GregorianCalendar calendar = new GregorianCalendar(choseyearint ,chosemonthint ,1); <BR>int start = calendar.get(Calendar.DAY_OF_WEEK)-1; <BR>int daysInMonth = dom[chosemonthint]; <BR>if(calendar.isLeapYear(choseyearint)&&chosemonthint == 1){ <BR>++daysInMonth; <BR>} <BR>for(int i =0;i<daysInMonth;i++){ <BR>button[start+i].setText(" "+(i+1)+" "); <BR>} <BR>*/ <BR>//add the default year and month to JComboBox <BR>for(int i= 0;i<=25;i++){ <BR>cbyears.addItem(years[i]); <BR>} <BR>for(int i=0;i<12;i++){ <BR>cbmonths.addItem(months[i]); <BR>} <BR>/* <BR>//add current year and month <BR>cbyears.setSelectedIndex(choseyearint-1995); <BR>cbmonths.setSelectedIndex(chosemonthint); <BR>*/ </P> <P>//show date to calendar <BR>showDate(); <BR>//open file add to note <BR>Calendar now = new GregorianCalendar(); <BR>int num = start + now.get(Calendar.DAY_OF_MONTH)-1; <BR>btnIndex = num; <BR>readFile(num); <BR>fileSound(); </P> <P>//add threadcb to listen jcombobox state <BR>new ThreadCB().start(); </P> <P>//listen the JComboBox of years and months <BR>cbyears.addItemListener(new cbyearsItemListener()); <BR>cbmonths.addItemListener(new cbmonthsItemListener()); </P> <P>addWindowListener(new WindowAdapter() { <BR>public void windowClosing(WindowEvent e) { <BR>dispose(); <BR>System.exit(0); <BR>} <BR>}); <BR>} </P> <P>/** <BR>*add menu listener to know the menu what do want to do <BR>*/ <BR>class MListener implements ActionListener{ <BR>public void actionPerformed(ActionEvent e){ <BR>MenuItem i = (MenuItem)e.getSource(); <BR>if(i.equals(miabout)){ <BR>JOptionPane.showMessageDialog(null ,"日历C本程序V1.0","关于..." ,JOptionPane.INFORMATION_MESSAGE); <BR>} <BR>else if(i.equals(mibc)){ <BR>//backgroundcolor = Color.BLACK; <BR>backgroundcolor = JColorChooser.showDialog(null ,"选择颜色..." ,getBackground()); <BR>setBackground(backgroundcolor); <BR>plbt.setBackground(backgroundcolor); <BR>// System.out.println(choseyear); <BR>//// <BR>} <BR>else{ <BR>JOptionPane.showMessageDialog(null ,"I am sorry ,this function is not complation" ,"Sorry" ,JOptionPane.INFORMATION_MESSAGE); <BR>} <BR>} <BR>} </P> <P>/** <BR>*add the year JComboBox listener to know what active <BR>*/ <BR>class cbyearsItemListener implements ItemListener{ <BR>public void itemStateChanged(ItemEvent e){ <BR>// System.out.println(e.paramString()); <BR>// System.out.println(e.getStateChange()); <BR>// System.out.println(e.getItem().toString()); <BR>// if(e.getSource().equals("1997")){ <BR>// System.out.println("1997 is chosed"); <BR>// } <BR>// else{ <BR>// System.out.println("the System is not chose 1997"); <BR>// } <BR>// choseyear = e.getItem().toString(); <BR>changed = true; <BR>// showDate(); <BR>// cbmonths.setSelectedIndex(5); <BR>} <BR>} </P> <P>/** <BR>*add the month JComboBox listener to know what active <BR>*/ <BR>class cbmonthsItemListener implements ItemListener{ <BR>public void itemStateChanged(ItemEvent e){ <BR>// System.out.println(choseyear); <BR>// chosemonth = e.getItem().toString(); <BR>changed = true; </P> <P>// chosemonthint = Integer.parseInt(chosemonth); <BR>// System.out.println(chosemonthint); <BR>// showDate(); <BR>} <BR>} </P> <P>public static void main(String args[]) { <BR>System.out.println("Starting Note..."); <BR>Note mainFrame = new Note(); <BR>mainFrame.setSize(600, 400); <BR>mainFrame.setTitle("日历C?); <BR>mainFrame.setBackground(backgroundcolor); <BR>mainFrame.setVisible(true); <BR>for(int i=0;i<10;i++){ <BR>System.out.print("\007"); <BR>} <BR>// Thread dd = new ThreadCB(); <BR>// dd.start(); <BR>// mainFrame.paintCalendar(); <BR>} </P> <P>protected void getCalendar(){ <BR>Calendar now = new GregorianCalendar(); <BR>// System.out.println("year :"+now.get(Calendar.YEAR)); <BR>// System.out.println("month:"+now.get(Calendar.MONTH)); <BR>// int y = now.get(Calendar.YEAR); <BR>// choseyear = Integer.toString(y); <BR>// int m = now.get(Calendar.MONTH); <BR>// chosemonth = Integer.toString(m+1); <BR>choseyearint = now.get(Calendar.YEAR); <BR>chosemonthint = now.get(Calendar.MONTH); <BR>// System.out.println("y "+choseyear+"::"+chosemonth); <BR>} </P> <P>/** <BR>*show date to calendar <BR>*/ <BR>protected void showDate(){ <BR>GregorianCalendar calendar = new GregorianCalendar(choseyearint ,chosemonthint ,1); <BR>start = calendar.get(Calendar.DAY_OF_WEEK)-1; <BR>int daysInMonth = dom[chosemonthint]; <BR>if(calendar.isLeapYear(choseyearint)&&chosemonthint == 1){ <BR>++daysInMonth; <BR>} <BR>for(int i =0;i<daysInMonth;i++){ <BR>button[start+i].setForeground(Color.BLACK); <BR>button[start+i].setText(" "+(i+1)+" "); <BR>} <BR>//set current day <BR>int nowDay = start + calendar.get(Calendar.DAY_OF_MONTH); <BR>button[nowDay+1].setForeground(Color.RED); <BR>//add current year and month <BR>cbyears.setSelectedIndex(choseyearint-1995); <BR>cbmonths.setSelectedIndex(chosemonthint); <BR>} </P> <P>//listen the buttons active <BR>class ButtonListener implements ActionListener{ <BR>public void actionPerformed(ActionEvent e){ <BR>Object obj = e.getSource(); <BR>// System.out.println("haha"+e.getSource()); <BR>btnIndex = v.indexOf(obj); <BR>readFile(btnIndex); <BR>/* switch(v.indexOf(obj)){ <BR>case 1: <BR>System.out.println("i am button1"); <BR>break; <BR>case 2: <BR>// System.out.println("I am button2"); <BR>readFile(2); <BR>break; <BR>case 41: <BR>System.out.println(tanote.getText()); <BR>break; <BR>default: <BR>System.out.println("I do not know who am I"); <BR>break; <BR>} <BR>*/ } <BR>} </P> <P>/** <BR>*create a thread to listen the year or month′s state <BR>*/ <BR>class ThreadCB extends Thread{ <BR>public void run(){ <BR>while(true){ <BR>if(changed){ <BR>changed = false; <BR>choseyearint = cbyears.getSelectedIndex()+1995; <BR>chosemonthint = cbmonths.getSelectedIndex(); <BR>//System.out.println("y:"+choseyearint+":M:"+chosemonthint); <BR>for(int i=0;i<40;i++){ <BR>button[i].setText(""); <BR>} <BR>showDate(); <BR>} <BR>try{ <BR>sleep(200); <BR>} <BR>catch(InterruptedException e){ <BR>System.err.println(e); <BR>} <BR>} <BR>} <BR>} </P> <P>/** <BR>* add note book listener to know the textarea active <BR>*/ <BR>/* <BR>class tanoteTextListener implements TextListener{ <BR>public void textValueChanged(TextEvent e){ <BR>//System.out.println(e.getSource()); <BR>} <BR>}*/ </P> <P>/** <BR>*check file to know the file is exist <BR>* if exist,read it to the note book <BR>*/ <BR>protected void readFile(int bt){ <BR>int y = cbyears.getSelectedIndex()+1995;//real year <BR>int m = cbmonths.getSelectedIndex()+1;//real month <BR>String fileName = Integer.toString(y) + Integer.toString(m)+"button"+Integer.toString(bt); <BR>// System.out.println("I am dudu"); <BR>// System.out.println(fileName); <BR>// String fileName = "testDay.java"; </P> <P>File file = new File(fileName); <BR>BufferedReader is; <BR>String line; <BR>StringBuffer sb = new StringBuffer(); </P> <P>tanote.setText(""); <BR>if(file.exists()){ <BR>try{ <BR>is = new BufferedReader(new FileReader(fileName)); </P> <P>while((line = is.readLine())!= null){ <BR>sb.append(line); <BR>sb.append("\n"); <BR>} <BR>is.close(); <BR>} <BR>catch(IOException e){ <BR>System.err.println(e); <BR>System.exit(0); <BR>} <BR>tanote.setText(sb.toString()); <BR>fileExist = true; <BR>} <BR>else{ <BR>System.out.println(fileName+" is not exists"); <BR>} </P> <P>} </P> <P>/** <BR>*sound <BR>*/ <BR>protected void fileSound(){ <BR>if(remindBook.isSelected()){ <BR>if(fileExist){ <BR>/* for(int i=0;i<10;i++){ <BR>System.out.println("\007"); <BR>} <BR>*/ <BR>needSound = true; <BR>} <BR>} <BR>} </P> <P>/** <BR>*listen the save button active <BR>*/ <BR>class SaveListener implements ActionListener{ <BR>public void actionPerformed(ActionEvent e){ <BR>int bt = btnIndex; <BR>int y = cbyears.getSelectedIndex()+1995;//real year <BR>int m = cbmonths.getSelectedIndex()+1;//real month <BR>String fileName = Integer.toString(y) + Integer.toString(m)+"button"+Integer.toString(bt); </P> <P>try{ <BR>BufferedWriter bw = new BufferedWriter(new FileWriter(fileName)); <BR>//int row = tanote.getRows(); <BR>//System.out.println("rows:"+row); <BR>String s = tanote.getText(); <BR>System.out.println("length:"+s.length()); <BR>bw.write(s); </P> <P>bw.close(); <BR>} <BR>catch(IOException ev){ <BR>System.err.println(ev); <BR>System.exit(0); <BR>} <BR>} <BR>} </P> <P>// <BR>class RemindListener implements ActionListener{ <BR>public void actionPerformed(ActionEvent ae){ <BR>Object obj = ae.getSource(); <BR>if(obj.equals(remindBook)){ <BR>if(remindBook.isSelected()){ <BR>System.out.println("I am selected"); <BR>} <BR>else{ <BR>System.out.println("I am not selected"); <BR>} <BR>} <BR>else{ <BR>if(alarmColock.isSelected()){ <BR>// System.out.println("I am selected"); <BR>final JFrame jf = new JFrame("讄旉"); <BR>jf.setSize(300,100); <BR>jf.setLocation(200 ,200); <BR>jf.setVisible(true); <BR>// Font f = new Font( ,Font.BOLD ,20); <BR>JLabel jl = new JLabel("逗你?); <BR>String name=jl.getFont().getName(); <BR>// System.out.println("Font:"+name);//name′s value is Dialog <BR>Font f = new Font(name ,Font.BOLD+Font.ITALIC ,20); <BR>jl.setForeground(Color.red); <BR>jl.setFont(f); <BR>jf.getContentPane().setLayout(new GridLayout(5 ,2)); <BR>jf.getContentPane().add(new JLabel(" ")); <BR>jf.getContentPane().add(jl); <BR>jf.getContentPane().add(new JLabel("sorry! this function is not do!!")); <BR>jf.pack(); <BR>jf.addWindowListener(new WindowAdapter(){ <BR>public void windowClosing(WindowEvent we){ <BR>jf.dispose(); <BR>} <BR>}); <BR>} <BR>else{ <BR>System.out.println("I am not selected"); <BR>} <BR>} <BR>} <BR>} <BR>} <BR></P><img src ="http://www.aygfsteel.com/lemon/aggbug/25371.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/lemon/" target="_blank">lemon</a> 2005-12-25 15:35 <a href="http://www.aygfsteel.com/lemon/archive/2005/12/25/25371.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于JAVA学习http://www.aygfsteel.com/lemon/archive/2005/12/12/23558.htmllemonlemonMon, 12 Dec 2005 13:37:00 GMThttp://www.aygfsteel.com/lemon/archive/2005/12/12/23558.htmlhttp://www.aygfsteel.com/lemon/comments/23558.htmlhttp://www.aygfsteel.com/lemon/archive/2005/12/12/23558.html#Feedback0http://www.aygfsteel.com/lemon/comments/commentRss/23558.htmlhttp://www.aygfsteel.com/lemon/services/trackbacks/23558.html

lemon 2005-12-12 21:37 发表评论
]]>
本h博客中国的分栏代?分n一?/title><link>http://www.aygfsteel.com/lemon/archive/2005/12/02/22278.html</link><dc:creator>lemon</dc:creator><author>lemon</author><pubDate>Fri, 02 Dec 2005 11:38:00 GMT</pubDate><guid>http://www.aygfsteel.com/lemon/archive/2005/12/02/22278.html</guid><wfw:comment>http://www.aygfsteel.com/lemon/comments/22278.html</wfw:comment><comments>http://www.aygfsteel.com/lemon/archive/2005/12/02/22278.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/lemon/comments/commentRss/22278.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/lemon/services/trackbacks/22278.html</trackback:ping><description><![CDATA[<P><!--用iframe来装?005索引,q样我们p得了所有本q度的文章列表了--><BR><!--<iframe id="cataloghtml" src="catalog_2005.html" style=display:none;position:absolute;top:400;left:400;z-index:250 </P> <P>></iframe>--><BR><script><BR>var startYear = 2005; //你的博客是哪一q徏立的Q?BR>var showCount = 10; // 每个栏目昄多少条?</P> <P><BR>var d = new Date();<BR>var currYear = d.getUTCFullYear();<BR>for(i=currYear;i>=startYear;i--)<BR>{<BR>document.writeln('<iframe id="cataloghtml'+i+'" src="catalog_'+i+'.html" </P> <P>style=display:none;position:absolute;top:400;left:400;z-index:250 ></iframe>');<BR>}<BR></script><BR><script><BR>//q部分的脚本是自动更新用?BR>//从cataloghtml的categorynameq个栏目d文章列表攑ֈ当前面的mycategoryname?BR>function showcatalog(mycategoryname,categoryname)<BR>{<BR>var currShowCount = 0;<BR>var currTotalCount = 0;<BR>l="<ul type='circle'>";<BR>for(iyear=currYear;iyear>=startYear;iyear--)<BR>{<BR>currCategory = document.body.all[mycategoryname];<BR>ol = eval("cataloghtml"+iyear+".document.body.all");</P> <P>var entityDiv = null;<BR>for(i=0;i<ol.length;i++)<BR>{<BR>if(ol[i].className =="entity")<BR>{<BR>entityDiv = ol[i];break;<BR>}<BR>}<BR>ol = entityDiv.children.tags("UL");<BR>var oLI=null;<BR>for(i=0;i<ol.length;i++)<BR>{<BR>if(ol[i].children(0).name==categoryname)<BR>{<BR>oLI = ol[i].children.tags("LI");<BR>break;<BR>}<BR>}<BR>if(oLI == null) return ;<BR>for(i=0;i<oLI.length;i++)<BR>{<BR>if(i>showCount-1) break;<BR>oA = oLI[i].children(1);<BR>s = oA.innerHTML;<BR>pos = s.search(/[Q|】|』|\]]{1}/);<BR>if(pos>0)s=s.slice(pos+1);<BR>l += "<li style='width:245px;height:18;overflow:hidden'><a href='"+oA.href+"' target='_blank'>"+s+"</a></li>\r\n";<BR>}<BR>currShowCount += i;<BR>currTotalCount += oLI.length;<BR>}</P> <P>for(;currShowCount<showCount;currShowCount++)<BR>l += "<li style='width:245px;height:18;overflow:hidden'>...</li>\r\n";</P> <P>l+="</ul>";<BR>currCategory.insertAdjacentHTML("beforeend",l);<BR>// 增加代码Q统计栏目文章数<BR>titleDIV = currCategory.parentElement.children(0);<BR>titleDIV.insertAdjacentHTML("beforeend","Q?+ currTotalCount +"Q?);<BR>}</P> <P><BR>//从cataloghtmld目录q生成当前页?</P> <P>  function showallcatalog() </P> <P>  { </P> <P>  //需要改写的地方之一 </P> <P>  showcatalog("mcategory1","category1");//L感绿z?</P> <P>  showcatalog("mcategory2","category2");//L学草?</P> <P>  showcatalog("mcategory3","category3");//ȝ教园?/P> <P>  showcatalog("mcategory4","category4");//ȝ脑网l?BR> <BR>        showcatalog("mcategory5","category5");//※院校文?</P> <P>  showcatalog("mcategory6","category6");//※都市生z?/P> <P>  showcatalog("mcategory7","category7");//d韛_?/P> <P>  showcatalog("mcategory8","category8");//Mh在北?</P> <P>  //…?</P> <P>  //注意Q上面的省略可C如果还有第九、第十个标题栏时依此cLQ写cM的代?</P> <P>  } </P> <P>  </script> </P> <P><!--当body装入后调用showallcatalog()装蝲最新文章列?-> </P> <P>  <body onload=showallcatalog()> </P> <P>   </P> <P>    <div><div class="mydiv1" target="_blank"><div class="mybg_01" target="_blank"><a href="<A target="_blank"><img class="myimg" alt="查看更多情感l洲的文章,LL? src="<A /></a>L感绿z?</div><div class="divtext" id="mcategory1" target="_blank"></div></div><!--l束--> </P> <P>    <div><div class="mydiv2" target="_blank"><div class="mybg_01" target="_blank"><a href="<A target="_blank"><img class="myimg" alt="查看更多文学草坪的文章,LL? src="<A /></a>L学草?lt;/div><!--文学部分--><div class="divtext" id="mcategory2" target="_blank"></div></div><!--l束--> </P> <P>    <div><div class="mydiv1" target="_blank"><div class="mybg_01" target="_blank"><a href="<A target="_blank"><img class="myimg" alt="查看更多U教园地的文章,LL? src="<A /></a>ȝ教园?lt;/div><div class="divtext" id="mcategory3" target="_blank"></div></div><!--l束--> </P> <P>    <div><div class="mydiv2" target="_blank"><div class="mybg_01" target="_blank"><a href="<A target="_blank"><img class="myimg" alt="查看更多电脑|络的文章,LL? src="<A /></a>ȝ脑网l?lt;/div><div class="divtext" id="mcategory4" target="_blank"></div></div><!--l束--> </P> <P>    <div><div class="mydiv1" target="_blank"><div class="mybg_01" target="_blank"><a href="<A target="_blank"><img class="myimg" alt="查看更多院校文化Q请点击此处" src="<A /></a>※院校文?lt;/div><div class="divtext" id="mcategory5" target="_blank"></div></div><!--l束--> </P> <P>   <div><div class="mydiv2" target="_blank"><div class="mybg_01" target="_blank"><a href="<A target="_blank"><img class="myimg" alt="查看更多都市生活Q请点击此处" src="<A /></a>※都市生z?lt;/div><div class="divtext" id="mcategory6" target="_blank"></div></div><!--l束--></P> <P>   <div><div class="mydiv1" target="_blank"><div class="mybg_01" target="_blank"><a href="<A ><img</A> class="myimg" alt="查看更多影音׃的文章,LL? src="<A /></a>d韛_?lt;/div><!--音乐时空部分--><div class="divtext" id="mcategory7" target="_blank"></div></div><!--l束--> </P> <P>   <div><div class="mydiv2" target="_blank"><div class="mybg_01" target="_blank"><a href="<A target="_blank"><img class="myimg" alt="查看更多人在北京Q请点击此处" src="<A /></a>Mh在北?lt;/div><div class="divtext" id="mcategory8" target="_blank"></div></div><!--l束--></P> <P>   </div></p></P><img src ="http://www.aygfsteel.com/lemon/aggbug/22278.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/lemon/" target="_blank">lemon</a> 2005-12-02 19:38 <a href="http://www.aygfsteel.com/lemon/archive/2005/12/02/22278.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>好的Java风格http://www.aygfsteel.com/lemon/archive/2005/10/18/15844.htmllemonlemonTue, 18 Oct 2005 13:44:00 GMThttp://www.aygfsteel.com/lemon/archive/2005/10/18/15844.htmlhttp://www.aygfsteel.com/lemon/comments/15844.htmlhttp://www.aygfsteel.com/lemon/archive/2005/10/18/15844.html#Feedback0http://www.aygfsteel.com/lemon/comments/commentRss/15844.htmlhttp://www.aygfsteel.com/lemon/services/trackbacks/15844.html管JAVA是用来写E序而不是散文, 但它仍然被用来表达思想和观点的。而且Q在调查中显C,那些思想和观点在实际中完成了很多事情。ؓ~写出好的JAVA风格而担忧,g是在费旉Q?但实际上它对我们~写E序是很适宜的,因ؓ它所要表辄思想和观Ҏ格外清晰的?

q里提供一些理由,Z么要使用好的JAVA代码规范


一个Y件品的80%的生命期是在l护QmaintenanceQ?
几乎没有一个Y件在它的整个生命期里都是被它的作者来l护的?
使用好的风格提高了Y件的可维护性?nbsp; 
如果源代码和软g产品是捆l给客户的,作ؓ产品的剩余部分,它应该有好的分包Qwell-packagedQ,_清晰和专业的代码?

使用好的风格~写代码有以下几点好处:


提高了代码的可读性,持箋性,和谐性。这些都能代码能更Ҏ的理解和l护?
使代码更Ҏ被跟t和调试Q因为它是清晰的和持l的?
使你或另一个程序员在编写终止时更容易再l箋下去Q尤其在一个很长的旉后?
增加了代码预排(walkthroughsQ的好处Q?因ؓ能让参入者更多的焦炚w中在代码正在做什么?

概要斚w
使用好的JAVA风格q不困难Q?但是它确实需要注意细节。下面是一些常用的概要指导斚wQ?


使代码更清晰和更Ҏ?nbsp; 
使代码更持箋  
使用显而易见的标识W名  
逻辑地组l你的文件和c?nbsp; 
每个文g只有一个类(q里不包括一些内部类)
使用80-90个字W的最大行?nbsp; 
明智的用空格来and/or其他分隔W?
~排上,使用I格QSpaceQ来代替Tab

Tabs vs. I格
在编写代码时Q“Tabs vs. I格?是一个严谨的观点。这里我q不是暗C只有一个正的Ҏ。我支持使用I格Q因为它能保证我的代码在你的~辑器里和我的编辑器里看到的相同Q反之矣然。如果你感觉使用I格来代替Tab"不是正确?, 那么׃用Tab吧?

括号和羃q?BR>在编写代码时Q羃q风?cf., Raymond, "Indent Style")Q或者放|括?"{" ?"}") 和一些相兌的羃q代码,是另一个严谨的观点。象JAVA一P有许多C风格的语a存在。我q里也不是暗C它们中哪一个更优先更好。在大多数本文的范例代码中,我用了K&R 风格Q如果你不喜ƢK&R风格Q那么就使用其他风格吧?BR>
注释
在JAVA代码中你可以使用两种注释Q?Javadoc 注释 (也称为文档注? 和执行注释?Javadoc注释能够被javadoc工具解压来制造一个API文档。执行注释是那些解释代码目的和方式的注释。在注释你的JAVA代码时请使用以下斚wQ?


可能的使用Javadoc注释(在类和方法上Q之能最化).
多用块注释Q少使用//注释, 除非一些特D的情况Q如变量声明
要记住:好注释是有帮助的Q坏注释是麻烦的?

Example 1. Bad Comment Style

// applyRotAscii() -- Apply ASCII ROT
   private void applyRotAscii(){
      try{
         int rotLength = Integer.parseInt(rotationLengthField.getText().trim()); // get rot len
         RotAscii cipher = new RotAscii(rotLength); // new cipher
         textArea.setText(cipher.transform(textArea.getText())); // transform
      }catch(Exception ex){
         /* Show exception */
         ExceptionDialog.show(this, "Invalid rotation length: ", ex); }
   }



Example 2. Good Comment Style

/**
    * Apply the ASCII rotation cipher to the user's text. The length is retrieved
    * from the rotation length field, and the user's text is retrieved from the
    * text area.
    *
    * @author Thornton Rose
    */
   private void applyRotAscii() {
      int      rotLength = 0;  // rotation length
      RotAscii cipher = null;  // ASCII rotation cipher
  
      try {
         // Get rotation length field and convert to integer.
          
         rotLength = Integer.parseInt(rotationLengthField.getText().trim());
        
         // Create ASCII rotation cipher and transform the user's text with it.
          
         cipher = new RotAscii(rotLength);
         textArea.setText(cipher.transform(textArea.getText()));
  
       } catch(Exception ex) {
         // Report the exception to the user.
        
         ExceptionDialog.show(this, "Invalid rotation length: ", ex);
      }
   }



块和语句
使用下面的方针来~写块和语句Q?


一行只写一个语?nbsp; 
控制语句L使用{}q样的括?(e.g., 'if').
考虑在块的末用一个注?(e.g., } // end if), 其是长的或嵌套?
在块的开头放|变量的声明语句  
总记得初始化变量  
如果你是个完主义者,左对齐变量名
在switch块里~进case从句  
在操作符后留有空?
在if, for, 或while语句中, 在括号“(”前留有I白
在表辑ּ中用空白和插入语来增强可读?

在for循环中的变量是个例外?循环变量可能会在语句初始化部分被定义?e.g., for (int i = 0; ...)

.

在块的末插入注释有助于你无意中跟踪到被删除的结括号“}?

Example 3. Bad Block Style.

try{
      for(int i=0;i<5;i++){
         ...
         }
      int threshold=calculateThreshold();
      float variance=(threshold*2.8)-1;
      int c=0;
      if (threshold<=15) c=calculateCoefficient();
      switch(c){
      case 1: setCeiling(c*2); break;
      case 2: setCeiling(c*3); break;
      else: freakOut();
      }
   }catch(Exception ex){ ... }



Example 4. Good Block Style.

try {
      int   threshold  = 0;
      float variance    = 0.0;
      int   coefficient = 0;
      
      // Prepare 5 cycles.
      
      for (int i = 0; i < 5; i ++){
         prepareCycle(i);
      }
      
      // Calculate the threshold and variance.
      
      threshold = calculateThreshold();
      variance = (threshold * 2.8) - 1;
      
      // If the threshold is less than the maximum, calculate the coefficient.
      // Otherwise, throw an exception.
      
      if (threshold <= MAX_THRESHOLD) {
         coefficient = calculateCoefficient();
      } else {
         throw new RuntimeException("Threshold exceeded!");
      }
      
      // Set the ceiling based on the coefficient.
      
      switch (coefficient) {
         case 1:
            setCeiling(coefficient * 2);
            break;
          
         case 2:
            setCeiling(coefficient * 3);
            break;
          
         else:
            freakOut();
      } // end switch
   } catch(Exception ex) {
      ...
   } // end try


lemon 2005-10-18 21:44 发表评论
]]>
关于BlogJavahttp://www.aygfsteel.com/lemon/archive/2005/10/09/15040.htmllemonlemonSun, 09 Oct 2005 02:29:00 GMThttp://www.aygfsteel.com/lemon/archive/2005/10/09/15040.htmlhttp://www.aygfsteel.com/lemon/comments/15040.htmlhttp://www.aygfsteel.com/lemon/archive/2005/10/09/15040.html#Feedback0http://www.aygfsteel.com/lemon/comments/commentRss/15040.htmlhttp://www.aygfsteel.com/lemon/services/trackbacks/15040.html

lemon 2005-10-09 10:29 发表评论
]]>
վ֩ģ壺 | ƽң| ɽ| | | | | ɽ| | ̨| | | Ľ| | «| | | | | ˮ| | | ˮ| ԰| | | | ľ| κ| ʳ| | ƽ| | °Ͷ| | ʡ| | Ǩ| | | |