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();
}
}
error in HyperlinkListener in java...help
Page 1 of 19 Replies - 1067 Views - Last Post: 22 April 2011 - 09:46 PM
#1
error in HyperlinkListener in java...help
Posted 29 March 2011 - 12:09 AM
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
Replies To: error in HyperlinkListener in java...help
#2
Re: error in HyperlinkListener in java...help
Posted 29 March 2011 - 03:02 AM
** Topic renamed for clarity **
Use a HyperlinkListener. You should be able to find the address clicked and set the JEditorPane to that new address.
Use a HyperlinkListener. You should be able to find the address clicked and set the JEditorPane to that new address.
#3
Re: error in HyperlinkListener in java...help
Posted 30 March 2011 - 06:09 AM
Dogstopper, on 29 March 2011 - 03:02 AM, said:
** Topic renamed for clarity **
Use a HyperlinkListener. You should be able to find the address clicked and set the JEditorPane to that new address.
Use a HyperlinkListener. You should be able to find the address clicked and set the JEditorPane to that new address.
thnku a lot sir ...for rplng...............
THROUGH THIS.......it will be feasible for me to....click on any ling of a website.??
LIKE IN THE SAME WAY.....we navigate in a web browser....plz reply sirrrrrrrr.....
#4
Re: error in HyperlinkListener in java...help
Posted 30 March 2011 - 02:56 PM
Yes, just get the URL location of the HyperlinkEvent (use getURL()) and then set the JEditorPane's location to that source (use setSource()). Make sure that you actually add the listener to the JEditorPane.
Give it a try!
Give it a try!
#5
Re: error in HyperlinkListener in java...help
Posted 01 April 2011 - 08:44 AM
Dogstopper, on 30 March 2011 - 02:56 PM, said:
Yes, just get the URL location of the HyperlinkEvent (use getURL()) and then set the JEditorPane's location to that source (use setSource()). Make sure that you actually add the listener to the JEditorPane.
Give it a try!
Give it a try!
thnks again sir,
i have done some changes......but the code is giving a CT error.....plz look at it..(sndng that snippet only...rest of the prgrm is same)
THE ERROR IS ";expected".... this error is coming at-->
JEditorPane window_pane = new JEditorPane("http://www.yahoo.com"); // for editor pane
//window_pane.addHyperlinkListener(link);
window_pane.setContentType("text/html"); // for content in the panel
window_pane.setEditable(false); // we can't update the text of a website
final JEditorPane finalpane =window_pane;
window_ pane.addHyperlinkListener(new HyperlinkListener()// [u]error is coming in this line..[/u] [b]; expected[/b]
{
public void hyperlinkUpdate(HyperlinkEvent r)
{
try
{
if(r.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
finalpane.setPage(r.getURL());
}catch(Exception e)
{}
}
});
plz helpppppppppppppp :-)
#6
Re: error in HyperlinkListener in java...help
Posted 01 April 2011 - 04:54 PM
#7
Re: error in HyperlinkListener in java...help
Posted 20 April 2011 - 07:09 PM
the code is giving a CT error.....plz look at it..(sndng that snippet only...rest of the prgrm is same)
THE ERROR IS ";expected".... this error is coming at-->
THE ERROR IS ";expected".... this error is coming at-->
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
//error in coming here ;expected.....plz help
window_ pane.addHyperlinkListener(new HyperlinkListener(){
public void hyperlinkUpdate(HyperlinkEvent evt)
{
if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
{
pane.setPage(evt.getURL());
}
}
});
//hyperlink code ending
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();
}
}
#8
Re: error in HyperlinkListener in java...help
Posted 20 April 2011 - 07:17 PM
Which line?! We aren't mind readers! Post the error exactly as it appears on your compiler! We need to know what errors you are encountering, as well as where they are occurring!
#9
Re: error in HyperlinkListener in java...help
Posted 20 April 2011 - 07:22 PM
...Topics merged...
Mac, the code does have a comment on the one where the error is...and he did tell us that the compiler is saying that it needs a semicolon there. I can confirm this.
OP, your problem is here:
You need to remove the space after the "_" character. Like this:
And that should fix your problem.
Mac, the code does have a comment on the one where the error is...and he did tell us that the compiler is saying that it needs a semicolon there. I can confirm this.
OP, your problem is here:
window_ pane.addHyperlinkListener(new HyperlinkListener()
You need to remove the space after the "_" character. Like this:
window_pane.addHyperlinkListener(new HyperlinkListener()
And that should fix your problem.
#10
Re: error in HyperlinkListener in java...help
Posted 22 April 2011 - 09:46 PM
Dogstopper, on 20 April 2011 - 07:22 PM, said:
...Topics merged...
Mac, the code does have a comment on the one where the error is...and he did tell us that the compiler is saying that it needs a semicolon there. I can confirm this.
OP, your problem is here:
You need to remove the space after the "_" character. Like this:
THNAKU U SO MUCH SIR.... so silly....ws jst laughing lloking at that error,,,,lol
And that should fix your problem.
Mac, the code does have a comment on the one where the error is...and he did tell us that the compiler is saying that it needs a semicolon there. I can confirm this.
OP, your problem is here:
window_ pane.addHyperlinkListener(new HyperlinkListener()
You need to remove the space after the "_" character. Like this:
window_pane.addHyperlinkListener(new HyperlinkListener()
THNAKU U SO MUCH SIR.... so silly....ws jst laughing lloking at that error,,,,lol
And that should fix your problem.
Page 1 of 1

New Topic/Question
Reply


MultiQuote






|