Opening a HTML file through GUI

Hi guys I am new to java and HTML and now I need to open a HTML file which is saved on disk and search for a word my code is as shown below.......
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class Test_Find extends JFrame {
    public Test_Find() {
        initComponents();
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        textarea.setText(initialText);
        textarea.setCaretPosition(0);
        setVisible(true);
        textarea.requestFocusInWindow();
    private void initComponents() {
        scrollTextarea = new JScrollPane();
        textarea = new JTextArea();
        toolbar = new JToolBar();
        findB = new JButton();
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setTitle("Test Find");
        scrollTextarea.setViewportView(textarea);
        getContentPane().add(scrollTextarea, BorderLayout.CENTER);
        toolbar.setFloatable(false);
        findB.setText("Find");
        findB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                findBActionPerformed(evt);
        toolbar.add(findB);
        getContentPane().add(toolbar, BorderLayout.NORTH);
    private void findBActionPerformed(ActionEvent evt) {
        String input = JOptionPane.showInputDialog(
                "Find what:", pattern);
        if(input==null){
            input="";
        pattern=input;
        doFind();
    private int doFind(){
        textarea.requestFocusInWindow();
        currentCaretPosition = textarea.getCaretPosition();
        text = textarea.getText();
        if(!pattern.equals("")){
            int pos=0;
            pos = text.toLowerCase().indexOf(pattern.toLowerCase(), currentCaretPosition);
            if(pos>-1){
                scrollTextarea.getHorizontalScrollBar().setValue(0);
                textarea.setCaretPosition(pos+pattern.length());
                highlight(textarea, pattern);
                return 1;//found
        }else{
            removeHighlights(textarea);
            return 0;//no pattern
        return -1;//not found
    // Creates highlights around all occurrences of pattern in textComp
    public void highlight(JTextComponent textComp, String pattern) {
        // First remove all old highlights
        removeHighlights(textComp);
        try {
            Highlighter hilite = textComp.getHighlighter();
            Document doc = textComp.getDocument();
            String text = doc.getText(0, doc.getLength());
            int pos = 0;
            // Search for pattern
            while ((pos = text.toLowerCase().indexOf(pattern.toLowerCase(), pos)) >= 0) {
                // Add highlight around pattern using private painter
                hilite.addHighlight(pos, pos+pattern.length(), textPainter);
                pos += pattern.length();
        } catch (BadLocationException e) {
    // Removes only our private highlights
    public void removeHighlights(JTextComponent textComp) {
        Highlighter hilite = textComp.getHighlighter();
        Highlighter.Highlight[] hilites = hilite.getHighlights();
        for (int i=0; i<hilites.length; i++) {
            if (hilites.getPainter() instanceof TextPainter) {
hilite.removeHighlight(hilites[i]);
// An instance of the private subclass of the default highlight painter
private Highlighter.HighlightPainter textPainter = new TextPainter(Color.yellow);
// A private subclass of the default highlight painter
class TextPainter extends DefaultHighlighter.DefaultHighlightPainter {
public TextPainter(Color color) {
super(color);
public static void main(String args[]) {
new Test_Find();
private String input, pattern, text;
private int currentCaretPosition;
private JButton findB;
private JScrollPane scrollTextarea;
private JTextArea textarea;
private JToolBar toolbar;
private String initialText =
"Swing JTable and JScrollPane Problem\n" +
" tlloreti 4 Jul 5, 2005 4:15 PM\n" +
"by Tom.Sanders \u00bb \n" +
"Swing CTRL-A (select all) ignored in applet\n" +
" ilmbeachgirl 4 Jul 5, 2005 4:10 PM\n" +
"by ilmbeachgirl \u00bb \n" +
"Swing drawing problem\n" +
" gnosnahz 0 Jul 5, 2005 4:09 PM\n" +
"by gnosnahz \u00bb \n" +
"Java Event Handling events effecting panels in multiple tabs\n" +
" sean_hagen 1 Jul 5, 2005 4:06 PM\n" +
"by es5f2000 \u00bb \n" +
"Swing Searching text in files & highlighting that text\n" +
" sketty 1 Jul 5, 2005 3:57 PM\n" +
"by camickr \u00bb \n" +
"Swing JTextField displaying prtially its contents\n" +
" SreeJay 1 Jul 5, 2005 3:55 PM\n" +
"by camickr \u00bb \n" +
"Swing how to get BufferedImage of a JPanel\n" +
" praveen.Arora 1 Jul 5, 2005 3:53 PM\n" +
"by camickr \u00bb \n" +
"Swing Creating a form from a xml schema..\n" +
" zoltern 0 Jul 5, 2005 3:51 PM\n" +
"by zoltern \u00bb \n" +
"Swing Da Suckers: Java and Windows XP\n" +
" [email protected] 1 Jul 5, 2005 3:42 PM\n" +
"by [email protected] \u00bb \n" +
"Java 2D Rescaling using JAI\n" +
" G-Rehuku 0 Jul 5, 2005 3:30 PM\n" +
"by G-Rehuku \u00bb \n" +
"Swing how to get Page Preview of multiple page JPanel\n" +
" Sonu.Arora 0 Jul 5, 2005 2:20 PM\n" +
"by Sonu.Arora \u00bb \n" +
"Swing IDE for Swing Development\n" +
" JavaEnthusiastt 8 Jul 5, 2005 2:17 PM\n" +
"by uhrand \u00bb \n" +
"Java 2D Can't connect to X11 window server\n" +
" kusigubi 0 Jul 5, 2005 2:06 PM\n" +
"by kusigubi \u00bb \n";
}Since I am new to the field requesting the kind quick help by java experts here to help me change the code so that I would be able to search a web apge saved on disk and search and highlight a word in that page ....
Thanks in advance........
Looking forward for your kind suggestions.......                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Since I am new to the field requesting the kind quick help by java experts here to help me change the code so that I would be able to search a web apge saved on disk and search and highlight a word in that page ....
Thanks in advance........
Looking forward for your kind suggestions......1) Did you write that code? If yes, proceed to 2). If no, I charge 150 euros/hr. Let me know when you want me to start.
2) Post the code for a program that opens a text file with the following in it:
hello world
and prints the contents out using System.out.println().
3) Modify the program in 2) to determine if the file contains the word "yes". Post the code.
4) An html file is no different than the text file in 2).

Similar Messages

  • FF16.02: opens webpage HTML file as code instead of webpage, seems to save as temporary .txt instead of html.

    Hi,
    I'm using FF 16.0.2
    I have to open a link/attachment on a webpage that is a .html file.
    When I click open, regardless of what software I use to do so: OpenOffice, IE, FF, notepad, wordpad - only HTML code is seen. This is what I assume to be because of what "jscher2000" mentioned - the URL is converted into a HTML.txt file.
    Notably, if I go to the website on IE and open the HTML file through it, it works no problem. I have tried disabling addons.
    I have been looking for fixes & addons to go around this problem, but none so far. First time posting!

    See my answer here: [[/questions/930461#answer-378263]]

  • Opening additional html file in same broswer window

    Hi here is what i wasnt to do i will write the whole process in sequence to make it clear.
    1. write to html file [accomplished]
    2. open html file from GUI in browser window [accomplished]
    3. rewrite html file from within GUI [accomplished]
    4. reopening the html file in the SAME browser window [the problem]
    Any one know if this is possible?
    here is the code im using to open the initial window...
    Process proc = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler results.html");

    Ok heres what im doing...
    im using googles api..and in my GUI i have a "Next 10
    results" button, i could refresh the page X amount of
    seconds but this isnt really ideal.
    But looks like that is what im gonna have to to do
    ...unless anyone else has any better suggestions?
    (ps. i dont want to go down the JEditorPane path....
    =] )Well then if you dont want to refresh the page, then you can have 2 pages.. The second page would be just this
    <body>
    </body>And include this HTML in the main one using a iframe like this
    <iframe src="XXX.html" width="0" height="0"></iframe>When the user clicks the next button, you have to write 2 HTML this time.. The second one(XXX.html) would have the following code now
    <body>
    <script>
    parent.window.location.reload();
    </script>
    </body>Just confirm the 'parent' one.. I am not that sure whether its parent or parent_...
    Cheers
    -P

  • Open an html file inside spry collapsible panel

    Greetings,
    Using CS5
    Does anyone know the CSS code/possibility of opening an html file inside the Spry panel?
    I've tried the following code:
    .CollapsiblePanelContent {
        background-image: url(lookoutgraph.html);
    Is there a better CSS element for calling up an html file?
    For what it's worth...the html file I'm tring to open uses a <canvas> tag. When opened by itself, the html file has no problem opening and displaying the canvas data.
    Much Thanks!

    With the exeption of images, to add external content to a document you will need to make use of either serverside or clientside code.
    Have a look at the SpryHTMLPanel here http://labs.adobe.com/technologies/spry/samples/htmlpanel/html_panel_sample.html
    Otherwise, please supply a link to your site so that we can come up with alternatives.
    Gramps

  • Open an HTML file from a SAP Report

    Hi all!
    I would like to open an HTML file, that`s in a local directory of my PC, from a SAP Report.
    It is an alv list, where I have added a pushbotton. And I would like to code the utility of open a local html file, when someone push it.
    Anybody knows if it is possible?
    Thx

    Here is some sample code.
    report zrich_0002.
    call method cl_gui_frontend_services=>execute
      EXPORTING
        DOCUMENT               = 'C:test.html'
    *    APPLICATION            =
    *    PARAMETER              =
    *    DEFAULT_DIRECTORY      =
    *    MAXIMIZED              =
    *    MINIMIZED              =
    *    SYNCHRONOUS            =
    *  EXCEPTIONS
    *    CNTL_ERROR             = 1
    *    ERROR_NO_GUI           = 2
    *    BAD_PARAMETER          = 3
    *    FILE_NOT_FOUND         = 4
    *    PATH_NOT_FOUND         = 5
    *    FILE_EXTENSION_UNKNOWN = 6
    *    ERROR_EXECUTE_FAILED   = 7
    *    others                 = 8
    if sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    Please remember to award points accordingly and mark this post as solved when you problem is solved.  Thanks.
    Also, Welcome to SDN!!
    Regards,
    Rich Heilman

  • Opening a pdf file through form 10g

    Dear all,
    I have requirement to open a pdf file through my form application.
    Ho will i do this?
    What is the procedure to do this??
    Please help me.
    Regards

    Can you tell me where the pdf can be found. Through a webserver or inside the database or is the pdf somewhere else?
    If the pdf is available through an url you could use web.show_document which can open the url/pdf document in a new browser window.
    If the pdf is inside the database you could download the pdf to the client using webutil and then open the pdf document using a host command.
    If the pdf is inside the database or by a url you can also use a forms bean. I've used forms bean bean to unload a pdf from the database and show it inside the forms application. Most important when using a forms bean is that the bean component can show all the fonts which are used inside the pdf. There are some free solutions which can not show i.e. bar codes. The are also some paid components which will do the trick.
    Regards,
    Mark

  • Open my html file and cannot edit it

    When I open my html file from Flash, in view design all I get is a grey box with the Flash symbol in the middle and no html tools.
    I want to link some of my buttons but if I go into view live I get html tools but I still can't access them to make links.
    How do I get my html page so that I can make my links?
    Forrest

    Your next button can still do that.  But it has to be programmed within Flash.  Flash files are not natively handled by Dreamweaver.  You have to export them in order to place them on a website within Dreamweaver.
    The only way that Dreamweaver can do this for you is if you create a button in Dreamweaver which does this action for you outside of the Flash area.  Then this button can link to another page or Flash file.  But if the button resides within the Flash file then it must be edited with Flash.

  • Help Needed in opening a HTML File from swing application

    Hi,
    I am opening a HTML file in Internet Explorer from my swing application.
    I am using the code given below
    private final static String WIN_FLAG = "url.dll,FileProtocolHandler";
    private final static String WIN_PATH = "rundll32";
    String cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
    // url is HTML file Path
    Process p = Runtime.getRuntime().exec( cmd );
    The HTML file is opening up,but it always opens behind the swing application,that makes me every time to maximize the HTML file after it being opened up.
    I want to open it in front of the Swing Application.
    Any Help Please ?
    - Manikandan

    Check your Application's JFrame properties (may be ur Frame is set to be in top position ,always),and also check running your application in some other OS.

  • How do I Open an HTML file for iOS?

    How do I open an HTML file for iOS using acrobat?

    This is a forum for Adobe Reader for iOS. Acrobat doesn't run on iOS. You need to run it on a Mac or Windows computer. In Acrobat, you can choose File > Create > PDF from Web Page to do what you want. You cannot do that in iOS.

  • Opening an HTML file stored locally

    Hello fellows,
    Is it possible to open a locally stored HTML file using  Acro javascript?
    If, yes, how to make Acrobat/Reader open the HTML file only once, when the rights-enabled PDF is opened for the 1st time?
    Thank you for your responses in advance!

    Reader cannot open HTML files even manually. You can use JavaScript in Acrobat to convert an HTML file to PDF, but only from a privileged context: http://livedocs.adobe.com/acrobat_sdk/11/Acrobat11_HTMLHelp/JS_API_AcroJS.89.164.html

  • How do I reinstall iWeb 3.0.3?  I inadvertently opened an html file of my website and tried to open it with iWeb '09. I get a message saying "Can't open file" etc., etc. I've tried reinstalling the updated version. Iweb will not open.

    How do I reinstall iWeb 3.0.3?  I inadvertently opened an html file of my website and tried to open it with iWeb '09. I get a message saying “Can’t open file” etc., etc. I’ve tried reinstalling the updated version. Iweb will not open.

    Delete the iWeb preference file, com.apple.iWeb.plist, that resides in your Home/Library/Preferences folder. Then launch iWeb and see if it opens. 
    What happened was trying to open the html file reset the file path that iWeb saves in its preference file to tell it where to go when you launch iWeb.  Deleting the pref file and launching iWeb creates a new file and iWeb looks in your Users/Home/Library/Application Support/iWeb folder for the Domain.sites2 file it uses to create your site.
    OT

  • When i open any .HTML file from my computer it is not opening in firefox. Only a blank New Window Opens. Facing this problem since the firefox has updated.

    Whenever i try to open any HTML file from my computer, it opens a new firefox window which is blank. Facing this problem after the new update. please fix this problem

    I found that after Firefox v29, a LOT of my settings and<BR>
    add-ons were changed / reset. Try this;
    '''''[https://support.mozilla.org/en-US/kb/troubleshoot-firefox-issues-using-safe-mode Start Firefox in Safe Mode]'''''
    <BR>While you are in safe mode;<BR>
    '''''Firefox Options > Advanced > General'''''.<BR>
    Look for and turn off '''Use Hardware Acceleration'''.<BR>
    Then check ALL of your settings. Browser and add-ons. Then restart.

  • Recently opening an HTML file on my computer makes firefox attempt a search for the entire file name in the search engine online, how to do i correct that?

    when opening an HTML file recently my Firefox automatically opens up a yahoo search screen and the file, the entire file name and route for the file is searched for online. I don't even use Yahoo Search i use Google but that doesn't mater have to open the file manually with searching it on on the open screen to read it because it's trying to search for it online instead of reading it from where i clicked on it.
    I.E.
    file:///F:/Reading/II.html
    would try to search
    https://us.search.yahoo.com/yhs/search?hspart=aztec&hsimp=yhs-default&type=derr_100_476&p=file%3A%2F%2F%2FF%3A%2FReading%2Fhtml&rnd=737753354&param1=sid%3D476%3Aaid%3D100%3Aver%3D15005%3Atm%3D264%3Asrc%3Dderr%3Alng%3Den%3Aitype%3Da%3Auip%3D1124173343
    I have no idea what the
    &rnd=737753354&param1=sid%3D476%3Aaid%3D100%3Aver%3D15005%3Atm%3D264%3Asrc%3Dderr%3Alng%3Den%3Aitype%3Da%3Auip%3D1124173343
    is for but it's never done this before.

    Please read this article about restoring bookmarks:
    http://kb.mozillazine.org/Lost_bookmarks
    As far as your passwords are concerned, I don't think there's anything you can do. But for the future, you can use the following add-ons to avoid any future loss:
    https://addons.mozilla.org/en-US/firefox/addon/2848/
    or
    http://www.xmarks.com/
    Both are good.
    And a simple way to import your bookmarks (since you already saved it on your desktop as html) is:
    Bookmarks / Organized Bookmarks / Import and Export
    Good luck.

  • Opening local .html files on iPad

    I have created a personal homepage that I have loaded on my Macs at home. Any way I can use this file on my iPad 3?

    It is possible to open local HTML files in Safari on iPad2. Easy!
    Open your Safari.
    Touch Bookmark icon for a little while.
    A dialogue box appears with "/var/Mobile" title.
    Go to "Applications" > your app (iFile, GoodReade or whatever yours) > Documents.
    And you are there. Open your HTML files.
    Now you can go anywhere to and fro without problem.
    It is FTP:///.
    If need later, Bookmark that.
    With Loving-Kindness!
    bhikkhusirin

  • I have opened two versions of Firefox (v3.6.18 and v3.5), v3.6.18 is my default browser. The problem comes after an attempt to open a HTML file.

    I have opened two versions of Firefox (v3.6.18 and v3.5), v3.6.18 is my default browser. The problem comes after an attempt to open a HTML file. An error appears: "Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart your system." Why wouldn't it just open on my default browser? Thanks for the help!

    A possible cause is security software (firewall) that blocks or restricts Firefox without informing you about that, maybe after detecting changes (update) to the Firefox program.
    Remove all rules for Firefox from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox.
    See [[Firewalls]] and http://kb.mozillazine.org/Firewalls
    http://kb.mozillazine.org/Browser_will_not_start_up

Maybe you are looking for