The Artima Developer Community
Sponsored Link

Java Answers Forum
Why doesn't this work?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Stefan Parijs

Posts: 16
Nickname: stefan
Registered: May, 2002

Why doesn't this work? Posted: May 18, 2002 12:19 PM
Reply to this message Reply
Advertisement
I want to find some words in my browser. An html browser, with an JEditorPane. And, When The words is found, it has to be selected. But for some reason, it stops running. That is why I 've put a method halp in it, to see, where it goes wrong. And it looks, like it stops running every time on a different character. (i)

the code:

/*
Dit is een produktie van Stefan Parijs(2T.I.2).
*/

import java.util.Vector;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class ZoekDialoogPagina extends JDialog
{
private static final ImageIcon EMBLEEM = new ImageIcon("pics//giraf.gif");

private String tekst;
private JTextField invoerVeld;
private JButton bevestigen;
private JButton annuleren;
private Vector nummers;
private JCheckBox hoofdKleineLetters;
private JPanel richting;
private ButtonGroup eenVanTwee;
private JCheckBox omlaag;
private JCheckBox omhoog;
private JEditorPane contents;
private Browser browser;

public ZoekDialoogPagina(Browser browser, JEditorPane contents, String titel)
{
super( (JFrame) browser, titel);
this.initialiseer(browser,contents);
}

public ZoekDialoogPagina(Browser browser, JEditorPane contents)
{
super( (JFrame) browser, "Zoeken");
this.initialiseer(browser,contents);
}

public ZoekDialoogPagina(Browser browser, String titel)
{
super( (JFrame) browser, titel);
this.initialiseer(browser,browser.getContents());
}

public ZoekDialoogPagina(Browser browser)
{
super( (JFrame) browser, "Zoeken");
this.initialiseer(browser,browser.getContents());
}

private void initialiseer(Browser browser,JEditorPane contents)
{
browser = browser;
contents = contents;

nummers = new Vector();
this.tekst = contents.getText();

Container c = getContentPane();
c.setLayout(null);
this.setBackground(browser.getBrowserKleur());
c.setBackground(browser.getBrowserKleur());
this.setSize(400,200);
this.setLocation(100,100);

this.invoerVeld = new JTextField();
this.invoerVeld.setSize(150,30);
this.invoerVeld.setLocation(10,10);
this.bevestigen = new JButton("Opnieuw Zoeken");
this.bevestigen.setMnemonic('O');
this.bevestigen.setSize(150,30);
this.bevestigen.setLocation(175,10);
this.bevestigen.setBackground(browser.getKnoppenKleur());
this.bevestigen.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
zoeken();
}
});
this.annuleren = new JButton("Annuleren");
this.annuleren.setMnemonic('A');
this.annuleren.setSize(150,30);
this.annuleren.setLocation(175,50);
this.annuleren.setBackground(browser.getKnoppenKleur());
this.annuleren.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
sluiten();
}
});
c.add(invoerVeld);
c.add(bevestigen);
c.add(annuleren);

this.hoofdKleineLetters = new JCheckBox("Hoofd- en kleine letters");
this.hoofdKleineLetters.setLocation(10,100);
this.hoofdKleineLetters.setSize(200,20);
this.hoofdKleineLetters.setBackground(browser.getBrowserKleur());
c.add(hoofdKleineLetters);

this.omlaag = new JCheckBox("Omlaag",true);
this.omlaag.setLocation(10,10);
this.omlaag.setSize(100,20);
this.omhoog = new JCheckBox("Omhoog");
this.omhoog.setLocation(10,40);
this.omhoog.setSize(100,20);
this.eenVanTwee = new ButtonGroup();
this.omlaag.setBackground(browser.getBrowserKleur());
this.omhoog.setBackground(browser.getBrowserKleur());
eenVanTwee.add(omlaag);
eenVanTwee.add(omhoog);
this.richting = new JPanel();
this.richting.setBackground(browser.getBrowserKleur());
richting.add(omlaag);
richting.add(omhoog);
c.add(richting);
richting.setSize(120,80);
richting.setLocation(260,100);

this.setVisible(true);
}

public void zoeken()
{
test();
String hulp ="";
String hulp2="";
try
{
hulp = invoerVeld.getText();
for (int i = 0 ; i <= ((tekst.length()-1)-hulp.length());i++)
{
for (int j=i ; j <= (i+hulp.length()-1) ;j++)
{
hulp2=hulp2+tekst.charAt(j);
}
if (hoofdKleineLetters.isSelected())
{
if (hulp2.equals(hulp))
{
nummers.addElement(new Integer(i));
}
}
else
{
if (hulp2.equalsIgnoreCase(hulp))
{
nummers.addElement(new Integer(i));
}
}
hulp2="";
}
}
catch(NullPointerException n)
{
System.err.println("NullPointerException: "+ n);
}

if (nummers.size()>0)
{
int keuze = 0;
if (omhoog.isSelected())
{
for (int i=0;i<=(nummers.size()-1);i++)
{
keuze = JOptionPane.showConfirmDialog(this,"Wenst u de volgende te zoeken?","Keuze om verder te zoeken.",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);
browser.selecteerString(((Integer)nummers.elementAt( i )).intValue(),((Integer)nummers.elementAt( i )).intValue() + hulp.length()); if (keuze == JOptionPane.CANCEL_OPTION && i != (nummers.size()-1))
{
i = nummers.size()-1;
JOptionPane.showMessageDialog(this, "U wenst te stoppen met het zoeken naar "+hulp+".","Be?indigen zoeken",JOptionPane.INFORMATION_MESSAGE);
}
else
{
if (i == (nummers.size()-1))
JOptionPane.showMessageDialog(this, hulp+" komt verder niet voor in de tekst", "Zoekactie gedaan",JOptionPane.INFORMATION_MESSAGE);
}
}
}
else
{
for (int i=(nummers.size()-1);i>=0;i--)
{
keuze = JOptionPane.showConfirmDialog(this,"Wenst u de volgende te zoeken?","Keuze om verder te zoeken.",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);
browser.selecteerString(((Integer)nummers.elementAt( i )).intValue(),((Integer)nummers.elementAt( i )).intValue() + hulp.length());
if (keuze == JOptionPane.CANCEL_OPTION && i !=0)
{
i = 0;
JOptionPane.showMessageDialog(this, "U wenst te stoppen met het zoeken naar "+hulp+".","Be?indigen zoeken",JOptionPane.INFORMATION_MESSAGE); }
else
{
if (i == 0)
JOptionPane.showMessageDialog(this, hulp+" komt verder niet voor in de tekst", "Zoekactie gedaan",JOptionPane.INFORMATION_MESSAGE);
}
}
}

}
else
{
JOptionPane.showMessageDialog(null,hulp+ " komt niet voor op deze html-pagina","Komt niet voor",JOptionPane.INFORMATION_MESSAGE);
this.setVisible(false);
}
}
private void sluiten()
{
this.setVisible(false);
}
public void veranderKleur(Color kleur)
{
this.setBackground(kleur);
}
public void veranderKleurKnoppen(Color kleur)
{
annuleren.setBackground(kleur);
bevestigen.setBackground(kleur);
}
public void test()
{
try
{
for(int i =0; i<6912;i++)
{
browser.selecteerString(i,i + 10);

System.out.print(tekst.charAt(i));
}
}
catch(NullPointerException neke)
{
System.err.println("NullPointerException"+ neke);

}
}
}



Can anyone help me plz?

Stefan Parijs

Parijs_stefan@yahoo.com

Topic: the Class class Previous Topic   Next Topic Topic: java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use