Hello again with my Java tutorial~! **as you see I'm always bored..**

In this tutorial, I'll teach you on how to add more components to your GUI. Not only frame as you learned before. If you haven't see my previous post about your First GUI, go to this
LINK
Let's write some codes (explanation on comments):
PHP Code:
import java.net.URL;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JEditorPane;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.event.HyperlinkListener;
import javax.swing.event.HyperlinkEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Color;
import java.io.IOException;
public class Browser extends JFrame implements HyperlinkListener,
ActionListener{
private static final long serialVersionUID = 1;
private JTextField urlField;
private JEditorPane htmlPane;
private String initialURL;
public Browser(String initialURL) {
super("My Web Browser");
this.initialURL = initialURL;
// add a listener to the window for closing init
setDefaultCloseOperation(EXIT_ON_CLOSE);
// add a top panel
JPanel topPanel = new JPanel();
topPanel.setBackground(Color.green);
// create a Jlabel and JTextField for gettingURL
JLabel urlLabel = new JLabel("URL:");
urlField = new JTextField(30);
urlField.setText(initialURL);
// add a listener to JTextField
urlField.addActionListener(this);
// add url label and field to toppanel
topPanel.add(urlLabel);
topPanel.add(urlField);
//add top panel at the top and html text at the center
getContentPane().add(topPanel, BorderLayout.NORTH);
try {
htmlPane = new JEditorPane(initialURL);
htmlPane.setEditable(false);
htmlPane.addHyperlinkListener(this);
JScrollPane scrollPane = new JScrollPane(htmlPane);
getContentPane().add(scrollPane, BorderLayout.CENTER);
} catch(IOException ioe) {
System.out.println("Can't build HTML pane for " + initialURL);
}
Dimension screenSize = getToolkit().getScreenSize();
int width = screenSize.width * 8 / 10;
int height = screenSize.height * 8 / 10;
setBounds(width/8, height/8, width, height);
setVisible(true);
}
// event handling for changing the URL
public void actionPerformed(ActionEvent event) {
String url;
url = urlField.getText();
try {
htmlPane.setPage(new URL(url));
urlField.setText(url);
} catch(IOException ioe) {
System.out.println("Can't follow link to " + url );
}
}
// event handling when you click on a link
public void hyperlinkUpdate(HyperlinkEvent event) {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
htmlPane.setPage(event.getURL());
urlField.setText(event.getURL().toExternalForm());
} catch(IOException ioe) {
System.out.println("Can't follow link to "
+ event.getURL().toExternalForm() );
}
}
}
public static void main(String[] args) {
// take the initial web page from the command line argument
if (args.length == 0)
new Browser("http://www.programmerstalk.net/");
else
new Browser(args[0]);
}
}
Guess what!!! You're now creating your own simple web browser with Java!
Follow this
LINK to see my tutorial about Action Listener if you want review about action Listener. In this code, I'm using the other way of using Action Listener. It's basically the same thing, you can change it either way
** Tested and worked with JVM 1.6 ** but, rendered crappy

lol..