Oi galera
Estou com um problema que nao consigo resolver.
Fiz um programa em java que le XML usando SAX, implementei JTextArea para mostrar os valores, o programa roda tranquilamente sem nenhum problema
So que agora quero colocar esse programa no NetBeans para trabalhar mais facilmente, mas nao estou consegindo implementalo por causa de um problema
O Netbeans usa
public class MySAXApp extends javax.swing.JFrame {
public class MySAXApp extends DefaultHandler
E ate onde sei nao se pode usar dois extender na mesma classe, nao entendo muito de java ainda, grande parte do programa que eu fiz foi com ajuda do google mesmo, por isso essa duvida
Muito obrigado pela ajuda
Aqui esta o codigo do SAX completo
import java.io.FileReader;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import org.xml.sax.XMLReader;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.helpers.DefaultHandler;
public class MySAXApp extends DefaultHandler
{
protected JTextArea textArea;
static JEditorPane jep = new JEditorPane();
public static void main (String args[])
throws Exception
{
XMLReader xr = XMLReaderFactory.createXMLReader();
MySAXApp handler = new MySAXApp();
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
String file = "C:\Users\Lucas\Java\bookds5.xml";
FileReader r = new FileReader(file);
xr.parse(new InputSource(r));
}
public MySAXApp ()
{
super();
textArea = new JTextArea();
JScrollPane scrollingArea = new JScrollPane(textArea);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.add(textArea);
frame.add(scrollingArea);
frame.pack();
frame.setVisible(true);
frame.setSize(600, 400);
}
////////////////////////////////////////////////////////////////////
// Event handlers.
////////////////////////////////////////////////////////////////////
public void startDocument ()
{
System.out.println("Início do documento");
textArea.append("Início do documento \n");
}
public void endDocument ()
{
System.out.println("Fim do documento");
textArea.append("Fim do documento \n");
}
public void startElement (String uri, String localName,
String qName, Attributes attrs)
{
int length = attrs.getLength();
for (int i=0; i<length; i++) {
String value = attrs.getValue(i);
if (value.equalsIgnoreCase("500")){
String value1 = attrs.getValue(0);
String value2 = attrs.getValue(1);
String value3 = attrs.getValue(2);
String value4 = attrs.getValue(3);
String value5 = attrs.getValue(4);
textArea.append(value1 + "\n"+ value2 + "\n"+ value3 + "\n"+ value4+ "\n"+ value5+ "\n");
}
}
}
}