N
Neuling
Gast
Hallo habe folgendes Problem:
ich schreibe grad ein programm, dass in einem text, den man in ein JTextArea lädt spezielle Buchstabenkombinationen wie z.b.: ## oder ++ gegen Wörter ausgetauscht werden, die das Programm aus einer JTable laden soll. Danach soll der jeweilige Text gespeichert werden. Am besten in folgender Form: wortaustabelle.html. Danach soll die schleife mit dem nächsten wort aus der Tabelle weitermachen und wieder speichern. so lange bis das ende der tabelle erreicht ist.
1. Problem: Meine Schleife wird nicht gestartet
2. Problem: Wie speichere ich einen String als xyz.html
hier der Code! wer kann helfen??
(die System outs sind nur zum debuggen gedacht!)
ich schreibe grad ein programm, dass in einem text, den man in ein JTextArea lädt spezielle Buchstabenkombinationen wie z.b.: ## oder ++ gegen Wörter ausgetauscht werden, die das Programm aus einer JTable laden soll. Danach soll der jeweilige Text gespeichert werden. Am besten in folgender Form: wortaustabelle.html. Danach soll die schleife mit dem nächsten wort aus der Tabelle weitermachen und wieder speichern. so lange bis das ende der tabelle erreicht ist.
1. Problem: Meine Schleife wird nicht gestartet
2. Problem: Wie speichere ich einen String als xyz.html
hier der Code! wer kann helfen??
(die System outs sind nur zum debuggen gedacht!)
Code:
package Model;
import View.*;
public class Controller
{
private MainView m;;
private String phKey = "##";
private String phAlt = "++";
private String back;
private String text;
private int i = 0;
public Controller(MainView m)
{
this.m = m;
}
public void generate()
{
System.out.println("works");
text = m.getHtmlTextArea().getText();
System.out.println((String)m.getTable().getValueAt(0, 1));
System.out.println((String)m.getTable().getValueAt(1, 0));
for(i = 0; i == 29 ; i++)
{
String key = (String)m.getTable().getValueAt(i, 0);
System.out.println("Hallo");
String alt = (String)m.getTable().getValueAt(i, 1);
if(key != null)
{
back = text.replaceAll(phKey, key);
if(alt != null)
{
System.out.println("Schleife");
System.out.println(back);
back = text.replaceAll(phAlt, alt);
}
}
m.getHtmlTextArea().append(back + "\n");
//speichern
//m.getHtmlTextPane().setText(text);
}
}
}
---------------------------------------------------------------------------------------------------------
package View;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import Model.*;
public class MainView extends JFrame
{
private JPanel commandsPanel = new JPanel();
private JButton saveButton = new JButton("Replace & Save");
private JTextArea htmlTextArea = new JTextArea();
private Controller c;
private JScrollPane tableScroll = new JScrollPane();
private JTable table = new JTable();
public MainView()
{
c = new Controller(this);
setTitle("Doorwaypage Generator v-1.0");
initComponents();
setVisible(true);
setResizable(false);
pack();
}
public void initComponents()
{
//add WindowListener to close window
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
//table
tableScroll.setBorder(new TitledBorder("Keywords"));
table.setModel(new DefaultTableModel(
new Object [][] {
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null}
},
new String [] {
"Keyword:", "Alternative:"
}
));
table.setGridColor(new Color(0, 0, 0));
table.setPreferredScrollableViewportSize(new Dimension(150, 480));
table.setPreferredSize(new Dimension(150, 480));
tableScroll.setViewportView(table);
//build JPanel
saveButton.setPreferredSize(new Dimension(150, 30));
commandsPanel.setPreferredSize(new Dimension(170, 570));
commandsPanel.add(tableScroll, BorderLayout.NORTH);
commandsPanel.add(saveButton, BorderLayout.CENTER);
saveButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
c.generate();
}
});
//build ScrollPane
JScrollPane textPane = new JScrollPane(htmlTextArea);
textPane.setPreferredSize(new Dimension(500,450));
//add components on frame
getContentPane().add(commandsPanel, BorderLayout.EAST);
getContentPane().add(textPane, BorderLayout.CENTER);
}
public static void main(String[] args)
{
MainView m = new MainView();
}
/**
* @return
*/
public JTextArea getHtmlTextArea()
{
return htmlTextArea;
}
/**
* @param pane
*/
public void setHtmlTextArea(JTextArea pane)
{
htmlTextArea = pane;
}
/**
* @return
*/
public JTable getTable()
{
return table;
}
}