代码之家  ›  专栏  ›  技术社区  ›  Matt Bannert

创建一个简单的表单应用程序来编辑文本文件

  •  1
  • Matt Bannert  · 技术社区  · 15 年前

    我有一个自动生成的报告文件,其中包含乳胶代码。现在我想构建一个小应用程序,为每个节及其标题创建一个表单字段。该文档仅包含几百行,并且应该执行以下操作:

    \section{ This is were the header text should go inside the document  }
    \normalsize{ This is where the normal text should go}
    

    编辑: 这是我的第一次尝试。我想我应该使用明文文件而不是直接发送,但我´我会弄明白的,因为我在编辑器/文本组件链接方面得到了垃圾神的大量帮助。主要问题是从\section{}和\normalsize{}内容中挑出内容。也许我会在这里买些regexp。每次出现我都需要一个新的文本区域。

    import java.awt.*;
    import java.awt.event.*;
    import java.io.File;
    import java.io.FileReader;
    
    import javax.swing.*;
    
    public class basicFrame extends JFrame {
    // Declare Variables
    
        JScrollPane bildlauf = new JScrollPane();
        JTextArea txtfeld = new JTextArea();
    
        public basicFrame() {
            super();
    
    
            // Main window
            setTitle("ReportEditor");
            setBackground(Color.LIGHT_GRAY);
    
            // components 
            try {
                File datei = new File("report.Rnw");
                FileReader in = new FileReader(datei);
                txtfeld.read(in, datei);
                in.close();
    
            } catch (Exception e) {
                System.out.println("Error !");
            }
    
            // setLayout(new GridLayout(2,2));
    
            // Scroll Shizzle
            bildlauf.getViewport().add(txtfeld, null);
            getContentPane().add(bildlauf, BorderLayout.CENTER);
    
            //txtfeld.setSize(500,680);
            //add(txtfeld);
            //this.getContentPane().add(txtfeld);
    
            // close
            addWindowListener(new WindowLauscher());
        }
    
        // event handlers... 
        protected static final class WindowLauscher extends WindowAdapter {
    
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        }
    
        public static void main(String[] args) {
            //Fesnter erzeugen und anzeigen, die main Sache halt
            basicFrame hf = new basicFrame();
            hf.setSize(500, 700);
            hf.setLocation(100, 100);
            hf.setVisible(true);
    
        }
    }
    

    1 回复  |  直到 15 年前
        1
  •  1
  •   Community CDub    8 年前

    这个 TeX on Mac OS X jEdit plugins . LaTeXTools 也许是个好的开始。

    附录:

    我不想重新发明轮子。
    我只想创建一个表单应用程序。

    JTextComponent 对于每个可编辑的部分。以下是对 Using Text Components Text Component Features 如果要创建自己的编辑器工具包,如中所述 Customizing a Text Editor .

    附录:除了教程,你可以看看这个 text field layout example . 另外,考虑两列 JTable

    附录:关于代码的一些注释。

    1. 类名通常大写,例如。 BasicFrame .

    2. JFrame 如果你不改变它的行为; JPanel 是其他组件的良好容器,可以在 .

    3. EDT .

    4. 保持您的视图和模型 separate .

    推荐文章