-1
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package texteditor;
//import java.awt.*;
import javax.swing.*;
/**
 *
 * @author 
 */
public class TextEditor {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        JFrame window = new JFrame("Text Editor");
        //JMenuBar menuBar = window.getJMenuBar();

        //Create menu bar
        JMenuBar menuBar= new JMenuBar();
        //File Menu
        JMenu fileMenu = new JMenu("File");
        fileMenu.add(new JMenuItem("Save"));

        menuBar.add(fileMenu);
        window.setJMenuBar(menuBar);

        JTextPane textArea= new JTextPane();

        Document d= textArea.getDocument();

        window.add(textArea);

        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setVisible(true);
    }
}

错误

Exception in thread "main" java.lang.RuntimeException: Uncompilable
source code - cannot find symbol   symbol:   class Document  
location: class texteditor.TextEditor   at
texteditor.TextEditor.main(TextEditor.java:33) Java Result: 1 BUILD
SUCCESSFUL (total time: 2 seconds)

如何解决?

4

2 回答 2

3

Document使用的 in包含JTextPane在单独的text包中。添加导入:

import javax.swing.text.Document;
于 2013-01-06T15:42:03.403 回答
1

线程“main”java.lang.RuntimeException 中的异常:无法编译的源代码 -找不到符号 symbol:class Document

您需要导入一个名为 Document 的适当类。

于 2013-01-06T15:41:57.140 回答