Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

java help needed...nt able to navigate

aman2010aman2010 Posts: 4Member
I WANT SAME WORKING AS IN A WEB BROWSER....nw read---
not able to navigate between web pages...that is on clicking any link on the website....it is not navigating to that link....but the website like www.yahoo.com is being opened by web browser...plz help......if this prblm not solved ....thn i will be no able to save history items nd bookmarks...plz helpppppppppppppppp

[code]
import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.applet.Applet;

public class WeBrowsertry3 extends JFrame
{

public JPanel panel1,panel2,window_panel,panel3,panel4;

public JLabel address_label;

public JTextField address_tf;

public JEditorPane window_pane;

public JScrollPane window_scroll;

public JButton b1,b2,b3,b4,b5,b6;

private Go go = new Go();
Go reload=new Go();
Menugo menugo1=new Menugo();
public JTabbedPane jtb1,jtb2;



public WeBrowsertry3() throws IOException
{
JMenuBar menuBar = new JMenuBar();
JMenu menu1 = new JMenu("....");

JMenuItem item1,item2,item3;
item1=new JMenuItem("add tab");
item2=new JMenuItem(">>>>");
item3=new JMenuItem("<<<<");
menu1.add(item1);
menu1.addSeparator();
menu1.add(item2);
menu1.add(item3);

menuBar.add(menu1);


item1.addActionListener(menugo1);


b1=new JButton("back");
b2=new JButton("forward");
//b2.setSize(30,40);
b3=new JButton("reload");
b4=new JButton("Go");
b5=new JButton("history");
b6=new JButton("Add Tab");
b6.addActionListener(new MyAction());
b4.addActionListener(go);
b3.addActionListener(go);
address_label = new JLabel(" address: ",SwingConstants.CENTER); // for address label
address_tf = new JTextField("http://www.yahoo.com",JTextField.LEFT);// for entering address


panel1=new JPanel(new BorderLayout());
panel2 = new JPanel(new BorderLayout());
panel3 = new JPanel(new BorderLayout());
window_panel = new JPanel(new BorderLayout());
panel4=new JPanel(new BorderLayout());



window_pane = new JEditorPane("http://www.yahoo.com"); // for editor pane
window_pane.setContentType("text/html"); // for content in the panel
window_pane.setEditable(false); // we can't update the text of a website
//window_pane.add(p1);

JSplitPane sp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,panel1,panel2);
JSplitPane sp2=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,panel3,panel4);


panel1.add(b1,BorderLayout.WEST);
panel1.add(b2,BorderLayout.CENTER);
panel1.add(b3,BorderLayout.EAST);
panel2.add(address_label,BorderLayout.WEST); // address label on the left
panel2.add(address_tf,BorderLayout.CENTER);
panel2.add(b4,BorderLayout.EAST);
panel3.add(b5,BorderLayout.WEST);
panel4.add(b6,BorderLayout.WEST);
panel4.add(menuBar,BorderLayout.EAST);



window_scroll = new JScrollPane(window_pane);
window_panel.add(window_scroll);

Container pane = getContentPane();
pane.setLayout(new BorderLayout());
pane.add(sp,BorderLayout.NORTH);
pane.add(sp2,BorderLayout.SOUTH);
//pane.add(panel3,BorderLayout.SOUTH);
pane.add(window_panel,BorderLayout.CENTER);
//pane.add(panel4,BorderLayout.SOUTH);


setTitle("My new web browser");
setSize(800,600);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);

}

public class Go implements ActionListener
{

public void actionPerformed(ActionEvent ae)
{

try
{

window_pane.setPage(address_tf.getText());

}

catch (MalformedURLException e)
{ // new URL() failed
window_pane.setText("MalformedURLException: " + e);

}

catch (IOException e)
{ // openConnection() failed
window_pane.setText("IOException: " + e);
}

}

}





public class Menugo implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String str2 = e.getActionCommand();
if(str2.equals("add tab"))
{



}


}
}


public class MyAction implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String str = e.getActionCommand();
if(str.equals("Add Tab"))
{
String st = JOptionPane.showInputDialog(null, "Enter Tab Name.");
if(!st.equals(""))
{


}
}

}
}
public static void main(String args[]) throws IOException
{
WeBrowsertry3 wb = new WeBrowsertry3();
}

}


[/code]
Sign In or Register to comment.