java 源代码 基础点的 谢谢

汗~~~这叫300行。。。

我也贴一个: 用Java写的记32313133353236313431303231363533e4b893e5b19e31333238636664事本,同样的,仅供交流,请勿商用! import javax.swing.*; import javax.swing.tree.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.io.*; class Remember extends JFrame implements TreeSelectionListener,ActionListener { JTree tree=null; JTextArea text=new JTextArea(20,20); int i=0; DefaultMutableTreeNode root; JButton b_save=new JButton(\"保存日记\"); JButton b_del=new JButton(\"删除日记\"); DefaultMutableTreeNode month[]=new DefaultMutableTreeNode[13]; Remember() { Container con=getContentPane(); DefaultMutableTreeNode root=new DefaultMutableTreeNode(\"日历记事本\"); for(i=1;i<=12;i++) { month=new DefaultMutableTreeNode(\"\"+i+\"月\"); root.add(month); } for(i=1;i<=12;i++) { if(i==1||i==3||i==5||i==7||i==8||i==10||i==12) { for(int j=1;j<=31;j++) month.add(new DefaultMutableTreeNode(j+\"日\")); } else if(i==4||i==6||i==9||i==11) { for(int j=1;j<=30;j++) month.add(new DefaultMutableTreeNode(j+\"日\")); } else { for (int j=1;j<=28;j++) month.add(new DefaultMutableTreeNode(j+\"日\")); } } b_save.addActionListener(this); b_del.addActionListener(this); tree=new JTree(root); JPanel p=new JPanel(); p.setLayout(new BorderLayout()); JScrollPane scrollpane_1=new JScrollPane(text); p.add(scrollpane_1,BorderLayout.CENTER); JPanel p_1=new JPanel(); p_1.add(b_save); p_1.add(b_del); p.add(p_1,BorderLayout.NORTH); JScrollPane scrollpane_2=new JScrollPane(tree); JSplitPane splitpane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,scrollpane_2,p); tree.addTreeSelectionListener(this); con.add(splitpane); setVisible(true); setBounds(70,80,460,320); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } public void valueChanged(TreeSelectionEvent e) { text.setText(null); if(e.getSource()==tree) { DefaultMutableTreeNode node=(DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); if(node.isLeaf()) { String str=node.toString(); for(int i=0;i<=12;i++) { if(node.getParent()==month) { try{ String temp=null; File f=new File(node.getParent().toString()+str+\".txt\"); FileReader file=new FileReader(f); BufferedReader in=new BufferedReader(file); while((temp=in.readLine())!=null) text.append(temp+\'\\n\'); file.close(); in.close(); } catch(Exception el){} } } } } } public void actionPerformed(ActionEvent e) { if(e.getSource()==b_save) { DefaultMutableTreeNode node=(DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); String str=node.toString(); if(node.isLeaf()) { try { File f=new File(node.getParent().toString()+str+\".txt\"); FileWriter tofile=new FileWriter(f); BufferedWriter out=new BufferedWriter(tofile); out.write(text.getText(),0,(text.getText()).length()); out.flush(); tofile.close(); out.close(); } catch(Exception el){} } } else if(e.getSource()==b_del) { DefaultMutableTreeNode node=(DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); String str=node.toString(); if(node.isLeaf()) { File f=new File(node.getParent().toString()+str+\".txt\"); f.delete(); } } } } public class Example17_13 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Remember win=new Remember(); win.validate(); } }