string to URL and URL to string
Hi All,
I am having a problem with assigning a URL to a string.
It accepts the idea of a URL from a string, does not accept
having the URL placed back into a string.
..
I have provided a sample program here as a demo. I have
tried to use the ".equals" and also the" =" but neither works.
TIA.
bH
import java.net.URL;
import java.net.MalformedURLException;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class BookmarksC extends JFrame implements ActionListener{
private JButton b1 = new JButton(" Hotmail ");
private String bmklistURL[] = new String[1];
public BookmarksC() {
super("URL Button");
bmklistURL[0]= "http://www.hotmail.msn.com/";
JPanel btnPanel = new JPanel();
b1.addActionListener(this);
btnPanel.add(b1);
Container contentPane= getContentPane();
contentPane.add(btnPanel);
contentPane.setSize(150,300);
this.setResizable(false);
setVisible(true);
}
public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
String theURLX = new String();
URL theURL = null;
try{
if (evt.getSource() == b1) {
theURL = new URL(bmklistURL[0]);
}
}
catch ( MalformedURLException e) {
System.out.println("Bad URL: " + theURL);
}
System.out.println(" The URL is "+ theURL);
theURLX.equals(theURL);
// theURLX below comes up empty.
System.out.println(" The string is "+ theURLX);
}
public static void main(String[] args)
{
BookmarksC app = new BookmarksC ();
app.pack();
app.setVisible(true);
}
}