package webbrowser; import java.util.*; import java.awt.*; import java.awt.event.*; import java.awt.event.MouseListener; import java.net.*; import java.io.*; import javax.swing.*; import javax.swing.event.*; import java.awt.datatransfer.*; import javax.swing.text.html.*; import javax.swing.UIManager; import javax.swing.SwingUtilities; class Main extends JFrame implements ActionListener{ public JPanel addressPanel,descriptionPanel,buttonPanel,socialPanel,siPanel; public JButton Home,Stop,Reload,backPage,forwardPage,bookmarks,facebook,twitter,gmail,yahoo,cricinfo,bbc,Openfile,cutbutton,copybutton,pastebutton,sourcebutton,historybutton,infobutton; public JButton blockbutton,unblockbutton,bpbutton,passbutton; public JTextField address,searchHere; public JComboBox Combo; public JEditorPane contents; public JLabel description,l1; public String[] searchItem={"Bing","Ask.com","Yahoo","Amazon.com","Answer.com","eBay","Wikipedia"}; final String key="http://"; Clipboard clip = getToolkit().getSystemClipboard(); public String str,copiedStr; JMenu skins,file,edit,view,history,bookmark,tool,help,security; JSeparator js1; File saveas; private String newtxtad=""; JMenuItem winlook = new JMenuItem("Windows"); JMenuItem unixlook = new JMenuItem("Motif"); JMenuItem nimbuslook= new JMenuItem("Nimbus"); Stack<String> backLog=new Stack<String>(); Stack<String> forLog=new Stack<String>(); boolean backButtonClicked=false; boolean forwardButtonClicked=false; boolean copyClicked=false; boolean addressClicked=false,searchHereClicked=false; int flag2=0; int search=0; int index = 0; String a[]; int bookmarkIndex=0; boolean bookmarkFlag=false; /***************************************CONSTRUCTOR*************************************************/ public Main(){ setLocation(100,80); setTitle("Infinity Web Browser"); setSize(new Dimension(1000,600)); setDefaultCloseOperation(EXIT_ON_CLOSE); try { UIManager.setLookAndFeel ("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); updater(); } catch(Exception e) {} MouseKarikuri Mouse = new MouseKarikuri(); int i; ImageIcon backIcon=new ImageIcon("Back.png"); ImageIcon forwardIcon=new ImageIcon("next.png"); ImageIcon stopIcon=new ImageIcon("Delete.png"); ImageIcon reloadIcon=new ImageIcon("refresh.png"); ImageIcon homeIcon=new ImageIcon("home.png"); ImageIcon bookmarkIcon=new ImageIcon("star.png"); ImageIcon facebookIcon=new ImageIcon("facebook.png"); ImageIcon twitterIcon=new ImageIcon("twitter.png"); ImageIcon gmailIcon=new ImageIcon("Gmail.png"); ImageIcon yahooIcon=new ImageIcon("yahoo.png"); ImageIcon cricinfoIcon=new ImageIcon("cricinfo.png"); ImageIcon bbcIcon=new ImageIcon("bbc.png"); addressPanel=new JPanel(); siPanel=new JPanel(); JPanel head=new JPanel(); head.setLayout(new FlowLayout()); buttonPanel=new JPanel(); socialPanel= new JPanel(); head.add(buttonPanel,BorderLayout.WEST); head.add(socialPanel,BorderLayout.EAST); buttonPanel.setBackground(Color.LIGHT_GRAY); socialPanel.setBackground(Color.LIGHT_GRAY); ImageIcon ofIcon=new ImageIcon("File1.png"); ImageIcon cutIcon=new ImageIcon("Cut1.png"); ImageIcon copyIcon=new ImageIcon("Copy1.png"); ImageIcon pasteIcon=new ImageIcon("paste1.png"); ImageIcon sourceIcon=new ImageIcon("Document1.png"); ImageIcon historyIcon=new ImageIcon("history1.png"); ImageIcon asIcon=new ImageIcon("Info1.png"); ImageIcon blockIcon=new ImageIcon("block.png"); ImageIcon unblockIcon=new ImageIcon("Unblock.png"); ImageIcon blockpageIcon=new ImageIcon("delete_page.png"); ImageIcon passIcon=new ImageIcon("lock1.png"); Openfile=new JButton(ofIcon); Openfile.setToolTipText("Open File"); Openfile.addActionListener(this); cutbutton=new JButton(cutIcon); cutbutton.setToolTipText("Cut"); cutbutton.addActionListener(this); copybutton=new JButton(copyIcon); copybutton.setToolTipText("Copy"); copybutton.addActionListener(this); pastebutton=new JButton(pasteIcon); pastebutton.setToolTipText("Paste"); pastebutton.addActionListener(this); sourcebutton=new JButton(sourceIcon); sourcebutton.setToolTipText("Source code"); sourcebutton.addActionListener(this); historybutton=new JButton(historyIcon); historybutton.setToolTipText("History"); historybutton.addActionListener(this); infobutton=new JButton(asIcon); infobutton.setToolTipText("Information"); infobutton.addActionListener(this); blockbutton=new JButton(blockIcon); blockbutton.setToolTipText("Block Web Page"); blockbutton.addActionListener(this); unblockbutton=new JButton(unblockIcon); unblockbutton.setToolTipText("Unblock Web Page"); unblockbutton.addActionListener(this); bpbutton=new JButton(blockpageIcon); bpbutton.setToolTipText("View Blocked Pages"); bpbutton.addActionListener(this); passbutton=new JButton(passIcon); passbutton.setToolTipText("Reset Password"); passbutton.addActionListener(this); siPanel.add(Openfile); siPanel.add(cutbutton); siPanel.add(copybutton); siPanel.add(pastebutton); siPanel.add(sourcebutton); siPanel.add(historybutton); siPanel.add(infobutton); siPanel.add(blockbutton); siPanel.add(unblockbutton); siPanel.add(bpbutton); siPanel.add(passbutton); Openfile.setBackground(Color.lightGray); cutbutton.setBackground(Color.lightGray); copybutton.setBackground(Color.lightGray); pastebutton.setBackground(Color.lightGray); sourcebutton.setBackground(Color.lightGray); historybutton.setBackground(Color.lightGray); infobutton.setBackground(Color.lightGray); blockbutton.setBackground(Color.lightGray); unblockbutton.setBackground(Color.lightGray); bpbutton.setBackground(Color.lightGray); passbutton.setBackground(Color.lightGray); backPage=new JButton(backIcon); backPage.setToolTipText("Click to go back"); backPage.setBounds(10,02,40,35); if(backLog.size()<=1) backPage.setEnabled(false); backPage.addActionListener(this); forwardPage=new JButton(forwardIcon); forwardPage.setToolTipText("Click to go forward"); forwardPage.setBounds(60,02,40,35); if(forLog.size()==0)forwardPage.setEnabled(false); forwardPage.addActionListener(this); Reload=new JButton(reloadIcon); Reload.setToolTipText("Reload this page"); Reload.addActionListener(this); Stop=new JButton(stopIcon); Stop.setToolTipText("Stop this page"); Stop.addActionListener(this); Home=new JButton(homeIcon); Home.setToolTipText("Open the Home page"); Home.addActionListener(this); bookmarks=new JButton(bookmarkIcon); bookmarks.setToolTipText("Bookmark this page"); bookmarks.addActionListener(this); facebook=new JButton(facebookIcon); facebook.setToolTipText("Open Facebook"); facebook.addActionListener(this); twitter=new JButton(twitterIcon); twitter.setToolTipText("Open Twitter"); twitter.addActionListener(this); gmail=new JButton(gmailIcon); gmail.setToolTipText("Open Gmail"); gmail.addActionListener(this); yahoo=new JButton(yahooIcon); yahoo.setToolTipText("Open Yahoo Mail"); yahoo.addActionListener(this); cricinfo=new JButton(cricinfoIcon); cricinfo.setToolTipText("Open Cricinfo"); cricinfo.addActionListener(this); bbc=new JButton(bbcIcon); bbc.setToolTipText("Read latest news"); bbc.addActionListener(this); buttonPanel.add(backPage); buttonPanel.add(forwardPage); buttonPanel.add(Reload); buttonPanel.add(Stop); buttonPanel.add(Home); buttonPanel.add(bookmarks); socialPanel.add(facebook); socialPanel.add(twitter); socialPanel.add(gmail); socialPanel.add(yahoo); socialPanel.add(cricinfo); socialPanel.add(bbc); Font font=new Font("Georgia",Font.PLAIN,18); l1=new JLabel(" Web Address :"); l1.setFont(font); addressPanel.add(l1); address=new JTextField(30); address.setSize(2000,10); address.setText("Enter Address Here"); address.setFont(font); address.addActionListener(this); address.addMouseListener(Mouse); addressPanel.add(address); Combo=new JComboBox(); Combo.addActionListener(this); for(i=0;i<searchItem.length;i++) Combo.addItem(searchItem[i]); addressPanel.add(Combo); Combo.setEditable(true); searchHere=new JTextField(10); searchHere.setText("Search Here!!!"); searchHere.setFont(font); searchHere.addMouseListener(Mouse); searchHere.addActionListener(this); addressPanel.add(searchHere); MenuInterface(); contents = new JEditorPane(); contents.setEditable(false); LinkListener linkHandler = new LinkListener(); contents.addHyperlinkListener(linkHandler); add(new JScrollPane(contents),BorderLayout.CENTER); descriptionPanel=new JPanel(); description=new JLabel(""); descriptionPanel.add(description); Stop.setBackground(Color.lightGray); Home.setBackground(Color.lightGray); Reload.setBackground(Color.lightGray); backPage.setBackground(Color.lightGray); forwardPage.setBackground(Color.lightGray); bookmarks.setBackground(Color.lightGray); facebook.setBackground(Color.white); twitter.setBackground(Color.white); gmail.setBackground(Color.white); yahoo.setBackground(Color.white); cricinfo.setBackground(Color.white); bbc.setBackground(Color.white); Combo.setBackground(Color.white); addressPanel.setBackground(Color.black); JPanel ananta=new JPanel(); ananta.setBackground(Color.white); ananta.setLayout(new GridLayout(2,1)); ananta.add(siPanel); siPanel.setBackground(Color.white); ananta.add(addressPanel); addressPanel.setBackground(Color.gray); JPanel Shovon=new JPanel(); Shovon.setBackground(Color.white); Shovon.setLayout(new GridLayout(2,1)); Shovon.add(head); head.setBackground(Color.lightGray); Shovon.add(ananta); ananta.setBackground(Color.GRAY); add(BorderLayout.NORTH,Shovon); add(BorderLayout.SOUTH,descriptionPanel); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); pack(); } JMenuBar menuBar; JMenuItem j[]=new JMenuItem[23]; JMenuItem b[]=new JMenuItem[10]; JMenuItem r[]=new JMenuItem[10]; JMenuItem clearbook,block,setPassword,blockedPage,unblock; int recentItem; public void MenuInterface(){ menuBar=new JMenuBar(); file=new JMenu("File"); file.setMnemonic('F'); edit=new JMenu("Edit"); edit.setMnemonic('E'); view=new JMenu("View"); view.setMnemonic('V'); history=new JMenu("History"); history.setMnemonic('H'); bookmark=new JMenu("Bookmarks"); bookmark.setMnemonic('B'); tool=new JMenu("Tools"); tool.setMnemonic('T'); help=new JMenu("Help"); help.setMnemonic('I'); security=new JMenu("Security"); security.setMnemonic('S'); j[0] = new JMenuItem("Open Location"); j[0].setIcon(new ImageIcon("url.png")); j[1] = new JMenuItem("Open File"); j[1].setIcon(new ImageIcon("File.png")); j[2] = new JMenuItem("Save"); j[2].setIcon(new ImageIcon("save.png")); j[3] = new JMenuItem("Exit"); j[3].setIcon(new ImageIcon("exit.png")); j[4] = new JMenuItem("Undo");//not used j[5] = new JMenuItem("Redo");//not used j[6] = new JMenuItem("Cut"); j[6].setIcon(new ImageIcon("Cut.png")); j[7] = new JMenuItem("Copy"); j[7].setIcon(new ImageIcon("Copy.png")); j[8] = new JMenuItem("Paste"); j[8].setIcon(new ImageIcon("paste.png")); j[9] = new JMenuItem("Find");//not used j[12] = new JMenuItem("Status Bar"); j[11] = new JMenuItem("Menu Bar");//not used j[10] = new JMenuItem("Navigation Bar");//not used j[13] = new JMenuItem("Page Source"); j[13].setIcon(new ImageIcon("Document.png")); j[14] = new JMenuItem("Back"); j[14].setIcon(new ImageIcon("Backward.png")); j[14].setEnabled(false); j[15] = new JMenuItem("Forward"); j[15].setIcon(new ImageIcon("Forward.png")); j[15].setEnabled(false); j[16] = new JMenuItem("Show All History"); j[16].setIcon(new ImageIcon("history.png")); j[17] = new JMenuItem("Recent Pages"); j[18] = new JMenuItem("Bookmark This Page"); j[18].setIcon(new ImageIcon("Stars.png")); j[19] = new JMenuItem("Recently Bookmarked"); j[19].setIcon(new ImageIcon("Green.png")); j[20] = new JMenuItem("Page Info"); j[20].setIcon(new ImageIcon("Info.png")); j[21] = new JMenuItem("Clear History"); j[21].setIcon(new ImageIcon("Clear.png")); clearbook=new JMenuItem("Clear All Bookmark"); clearbook.setIcon(new ImageIcon("broom.png")); block=new JMenuItem("Block Web Page"); block.setIcon(new ImageIcon("block1.png")); unblock=new JMenuItem("Unblock Page"); unblock.setIcon(new ImageIcon("page_accept.png")); blockedPage=new JMenuItem("Blocked Pages"); blockedPage.setIcon(new ImageIcon("delete_page1.png")); setPassword=new JMenuItem("Set Password"); setPassword.setIcon(new ImageIcon("lock.png")); skins=new JMenu("Skins"); j[22] = new JMenuItem("About Us"); j[22].setIcon(new ImageIcon("Info.png")); j[22].setBackground(Color.white); js1=new JSeparator(); int k; for(k=0;k<=3;k++) file.add(j[k]); for(k=6;k<=8;k++) edit.add(j[k]); for(k=13;k<=13;k++) view.add(j[k]); for(k=14;k<=17;k++) history.add(j[k]); for(k=18;k<=19;k++) bookmark.add(j[k]); for(k=20;k<=21;k++) tool.add(j[k]); help.add(j[22]); tool.add(clearbook); tool.add(js1); tool.add(skins); security.add(block); security.add(setPassword); security.add(blockedPage); security.add(unblock); unblock.addActionListener(this); blockedPage.addActionListener(this); block.addActionListener(this); setPassword.addActionListener(this); clearbook.addActionListener(this); skins.add(winlook); skins.add(unixlook); skins.add(nimbuslook); winlook.addActionListener(this); unixlook.addActionListener(this); nimbuslook.addActionListener(this); history.addSeparator(); bookmark.addSeparator(); for(k=0;k<j.length;k++) j[k].addActionListener(this); menuBar.add(file); menuBar.add(edit); menuBar.add(view); menuBar.add(history); menuBar.add(bookmark); menuBar.add(tool); menuBar.add(help); menuBar.add(security); try{ addBookmark(); }catch(IOException e){ System.out.println("Error Reading File"); } addRecentHistory(); setJMenuBar(menuBar); } public void addBookmark()throws IOException { FileReader ff=null; try{ ff=new FileReader("bookmarkLog.txt"); }catch(FileNotFoundException e){ System.out.println("File Not Found"); } BufferedReader br=new BufferedReader(ff); String s; int i=0; while((s=br.readLine())!=null){ b[i]=new JMenuItem(s); bookmark.add(b[i]); b[i].addActionListener(this); i++; if(i>=10){ break; } } bookmarkIndex=i; ff.close(); } public void addRecentHistory(){ FileReader f=null; try{ f=new FileReader("historyLog.txt"); BufferedReader br=new BufferedReader(f); int count=0; String s=null; while((s=br.readLine())!=null)count++; f.close(); br=null; String ss[]=new String[10]; s=null; f=new FileReader("historyLog.txt"); br=new BufferedReader(f); int v=count-ss.length; for(int i=0;i<v;i++){ s=br.readLine(); } int j=0; while((s=br.readLine())!=null){ ss[j]=s; j++; } recentItem=j; j--; int k=0; while(j>=0){ r[k]=new JMenuItem(ss[j]); r[k].addActionListener(this); history.add(r[k]); k++;j--; } }catch(FileNotFoundException e){ System.out.println("File Not Found"); }catch(IOException ee){ System.out.println("Error Reading File"); } } private class MouseKarikuri implements MouseListener{ public void mousePressed(MouseEvent e) { if(e.getComponent()==address){ if(copyClicked)j[8].setEnabled(true); } else if(e.getComponent()==searchHere){ if(copyClicked)j[8].setEnabled(true); } else j[8].setEnabled(false); if(e.getComponent()==address) { if(addressClicked==false){ address.setSelectionStart(0); addressClicked=true; } else addressClicked=false; } else if(e.getComponent()==searchHere)searchHere.setSelectionStart(0); } public void mouseReleased(MouseEvent e) { if(e.getComponent()==contents){ str=contents.getSelectedText(); if(str!=null){ j[7].setEnabled(true); } else j[7].setEnabled(false); } else if(e.getComponent()==address){ str=address.getSelectedText(); if(str!=null){ j[7].setEnabled(true); } else j[7].setEnabled(false); } else if(e.getComponent()==searchHere){ str=searchHere.getSelectedText(); if(str!=null){ j[7].setEnabled(true); } else j[7].setEnabled(false); } else { j[7].setEnabled(false); } } public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mouseClicked(MouseEvent e) {} } private class LinkListener implements HyperlinkListener{ public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) showPage(event.getURL().toString()); if (event.getEventType() == HyperlinkEvent.EventType.ENTERED){ description.setText(event.getURL().toString()); } else description.setText(""); } } public void actionPerformed(ActionEvent ae){ if(ae.getSource()==address){ showPage(address.getText()); } ///********************************************************************************************************************************//// /***************************************OPEN LOCATION*************************************************/ if(ae.getSource()==j[0]) showPage(address.getText()); /***************************************OPEN*************************************************/ else if((ae.getSource()==j[1])||(ae.getSource()==Openfile)) { try { JFileChooser ch=new javax.swing.JFileChooser(); ch.setFileSelectionMode(javax.swing.JFileChooser.FILES_ONLY); int i=ch.showOpenDialog(contents); File f=ch.getSelectedFile(); contents.setPage("file:///"+f.getAbsolutePath()); } catch(Exception ec){} } /***************************************EXIT*************************************************/ else if(ae.getSource()==j[3]){ int i=JOptionPane.showConfirmDialog(this,"Do you want to exit Browser?","Web Browser",JOptionPane.OK_CANCEL_OPTION); if(i==JOptionPane.OK_OPTION) System.exit(1); } /***************************************CUT*************************************************/ else if((ae.getSource()==j[6])||(ae.getSource()==cutbutton)){ address.cut(); searchHere.cut(); } /***************************************COPY*************************************************/ else if((ae.getSource()==j[7])||(ae.getSource()==copybutton)){//copy copiedStr=str; copyClicked=true; address.copy(); } /***************************************PASTE*************************************************/ else if((ae.getSource()==j[8])||(ae.getSource()==pastebutton)){ address.paste(); } /***************************************PAGE SOURCE*************************************************/ else if((ae.getSource()==j[13])||(ae.getSource()==sourcebutton)){ JFrame pageFrame=new JFrame("SOURCE CODE"); pageFrame.setLocation(300,150); pageFrame.setSize(600,400); JTextArea pageArea=new JTextArea(); pageFrame.add(new JScrollPane(pageArea)); pageFrame.setVisible(true); float f2[]=new float[3]; Color.RGBtoHSB(211,218,237,f2); pageArea.setBackground(Color.getHSBColor(f2[0],f2[1],f2[2])); Font f=new Font("Georgia",Font.PLAIN,14); pageArea.setFont(f); try { URL PageUrl; URLConnection GetConn = null; GetConn = null; PageUrl = new URL(address.getText()); GetConn = PageUrl.openConnection(); GetConn.connect(); InputStreamReader ReadIn = new InputStreamReader(GetConn.getInputStream()); BufferedReader BufData = new BufferedReader(ReadIn); String TextFileName = ("crossword.txt"); FileWriter FWriter = new FileWriter(TextFileName); BufferedWriter BWriter = new BufferedWriter(FWriter); String UrlData = null; while ((UrlData = BufData.readLine()) != null) { BWriter.write(UrlData); BWriter.newLine(); } BWriter.close(); } catch(IOException io) { try{ FileWriter input=new FileWriter("crossword.txt"); input.write(""); input.close(); }catch(IOException e){ System.out.println(e); } //System.out.println(io); } try{ String g=null; StringBuffer sb1=new StringBuffer(""); FileReader ff1=new FileReader("crossword.txt"); BufferedReader br1=new BufferedReader(ff1); boolean flag1=true; while((g=br1.readLine())!=null) { flag1=false; sb1.append(g+'\n'); } if(flag1) sb1.append("\t\tNo Source Code Found"); pageArea.setText(sb1.toString()); pageArea.setEditable(false); ff1.close(); } catch(FileNotFoundException e){ System.out.println("File Not Found"); } catch(IOException ee){ System.out.println("File Reading Error!!!"); } } /***************************************BACK*************************************************/ else if(ae.getSource()==j[14]){ ae.setSource(backPage); return; } /***************************************FORWARD*************************************************/ else if(ae.getSource()==j[15]){ ae.setSource(forwardPage); return; } /************************************HISTORY***********************************/ else if((ae.getSource()==j[16])||(ae.getSource()==historybutton)){ JFrame histFrame=new JFrame("History"); histFrame.setSize(400,400); JTextArea histArea=new JTextArea(); histFrame.add(new JScrollPane(histArea)); histFrame.setVisible(true); histArea.setBackground(Color.gray); Font f=new Font("Georgia",Font.PLAIN,18); histArea.setFont(f); BufferedReader br=null; FileReader ff=null; try{ String s=null; StringBuffer sb=new StringBuffer(""); ff=new FileReader("historyLog.txt"); br=new BufferedReader(ff); boolean flag=true; while((s=br.readLine())!=null) { flag=false; sb.append(s+'\n'); } if(flag) sb.append("\tNo History Found"); histArea.setText(sb.toString()); histArea.setEditable(false); ff.close(); } catch(FileNotFoundException e){ System.out.println("File Not Found"); } catch(IOException ee){ System.out.println("File Reading Error!!!"); } } /******************************************BOOKMARK*********************************************/ else if(ae.getSource()==j[18]){ FileWriter f=null; if(bookmarkFlag==true) { String s=address.getText()+'\n'; char buffer[]=new char[s.length()]; s.getChars(0,s.length(),buffer,0); try{ f=new FileWriter("bookmarkLog.txt",true); f.write(buffer); f.close(); for(int i=0;i<bookmarkIndex;i++)bookmark.remove(b[i]); addBookmark(); }catch(IOException e){ System.out.println("File Error!"); } } } /***********************************PAGE INFO**************************************/ else if(ae.getSource()==j[20]){ URL hp=null; String loc,st=address.getText(); if(st.startsWith(key)==false)loc=key+st; else loc=st; System.out.println(loc); try{ hp=new URL(loc); st="Protocol: "+hp.getProtocol()+'\n'+ "Port: "+hp.getPort()+'\n'+ "Host: "+hp.getHost()+'\n'+ "File: "+hp.getFile()+'\n'+ "Ext: "+hp.toExternalForm(); contents.setText(st); }catch(MalformedURLException e){ st="Unable to Retrive Any Information"; JOptionPane.showMessageDialog(this,"Page Info:\n"+st,"Page Info",JOptionPane.INFORMATION_MESSAGE); } } /***********************************CLEAR HISTORY*************************************/ else if(ae.getSource()==j[21]){ FileWriter f=null; int i=JOptionPane.showConfirmDialog(this,"Are You Sure To Clear History?","History",JOptionPane.OK_CANCEL_OPTION); if(i==JOptionPane.CANCEL_OPTION)return; if(i==JOptionPane.CLOSED_OPTION)return; try{ f=new FileWriter("historyLog.txt"); f.write(""); f.close(); for(int p=0;p<recentItem;p++)history.remove(r[p]); }catch(FileNotFoundException e){ System.out.println("History Can't be cleared"); }catch(IOException ee){ System.out.println("History Can't be cleared"); } } /*********************************ABOUT US************************************/ else if((ae.getSource()==j[22])||(ae.getSource()==infobutton)){ String s=" Term Project \n"+ " ****WEB BROWSER**** \n"+ "Adviser: Shebuti Rayana\n"+ " Lecturer,BUET\n"+ "Programmers: Mir Tazbinur Shovon (0805040) \n"+ " Ananta Ghosh (0805041)\n"+ " For further information you can mail us at\n"+ " [email]tazbinur@gmail.com[/email]\n"+ " [email]g_ananta@hotmail.com[/email]"; JOptionPane.showMessageDialog(this,s,"About Us",JOptionPane.INFORMATION_MESSAGE); } /*****************************CLEAR BOOKMARK***************************/ else if(ae.getSource()==clearbook){ FileWriter f=null; int i=JOptionPane.showConfirmDialog(this,"Are You Sure To Clear All Bookmarks?","Bookmark",JOptionPane.OK_CANCEL_OPTION); if(i==JOptionPane.CANCEL_OPTION)return; if(i==JOptionPane.CLOSED_OPTION)return; try{ f=new FileWriter("bookmarkLog.txt"); f.write(""); f.close(); System.out.println(bookmarkIndex); for(int p=0;p<bookmarkIndex;p++)bookmark.remove(b[p]); }catch(FileNotFoundException e){ System.out.println("Bookmark Can't be cleared"); }catch(IOException ee){ System.out.println("Bookmark Can't be cleared"); } } /*****************************BLOCK PAGE*******************************/ else if((ae.getSource()==block)||(ae.getSource()==blockbutton)){ WebBlocker ob=new WebBlocker(true); } /*****************************UNBLOCK PAGE*******************************/ else if((ae.getSource()==unblock)||(ae.getSource()==unblockbutton)){ WebBlocker ob=new WebBlocker(false); } /**************************SHOW BLOCKED PAGES***************************/ else if((ae.getSource()==blockedPage)||(ae.getSource()==bpbutton)){ try{ FileReader f=new FileReader("block.txt"); BufferedReader br=new BufferedReader(f); String s=br.readLine(); if(s==null){ JOptionPane.showConfirmDialog(this,"No Blocked Pages","Page Blocker",JOptionPane.PLAIN_MESSAGE); } else{ JFrame pageFrame=new JFrame("Blocked Pages"); pageFrame.setLocation(300,150); pageFrame.setSize(600,400); pageFrame.setVisible(true); JTextArea pageArea=new JTextArea(); pageFrame.add(new JScrollPane(pageArea)); pageFrame.setVisible(true); Font ff=new Font("Georgia",Font.PLAIN,14); pageArea.setFont(ff); float f2[]=new float[3]; Color.RGBtoHSB(211,218,237,f2); pageArea.setBackground(Color.getHSBColor(f2[0],f2[1],f2[2])); pageArea.setEditable(false); StringBuffer sbuf=new StringBuffer(s+'\n'); while((s=br.readLine())!=null){ sbuf.append(s+'\n'); } pageArea.setText(sbuf.toString()); } f.close(); }catch(IOException e){ } } /***************************SET PASSWORD******************************/ else if((ae.getSource()==setPassword)||(ae.getSource()==passbutton)){ PasswordSetter ob=new PasswordSetter(); } /*****************************CLEAR BOOKMARK***************************/ else if(ae.getSource()==clearbook){ FileWriter f=null; int i=JOptionPane.showConfirmDialog(this,"Are You Sure To Clear All Bookmarks?","Bookmark",JOptionPane.OK_CANCEL_OPTION); if(i==JOptionPane.CANCEL_OPTION)return; if(i==JOptionPane.CLOSED_OPTION)return; try{ f=new FileWriter("bookmarkLog.txt"); f.write(""); f.close(); System.out.println(bookmarkIndex); for(int p=0;p<bookmarkIndex;p++)bookmark.remove(b[p]); }catch(FileNotFoundException e){ System.out.println("Bookmark Can't be cleared"); }catch(IOException ee){ System.out.println("Bookmark Can't be cleared"); } } for(int q=0;q<bookmarkIndex;q++){ if(ae.getSource()==b[q]){ showPage(b[q].getText()); } } for(int p=0;p<recentItem;p++){ if(ae.getSource()==r[p]){ showPage(r[p].getText()); } } ////*********************************************************************************************************************************////// /***************************************FOR BUTTONS*************************************************/ if(ae.getSource()==Home){ showPage("http://www.google.com"); } else if(ae.getSource()==facebook){ showPage("http://www.facebook.com"); } else if(ae.getSource()==twitter){ showPage("http://www.twitter.com"); } else if(ae.getSource()==gmail){ showPage("http://www.gmail.com"); } else if(ae.getSource()==yahoo){ showPage("http://mail.yahoo.com/"); } else if(ae.getSource()==cricinfo){ showPage("http://www.cricinfo.com/"); } else if(ae.getSource()==bbc){ showPage("http://www.bbc.co.uk"); } else if(ae.getSource()==Reload){ showPage(address.getText()); } else if(ae.getSource()==Stop){ try{ File gt=new File("C:/White.html"); if(gt.isFile() && gt.exists()) { contents.setPage(new URL("file://localhost/C:/White.html")); } else { FileWriter m=new FileWriter("C:/stop.html"); m.write("<html>"+"\n" +" <body>"+"\n" +"</body>" +"\n" +" </html> "); m.close(); contents.setPage(new URL("file://localhost/C:/stop.html")); } } catch(Exception gty){} } else if(ae.getSource()==backPage){ forLog.push(backLog.pop()); backButtonClicked=true; showPage(backLog.peek()); } else if(ae.getSource()==forwardPage){ forwardButtonClicked=true; showPage(forLog.pop()); } /*******************************Skin Updater******************************/ /********************Windows******************************/ else if(ae.getSource()==winlook){ try { UIManager.setLookAndFeel ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); updater(); } catch(Exception e) {} } /******************************Motif**********************************/ else if(ae.getSource()==unixlook){ try { UIManager.setLookAndFeel ("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); updater(); } catch(Exception e) {} } /*******************Nimbus***************/ else if(ae.getSource()==nimbuslook){ /* try { UIManager.setLookAndFeel ("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); updater(); } catch(Exception e) {}*/ try { UIManager.setLookAndFeel("com.jtattoo.plaf.hifi.HiFiLookAndFeel"); updater(); } catch (Exception e) { } } /*******************************************************************************************************************/ else if(ae.getSource()==bookmarks){ FileWriter f=null; if(bookmarkFlag==true) { String s=address.getText()+'\n'; char buffer[]=new char[s.length()]; s.getChars(0,s.length(),buffer,0); try{ f=new FileWriter("bookmarkLog.txt",true); f.write(buffer); f.close(); for(int i=0;i<bookmarkIndex;i++)bookmark.remove(b[i]); addBookmark(); }catch(IOException e){ System.out.println("File Error!"); } } } /******************************SEARCH ENGINE**********************************************/ else if(ae.getSource()==Combo){ String select = (String)Combo.getSelectedItem(); if(select.equals("Bing")) { search = 1; } if(select.equals("Ask.com")) { search = 2; } else if(select.equals("Yahoo")) { search = 3; } else if(select.equals("Amazon.com")) { search = 4; } else if(select.equals("Answer.com")) { search = 5; } else if(select.equals("eBay")) { search = 6; } else if(select.equals("Wikipedia")) { search = 7; } } else if(ae.getSource()==searchHere){ if(search == 1) // Google { String google = "http://www.bing.com/search?q="+searchHere.getText()+"&go=&form=QBLH&qs=n&sk=&sc=8-3" ; address.setText(google); showPage(google); } if(search == 2) // Ask.com { String ask = "http://www.ask.com/web?q="+searchHere.getText()+"&search=&qsrc=0&o=0&l=dir" ; address.setText(ask); showPage(ask); } if(search == 3) // Yahoo { String yahoo = "http://search.yahoo.com/search?p="+searchHere.getText()+"&fr=yfp-t-501&toggle=1&cop=mss&ei=UTF-8" ; address.setText(yahoo); showPage(yahoo); } if(search == 4) // Amazon { String amazon = "http://www.amazon.com/s/192-2503304-2985467?ie=UTF8&tag=mozilla-20&index=blended&link_code=qs&field-keywords="+searchHere.getText()+"&sourceid=Mozilla-search" ; address.setText(amazon); showPage(amazon); } if(search == 5) // Answer.com { String answer = "http://www.answers.com/main/ntquery?s="+searchHere.getText()+"&gwp=13" ; address.setText(answer); showPage(answer); } if(search == 6) // eBay.com { String ebay = "http://shop.ebay.com/i.html?_nkw="+searchHere.getText()+"&_armrs=1&_from=&_ipg=" ; address.setText(ebay); showPage(ebay); } if(search == 7) // Wikipedia { String wiki = "http://en.wikipedia.org/wiki/Special:Search?search="+searchHere.getText()+"&go=Go"; address.setText(wiki); showPage(wiki); } } } /*****************************************************************************************************************************************/ public boolean isBlocked(String loc){ try{ FileReader f=new FileReader("block.txt"); BufferedReader br=new BufferedReader(f); String s=null; while((s=br.readLine())!=null){ if(loc.equals(s)){ f.close(); return true; } } f.close(); return false; }catch(IOException e){ return false; } } public void showPage(String str){ if(str.equals("Enter Address Here") || str.equals("")) return; String location; if(str.startsWith(key)==false) location=key+str; else location=str; if(backButtonClicked==false){ backLog.push(location); //forLog.clear(); } else backButtonClicked=false; if(backLog.size()<=1) { backPage.setEnabled(false); j[14].setEnabled(false); } else { backPage.setEnabled(true); j[14].setEnabled(true); } if(forLog.size()==0) { forwardPage.setEnabled(false); j[15].setEnabled(false); } else { forwardPage.setEnabled(true); j[15].setEnabled(false); } if(isBlocked(location)){ JOptionPane.showMessageDialog(this,"This WebSite is Blocked","Infinity",JOptionPane.ERROR_MESSAGE); return; } try{ address.setText(location); contents.setPage(location); bookmarkFlag=true; FileWriter f=new FileWriter("historyLog.txt",true); String ss=location+'\n'; f.write(ss); f.close(); for(int k=0;k<recentItem;k++)history.remove(r[k]); addRecentHistory(); }catch(IOException hyu){ bookmarkFlag=false; try{ File rt=new File("C:/error.html"); if(rt.isFile() && rt.exists()) contents.setPage(new URL("file://localhost/C:/Error.html")); else{ FileWriter w=new FileWriter("C:/error.html"); w.write("<Html> <head> Server not Found (Mirror Error Details) <head>"+"\n\r" +" <Title> Error</Title></head>" +"<Body> <Body> <h1> The page cannot be displayed </h1>" +"The page you are looking for is currently unavailable.</br> \n\r The Web site might be experiencing technical difficulties,</br> \n\r or you may need to adjust your browser settings.</br>" +" <h3> <u><b>Url ="+address.getText()+"</b></u></h3><br> Please Search On <a href a=http://www.google.co.in> Google </a> </body><html>"); w.close(); contents.setPage(new URL("file://localhost/C:/error.html")); } } catch(Exception gty){} } } /*******************************CLASS for Skin Updater*************************************/ public void updater() { addressPanel.updateUI(); descriptionPanel.updateUI(); buttonPanel.updateUI(); socialPanel.updateUI(); siPanel.updateUI(); js1.updateUI(); skins.updateUI(); file.updateUI(); edit.updateUI(); view.updateUI(); history.updateUI(); bookmark.updateUI(); tool.updateUI(); help.updateUI(); security.updateUI(); Home.updateUI(); Stop.updateUI(); Reload.updateUI(); backPage.updateUI(); forwardPage.updateUI(); bookmarks.updateUI(); facebook.updateUI(); twitter.updateUI(); gmail.updateUI(); yahoo.updateUI(); cricinfo.updateUI(); bbc.updateUI(); Openfile.updateUI(); cutbutton.updateUI(); copybutton.updateUI(); pastebutton.updateUI(); sourcebutton.updateUI(); historybutton.updateUI(); infobutton.updateUI(); blockbutton.updateUI(); unblockbutton.updateUI(); bpbutton.updateUI(); passbutton.updateUI(); address.updateUI(); searchHere.updateUI(); Combo.updateUI(); description.updateUI(); l1.updateUI(); winlook.updateUI(); unixlook.updateUI(); nimbuslook.updateUI(); contents.updateUI(); menuBar.updateUI(); file.updateUI(); edit.updateUI(); clearbook.updateUI(); view.updateUI(); history.updateUI(); bookmark.updateUI(); tool.updateUI(); help.updateUI(); security.updateUI(); int counter=0; while(j[counter]!=null){ j[counter].updateUI(); counter++; } clearbook.updateUI(); block.updateUI(); blockedPage.updateUI(); unblock.updateUI(); setPassword.updateUI(); } /******************************************MAIN***************************************************/ static Main frame; public static void main(String[] args) { frame=new Main(); frame.setVisible(true); frame.setSize(new Dimension(1200,600)); } }