Hello When run my web browser this is not displaying complete page any of the website like other browser.So Plz help me.
package vision.sun;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.URL;
import java.util.Stack;
import java.util.jar.JarFile;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
public class WebBrowser2 {
@SuppressWarnings("deprecation")
public static void main(String args[])
{
JFrame frame=new EditorPaneFrame();
frame.show();
}
}
class EditorPaneFrame extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
private JTextField url;
private JCheckBox editable;
private JButton loadButton;
private JButton backButton;
private JEditorPane editorPane;
private JMenuItem FavAdd;
JarFile jar;
private Stack<String> urlStack=new Stack<String>();
public EditorPaneFrame()
{
if(isConnected())
System.out.println("Proxy Connected.");
setTitle("NextVision Browser");
setSize(600,400);
Container contentPane = getContentPane();
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
url=new JTextField(30);
loadButton=new JButton("Load");
loadButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try
{
URL netURL=new URL(url.getText());
urlStack.push(url.getText());
editorPane.setPage(netURL);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
});
// set up back button and button action
backButton = new JButton("<<");
backButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
if(urlStack.size()<=1) return;
try
{
urlStack.pop();
String urlString = (String)urlStack.peek();
url.setText(urlString);
editorPane.setPage(urlString);
}
catch(IOException e)
{
editorPane.setText("Error : " +e);
}
}
});
editorPane = new JEditorPane();
editorPane.setEditable(false);
editorPane.addHyperlinkListener(new HyperlinkListener()
{
public void hyperlinkUpdate(HyperlinkEvent event)
{
if(event.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
{
try
{
urlStack.push(event.getURL().toString());
url.setText(event.getURL().toString());
editorPane.setPage(event.getURL().toString());
}
catch(IOException e)
{
editorPane.setText("Error: " + e);
}
}
}
});
editable = new JCheckBox();
editable.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
editorPane.setEditable(editable.isSelected());
}
});
//referesh=new JButton("Referesh");
contentPane.add(new JScrollPane(editorPane), "Center");
JPanel panel = new JPanel();
panel.add(new JLabel("URL"));
panel.add(url);
panel.add(loadButton);
panel.add(backButton);
panel.add(new JLabel("Editable"));
panel.add(editable);
//panel.setBounds(10, 10, 50, 60);
JMenuBar objMenuBar=new JMenuBar();
JMenu objMenu=new JMenu("File");
JMenu objSetting=new JMenu("Setting");
JMenu objFavourite=new JMenu("Favourite");
objMenuBar.add(objMenu);
objMenuBar.add(objFavourite);
JMenuItem objMenuItem=new JMenuItem("New");
JMenuItem objMenuExit=new JMenuItem("Exit");
JMenuItem OpenRun=new JMenuItem("Open Type");
objMenu.add(objMenuItem);
objMenu.add(OpenRun);
objMenu.add(objMenuExit);
JMenuItem Internet=new JMenuItem("Connection");
FavAdd=new JMenuItem("Add Address");
objMenuBar.add(objSetting);
objFavourite.add(FavAdd);
objSetting.add(Internet);
contentPane.add(panel,"South");
contentPane.add(objMenuBar,"North");
FavAdd.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "Program Under Progress !");
}
}
);
objMenuExit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(JOptionPane.showConfirmDialog(null, "Are You Sure To Exit ?","Message",JOptionPane.CANCEL_OPTION)==0)
{
System.exit(0);
}
}
});
OpenRun.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
runCommand();
}
});
}
private void runCommand()
{
String inputCommand=null;
try
{
inputCommand=JOptionPane.showInputDialog(null,"Enter Command Here");
if(inputCommand!=null)
{
Runtime runtime=Runtime.getRuntime();
runtime.exec(inputCommand);
}
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
if(ex.getMessage().toString().indexOf("The system cannot find the file specified")!=-1)
{
JOptionPane.showMessageDialog(null, "Invalid Command !");
runCommand();
}
else if(ex.getMessage().toString().indexOf("Empty command")!=-1)
{
JOptionPane.showMessageDialog(null, "Please Enter Command !");
runCommand();
}
else if(ex.getMessage().toString().indexOf("Access is denied")!=-1)
{
JOptionPane.showMessageDialog(null, "Invalid Command !");
runCommand();
}
else if(ex.getMessage().toString().indexOf("The parameter is incorrect")!=-1)
{
JOptionPane.showMessageDialog(null, "Invalid Command !");
runCommand();
}
}
}
private boolean isConnected()
{
//System.setProperty("http.proxyHost","10.0.0.3");
//System.setProperty("http.proxyPort","6588");
String host=System.getProperty("http.proxyHost");
String port=System.getProperty("http.proxyPort");
System.out.println("host is "+host);
System.out.println("port is "+port);
System.setProperty("https.proxyHost", "10.0.0.3");
System.setProperty("https.proxyPort", "6588");
if(!host.equals("")&&!port.equals(""))
return true;
else
return false;
}
}