Cybertronic
Technical User
- May 18, 2006
- 19
Hi all,
In my previous thread I posted a few days ago about JEditorPane regarding my Java web browser, now I've got another problem which is that I would like to separate some of my coding into several classes to prevent my code from getting too long.
Below is my current code I have for my browser constructor:
I have other constructors in the same browser class which is why I would like to separate them into different classes to ease of coding.
How can I convert all my GUI declarations, properties, etc in a separate class file? Will I need to use the "extends" in the separate class method?
I appreciate anybody's assistance
In my previous thread I posted a few days ago about JEditorPane regarding my Java web browser, now I've got another problem which is that I would like to separate some of my coding into several classes to prevent my code from getting too long.
Below is my current code I have for my browser constructor:
Code:
public class browser extends JFrame implements ActionListener, HyperlinkListener
{
// Private GUI components initialisation
// Constructor for browser.
public browser()
{
browserMenu = new JMenu("File");
newMenuItem = new JMenuItem("New");
newMenuItem.addActionListener(this);
openMenuItem = new JMenuItem("Open");
openMenuItem.addActionListener(this);
fileChooser = new JFileChooser();
printMenuItem = new JMenuItem("Print");
printMenuItem.addActionListener(this);
exitMenuItem = new JMenuItem("Exit");
exitMenuItem.addActionListener(this);
browserMenu.add(newMenuItem);
browserMenu.add(openMenuItem);
browserMenu.add(printMenuItem);
browserMenu.addSeparator();
browserMenu.add(exitMenuItem);
favouritesMenu = new JMenu("Favourites");
favMenuItem1 = new JMenuItem("fav1");
favMenuItem1.addActionListener(this);
favMenuItem2 = new JMenuItem("fav2");
favMenuItem2.addActionListener(this);
favMenuItem3 = new JMenuItem("fav3");
favMenuItem3.addActionListener(this);
favMenuItem4 = new JMenuItem("fav4");
favMenuItem4.addActionListener(this);
favMenuItem5 = new JMenuItem("fav5");
favMenuItem5.addActionListener(this);
favouritesMenu.add(favMenuItem1);
favouritesMenu.add(favMenuItem2);
favouritesMenu.add(favMenuItem3);
favouritesMenu.add(favMenuItem4);
favouritesMenu.add(favMenuItem5);
menuBar = new JMenuBar();
menuBar.add(browserMenu);
menuBar.add(favouritesMenu);
setJMenuBar(menuBar);
toolBar = new JToolBar();
addressLabel = new JLabel(" Address: ");
addressTextField = new JTextField(30);
addressTextField.addActionListener(this);
homePageButton = new JButton("Home");
homePageButton.addActionListener(this);
searchButton = new JButton("Search");
searchButton.addActionListener(this);
printButton = new JButton("Print");
printButton.addActionListener(this);
goButton = new JButton("Go");
goButton.addActionListener(this);
toolBar.add(homePageButton);
toolBar.add(searchButton);
toolBar.add(printButton);
toolBar.add(addressLabel);
toolBar.add(addressTextField);
toolBar.add(goButton);
try
{
// display web page
}
catch (IOException ioe)
{
// display error
}
contentScrollPane = new JScrollPane(contentPane);
contentPane.setEditable(false);
contentPane.addHyperlinkListener(this);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(toolBar, BorderLayout.NORTH);
getContentPane().add(contentScrollPane, BorderLayout.CENTER);
setTitle("Java Web Browser");
setSize(800, 600);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setVisible(true);
}
...
}
I have other constructors in the same browser class which is why I would like to separate them into different classes to ease of coding.
How can I convert all my GUI declarations, properties, etc in a separate class file? Will I need to use the "extends" in the separate class method?
I appreciate anybody's assistance