2 u013027835 u013027835 于 2014.09.17 16:08 提问

这是我的java加密日记本程序 哪里错了啊!!求解释

public class Diary {
public static void main(String args[])throws Exception;{

new LoginWindow();
Remember win=new Remember();
win.pack();
}
}
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.io.*;
import java.util.*;
class Remember extends JFrame implements
TreeSelectionListener,ActionListener{
private static final String DiaryRoot = null;
JTree tree=null;
int i=0,r=255,g=255,b=255;
JTextArea text=new JTextArea(" ",20,50);
DefaultMutableTreeNode root;
DefaultMutableTreeNode
month[]=new DefaultMutableTreeNode[13];
JButton b_save=new JButton("保存"),
b_fontCommen=new JButton("还原"),
b_fontBig=new JButton("大字"),
b_fontRed=new JButton("红色"),
b_fontBlue=new JButton("蓝色"),
b_bg=new JButton("背景");
Remember ()
{
Container con=getContentPane();
DefaultMutableTreeNode root=new DefaultMutableTreeNode("日记本");
for(i=1;i<=12;i++){
month[i]=new DefaultMutableTreeNode(""+i+"月");
root.add(month[i]);
}
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++){
String s1=month[i].toString();
String s2=j+"日.txt";
File file=new File(DiaryRoot+s1+s2);
if(file.exists()==true) month[i].add(new DefaultMutableTreeNode(j+"日*"));
}
}
else if(i==4||i==6||i==9||i==11){
for(int j=1;j<=30;j++){
String s1=month[i].toString();
String s2=j+"日.txt";
File file=new File(DiaryRoot+s1+s2);
if(file.exists()==true) month[i].add(new DefaultMutableTreeNode(j+"日*"));
else month[i].add(new DefaultMutableTreeNode(j+"日"));
}
}
else{
for(int j=1;j<=28;j++){
String s1=month[i].toString();
String s2=j+"日.txt";
File file=new File(DiaryRoot+s1+s2);
if(file.exists()==true) month[i].add(new DefaultMutableTreeNode(j+"日*"));
else month[i].add(new DefaultMutableTreeNode(j+"日"));
}

        }
    }
    b_save.addActionListener(this);
    b_fontRed.addActionListener(this);
    b_fontCommen.addActionListener(this);
    b_fontBig.addActionListener(this);
    b_fontBlue.addActionListener(this);
    b_bg.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_fontCommen);
    p_1.add(b_fontBig);
    p_1.add(b_fontRed);
    p_1.add(b_fontBlue);
    p_1.add(b_bg);
    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);
    addWindowListener(new WindowAdapter(){
        public void windowClosing(WindowEvent e){
            System.exit(0);
        }
    });
setVisible(true);
setBounds(200,150,500,600);

}
public void valueChanged(TreeSelectionEvent e){
text.setText(" ");
if(e.getSource()==tree){
DefaultMutableTreeNode node=(DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
if(node.isLeaf()){
String str=node.toString();
str=str.substring(0,str.length()-1);
for(int i=0;i<=12;i++){
if(node.getParent()==month[i]){
try {
String temp=null;
File f=new File(DiaryRoot+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(FileNotFoundException e1){ }
catch(IOException e1){ }
}
}
}
}
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b_save){
DefaultMutableTreeNode node=(DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
String str=node.toString();
str=str.replace("*","");
if(node.isLeaf()){
try{
File f=new File(DiaryRoot+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(FileNotFoundException e1){ }
catch(IOException e1){ }
}
}
else if(e.getSource()==b_fontBig){
text.setFont(new Font("Serif",1, 18));
}
else if(e.getSource()==b_fontCommen){
text.setFont(new Font("Serif",0,12));
text.setForeground(Color.black);
}
else if(e.getSource()==b_fontRed){
text.setForeground(Color.red);
}
else if(e.getSource()==b_fontBlue){
text.setForeground(Color.blue);
}
else if(e.getSource()==b_bg){
double op = Math.random();
double c = Math.random()*10;
if(op>0.5){
if(c if(c>4 && c if(c>7) b-=Math.random()*50;
}
if(op<=0.5){
if(c if(c>4 && c if(c>7) b-=Math.random()*50;
}
text.setBackground(new Color(r,g,b));
}
}
void del(){
try{
Runtime ce=Runtime.getRuntime();
ce.exec("gxy.bat");
}
catch(IOException e1){ }
}
}
class
LoginWindow extends JDialog implements ActionListener{
JTextField txtUserName=new JTextField(15);
JTextField txtPwd=new JPasswordField(15);
JButton ok=new JButton("确定");
JButton cancel=new JButton("取消");
public LoginWindow(){
JPanel[] p=new JPanel[4];
for(int i=0;i<4;i++ )
p[i]=new JPanel();
JPanel p1=new JPanel();
setModal(true);
setBackground(Color.LIGHT_GRAY);
Container contentPane=this.getContentPane();
contentPane.setLayout(new GridLayout(5,1));
p[1].add(new JLabel("用户名:"));p[1].add(txtUserName);
p[2].add(new JLabel("密 码:"));p[2].add(txtPwd);
p[3].add(ok);p[3].add(cancel);
ok.addActionListener(this);
cancel.addActionListener(this);
txtUserName.addActionListener(this);
txtPwd.addActionListener(this);
contentPane.add(p[0]);
contentPane.add(p[1]);
contentPane.add(p[2]);
contentPane.add(p[3]);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(300,220);
Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
setLocation((screen.width-300)/2,(screen.height-220)/2);
setTitle("登录窗口");
setResizable(false);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==ok||e.getSource()==txtPwd){
if(txtUserName.getText().trim().equals("c") && txtPwd.getText().equals("123")){
dispose();
}
else{
JOptionPane.showMessageDialog(null,"用户名或密码错误!");
txtUserName.requestFocus();
txtUserName.setSelectionStart(0);
txtUserName.setSelectionEnd(txtUserName.getText().length());
}
}
else if(e.getSource()==cancel){
dispose();
System.exit(0);
}
else if(e.getSource()==txtUserName){
txtPwd.requestFocus();
}
}
}

Csdn user default icon
上传中...
上传图片
插入图片