import javax.swing.BorderFactory; import javax.swing.border.Border;import javax.swing.border.TitledBorder;import javax.swing.Box;import javax.swing.BoxLayout;import java.util.*;import java.io.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.net.*;public class TPV extends JFrame{ JButton View_B, Clear_B, Close_B; JTextArea JTA_TextAuszug; JTextField EF_FileName, EF_TextAuszug; String V_FileName, V_TextAuszug, St_TextAuszug; public TPV() { super("Text-Part-Viewer"); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { setVisible(false); dispose(); System.exit(0); } }); View_B = new JButton("view"); Clear_B = new JButton("clear"); Close_B = new JButton("close"); JTA_TextAuszug = new JTextArea(); EF_FileName = new JTextField("Beispiel.txt", 20); EF_FileName.setCaretPosition(12); EF_TextAuszug = new JTextField("Text08", 20); EF_TextAuszug.setCaretPosition(6); ActionListener TextAuszugListener = new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("view")) { try { V_FileName = new String(EF_FileName.getText()); V_TextAuszug = new String(EF_TextAuszug.getText()); JTA_TextAuszug.setText(null); String TextAuszug = V_TextAuszug; BufferedReader in = new BufferedReader(new FileReader("D:\\"+V_FileName)); while ((St_TextAuszug = in.readLine()) !=null) { int Int_TextAuszug = St_TextAuszug.indexOf(V_TextAuszug); if (Int_TextAuszug > -1) { JTA_TextAuszug.append(St_TextAuszug+"\n"); while ((St_TextAuszug = in.readLine()) !=null) { JTA_TextAuszug.append(St_TextAuszug+"\n"); } } } in.close(); } catch (IOException ioe) { System.out.println("IOException: "+ioe); } } else if (e.getActionCommand().equals("clear")) { JTA_TextAuszug.setText(null); } else if (e.getActionCommand().equals("close")) { setVisible(false); dispose(); System.exit(0); } } }; Border paneEdge10 = BorderFactory.createEmptyBorder(10,10,10,10); View_B.addActionListener(TextAuszugListener); Clear_B.addActionListener(TextAuszugListener); Close_B.addActionListener(TextAuszugListener); JPanel Ebene0 = new JPanel(); Ebene0.setLayout(new BorderLayout()); Ebene0.setBorder(paneEdge10); JPanel Ebene0o = new JPanel(); Ebene0o.setLayout(new GridLayout(2,4)); JPanel Ebene0m = new JPanel(); Ebene0m.setLayout(new BorderLayout()); JPanel Ebene0u = new JPanel(); Ebene0u.setLayout(new BorderLayout()); JLabel E0o_Leer01 = new JLabel(" "); JLabel E0o_FileName = new JLabel("filename:"); JLabel E0o_TextPart = new JLabel("word:"); JLabel E0o_Leer02 = new JLabel(" "); Ebene0o.add(E0o_Leer01); Ebene0o.add(E0o_FileName); Ebene0o.add(E0o_TextPart); Ebene0o.add(E0o_Leer02); Ebene0o.add(Clear_B); Ebene0o.add(EF_FileName); Ebene0o.add(EF_TextAuszug); Ebene0o.add(View_B); JScrollPane SP_TextOutput = new JScrollPane(JTA_TextAuszug); SP_TextOutput.setPreferredSize(new Dimension(380,240)); Ebene0m.add(SP_TextOutput, BorderLayout.CENTER); Ebene0u.add(Close_B, BorderLayout.EAST); Ebene0.add(Ebene0o, BorderLayout.NORTH); Ebene0.add(Ebene0m, BorderLayout.CENTER); Ebene0.add(Ebene0u, BorderLayout.SOUTH); getContentPane().add(Ebene0, BorderLayout.CENTER); } public static void main(String[] args) { TPV TPVw = new TPV(); Toolkit tk = Toolkit.getDefaultToolkit(); Dimension d = tk.getScreenSize(); TPVw.setLocation(d.width/2-200, d.height/2-150); TPVw.setSize(400, 300); TPVw.setResizable(false); TPVw.setVisible(true); }}