public void getParam(){
        frameX = Integer.parseInt(props.getProperty("top"));
        frameY = Integer.parseInt(props.getProperty("left"));
        frameWidth = Integer.parseInt(props.getProperty("width"));
        frameHeight = Integer.parseInt(props.getProperty("height"));
    }
    
    public void setParam(){
        props.setProperty("top", frameX + "");
        props.setProperty("left", frameY + "");
        props.setProperty("width", frameWidth + "");
        props.setProperty("height", frameHeight + "");
    }
    
    public void doClosing(){
        if(change == true){
            int result = JOptionPane.showConfirmDialog(null, "文件被改动了,请注意保存文件!",
            "注意", JOptionPane.OK_CANCEL_OPTION);
            if(result == JOptionPane.OK_OPTION){
                if(fileName != null)
                    writeFile(fileName);
                saveAsFileDialog.show();
                fileName = saveAsFileDialog.getDirectory()+saveAsFileDialog.getFile();
                if (fileName!= null)
                    writeFile(fileName);
            }
        }
        frameX = getX();
        frameY = getY();
        frameWidth = getWidth();
        frameHeight = getHeight();
        
        setParam();
        try{
            savaConfig();
        }catch(Exception ex){
            ex.printStackTrace();
        }
        System.exit(1);
    }
    
    public void doOpening(){
        try{
            loadConfig();
            getParam();
        }catch(Exception ex){
            ex.printStackTrace();
        }
        setLocation(frameX, frameY);
        setSize(frameWidth, frameHeight);
    }
    
    public void readFile(String fileName){
        try{
            textArea.setText("");
            File file = new File(fileName);
            BufferedReader breader = new BufferedReader(new FileReader(file));
            while(true){
                str = breader.readLine();
                if(str == null)
                    break;
                textArea.append(str + "\n");
                change = false;
            }
        }catch(IOException e){
            System.out.println("不能打开文件");
        }
    }
    
    public void writeFile(String fileName){
        try{
            File file = new File (fileName);
            FileWriter writeOut = new FileWriter(file);
            writeOut.write(textArea.getText());
            writeOut.close();
            change = false;
        }catch(IOException e){
            System.out.println("存储文件错误");
        }
    }
    
    public void setLookAndFeel(int index){
        try {
            UIManager.setLookAndFeel(lafArray[index]);
 } catch (Exception exc) {
        System.err.println("Error loading " + lafArray[index] + ": " + exc);
 }
    }
    
    private void theSetToolTipText(){
        newItem.setToolTipText("新建一个文件");
    }
}

解决方案 »

  1.   

    哪位有自己用JAVA编的记事本,把源代码发给我好吗?
    [email protected]
      

  2.   

    何必舍近求远,JDK里就自带有个很不错的记事本。
      

  3.   

    java web start 就带了个记事本程序
      

  4.   

    第一个问题已经解决:The java.awt.TextArea could be monitored for changes by adding a TextListener for TextEvents. In the JTextComponent based components, changes are broadcasted from the model via a DocumentEvent to DocumentListeners. The DocumentEvent gives the location of the change and the kind of change if desired. The code fragment might look something like:     DocumentListener myListener = ??;
        JTextArea myArea = ??;
        myArea.getDocument().addDocumentListener(myListener);
      

  5.   

    谁要是兄弟,就帮yoti一个忙。把答案告诉他
      

  6.   

    弹pop菜单就行了。难道这个不行吗?
      

  7.   

    第二个问题,你要replaint一下
    第三个问题,你要监听鼠标右键,相应单击动作
    获取鼠标坐标,然后根据坐标new frame()就好了我只知道这些,可能有更好的方法
      

  8.   

    第三个问题,是我忘记加监听器了,哈哈,真是丢脸!
    第二个问题,需要加一句话!
    SwingUtilities.updateComponentTreeUI(this);但是我郁闷的就是,我遇到这样的问题的时候,我怎么找才能知道要加这句话,我根本不可能想到,也不可能轻易的找到是需要加这一句话,郁闷!