Results 1 to 10 of 10
  1. #1
    Nathan's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    In a magical place
    Posts
    6,113
    Reputation
    394
    Thanks
    363

    Cookie's Shitty Webbrowser

    I couldn't post this in the webbrowser thread.
    So I'll post it here.

    It's not good, it doesn't support a lot.

    But here you go

    Code:
    import javax.swing.*;
    import javax.swing.event.HyperlinkEvent;
    import javax.swing.event.HyperlinkListener;
    import javax.swing.text.html.HTMLDocument;
    import javax.swing.text.html.HTMLFrameHyperlinkEvent;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.net.URL;
    import java.util.ArrayList;
    
    /**
     * Created by IntelliJ IDEA.
     * User: Nathaniel
     * Date: 8/31/11
     * Time: 5:57 PM
     * To change this template use File | Settings | File Templates.
     */
    
    public class Browser extends JFrame implements HyperlinkListener {
        private ArrayList pageList = new ArrayList();
    
        private JTextField address;
        private JButton go;
        private JButton back;
        private JButton next;
        private JScrollPane scrollPane1;
        private JEditorPane body;
    
    
        public static void main(String[] args) {
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        try {
                            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                        } catch (Exception e) {
                        }
                        Browser g = new Browser();
                        g.setVisible(true);
                    }
                });
            } catch (Exception ex) {
            }
        }
    
        public Browser() {
            address = new JTextField();
            go = new JButton();
            back = new JButton();
            next = new JButton();
            scrollPane1 = new JScrollPane();
            body = new JEditorPane();
            Container contentPane = getContentPane();
            go.setText("Go");
            back.setText("<");
            next.setText(">");
            {
                body.setContentType("text/html");
                scrollPane1.setViewportView(body);
            }
    
            GroupLayout contentPaneLayout = new GroupLayout(contentPane);
            contentPane.setLayout(contentPaneLayout);
            contentPaneLayout.setHorizontalGroup(
                    contentPaneLayout.createParallelGroup()
                            .addGroup(contentPaneLayout.createSequentialGroup()
                                    .addContainerGap()
                                    .addGroup(contentPaneLayout.createParallelGroup()
                                            .addComponent(scrollPane1, GroupLayout.DEFAULT_SIZE, 597, Short.MAX_VALUE)
                                            .addGroup(contentPaneLayout.createSequentialGroup()
                                                    .addComponent(back, GroupLayout.PREFERRED_SIZE, 43, GroupLayout.PREFERRED_SIZE)
                                                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                                    .addComponent(next)
                                                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                                    .addComponent(address, GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
                                                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                                    .addComponent(go)))
                                    .addContainerGap())
            );
            contentPaneLayout.setVerticalGroup(
                    contentPaneLayout.createParallelGroup()
                            .addGroup(contentPaneLayout.createSequentialGroup()
                                    .addContainerGap()
                                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                            .addComponent(back)
                                            .addComponent(next)
                                            .addComponent(address, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
                                            .addComponent(go))
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(scrollPane1, GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
                                    .addContainerGap())
            );
            pack();
            setLocationRelativeTo(getOwner());
            setTitle("Cookie's Java Browser");
            back.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if (pageList.size() > 1) {
                        URL currentUrl = body.getPage();
                        int pageIndex = pageList.indexOf(currentUrl.toString());
                        try {
                            showPage(new URL((String) pageList.get(pageIndex - 1)), false);
                        } catch (Exception ex) {
                        }
                    }
                }
            });
            next.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    URL currentUrl = body.getPage();
                    int pageIndex = pageList.indexOf(currentUrl.toString());
                    if (pageList.get(pageIndex + 1) != null) {
                        try {
                            showPage(new URL((String) pageList.get(pageIndex + 1)), false);
                        } catch (Exception ex) {
                        }
                    }
                }
            });
            go.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    URL url = verifyUrl(address.getText());
                    if (url != null) {
                        showPage(url, true);
                    } else {
                        showError("Invalid URL");
                    }
                }
            });
        }
    
        private void showPage(URL pageUrl, boolean addToList) {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            try {
                URL currentUrl = body.getPage();
                body.setPage(pageUrl);
                URL newUrl = body.getPage();
                if (addToList) {
                    int listSize = pageList.size();
                    if (listSize > 0) {
                        int pageIndex = pageList.indexOf(currentUrl.toString());
                        if (pageIndex < listSize - 1) {
                            for (int i = listSize - 1; i > pageIndex; i--) {
                                pageList.remove(i);
                            }
                        }
                    }
                    pageList.add(newUrl.toString());
                }
                address.setText(newUrl.toString());
            } catch (Exception e) {
            } finally {
                setCursor(Cursor.getDefaultCursor());
            }
        }
    
        public void hyperlinkUpdate(HyperlinkEvent event) {
            HyperlinkEvent.EventType eventType = event.getEventType();
            if (eventType == HyperlinkEvent.EventType.ACTIVATED) {
                if (event instanceof HTMLFrameHyperlinkEvent) {
                    HTMLFrameHyperlinkEvent linkEvent = (HTMLFrameHyperlinkEvent) event;
                    HTMLDocument document = (HTMLDocument) body.getDocument();
                    document.processHTMLFrameHyperlinkEvent(linkEvent);
                } else {
                    showPage(event.getURL(), true);
                }
            }
        }
    
        private void showError(String errorMessage) {
            JOptionPane.showMessageDialog(this, errorMessage, "Error", JOptionPane.ERROR_MESSAGE);
        }
    
        private URL verifyUrl(String url) {
            if (!url.toLowerCase().startsWith("https://"))
                return null;
            URL verifiedUrl = null;
            try {
                verifiedUrl = new URL(url.toLowerCase());
            } catch (Exception e) {
                return null;
            }
            return verifiedUrl;
        }
    }

  2. #2
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Screenshot pl0x ? I don't haz java but I'd like to see what it looks like.

  3. #3
    Threadstarter
    Still a Cookie at heart
    Donator
    Nathan's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    In a magical place
    Posts
    6,113
    Reputation
    394
    Thanks
    363

  4. #4
    Threadstarter
    Still a Cookie at heart
    Donator
    Nathan's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    In a magical place
    Posts
    6,113
    Reputation
    394
    Thanks
    363
    @Hassan, you wanted a screenshot, so now you're gonna look at it and say what you think






  5. #5
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    This is so awesome.

  6. #6
    Lehsyrus's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    Jersey
    Posts
    10,893
    Reputation
    1281
    Thanks
    3,130
    That browser's fucking beast!

  7. #7
    Threadstarter
    Still a Cookie at heart
    Donator
    Nathan's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    In a magical place
    Posts
    6,113
    Reputation
    394
    Thanks
    363
    Quote Originally Posted by Lehsyrus View Post
    That browser's fucking beast!
    I know right

  8. #8
    Jakob's Avatar
    Join Date
    Feb 2011
    Gender
    male
    Posts
    4,721
    Reputation
    237
    Thanks
    510
    My Mood
    Psychedelic
    Quote Originally Posted by Cookie. View Post
    Wow, nice bro!

  9. #9
    Velocity's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    Usa
    Posts
    4,375
    Reputation
    106
    Thanks
    773
    java musnt be very good for browser development....
    this can be done in visual basic in 10 minutes.

    no offence.

  10. #10
    Shakugan no Shana's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Posts
    5,213
    Reputation
    176
    Thanks
    830
    My Mood
    Pensive
    Quote Originally Posted by Velocity View Post
    java musnt be very good for browser development....
    this can be done in visual basic in 10 minutes.

    no offence.
    It's a high level language tard. Java is lower and you have to write the GUI yourself (which accounts for most of his code). VB.NET = drag and drop.

  11. The Following User Says Thank You to Shakugan no Shana For This Useful Post:

    RYkEt (11-24-2011)

Similar Threads

  1. Cookies 4 Everyone
    By AthlaS in forum Spammers Corner
    Replies: 18
    Last Post: 02-25-2007, 11:46 AM
  2. Cookies
    By Severed in forum Spammers Corner
    Replies: 7
    Last Post: 12-11-2006, 05:34 PM
  3. cookie stealing
    By ace76543 in forum Game Hacking Tutorials
    Replies: 6
    Last Post: 08-31-2006, 12:28 AM
  4. My Very(shitty) First Sig
    By EleMentX in forum Art & Graphic Design
    Replies: 21
    Last Post: 05-24-2006, 01:25 AM
  5. Shitty Programs
    By Dave84311 in forum General
    Replies: 5
    Last Post: 05-20-2006, 02:55 AM