Answer to Question #1366 in Java | JSP | JSF for Abhishek

Question #1366
I want to know how to show an html page enabled with java script in a window application
1
Expert's answer
2011-01-21T05:20:39-0500
Use a simple extension of the JInternalFrame class that
contains a list objects. Here elements of the list represent HTML pages for a
web site.









import java.awt.*;

import java.io.*;

import java.awt.event.*;

import javax.swing.*;



public class PageFrame extends JInternalFrame implements ActionListener {



SiteManager parent;

String filename;

JTextArea ta;



public PageFrame(String name, SiteManager sm) {

super("Page: " + name, true, true, true, true);

parent = sm;

setBounds(50,50,300,150);



Container contentPane = getContentPane();



// Create a text area to display the contents of our file in

// and stick it in a scrollable pane so we can see everything

ta = new JTextArea();

JScrollPane jsp = new JScrollPane(ta);

contentPane.add(jsp, BorderLayout.CENTER);



JMenuBar jmb = new JMenuBar();

JMenu fileMenu = new JMenu("File");

JMenuItem saveItem = new JMenuItem("Save");

saveItem.addActionListener(this);

fileMenu.add(saveItem);

jmb.add(fileMenu);

setJMenuBar(jmb);



filename = name;

loadContent();

}



public void actionPerformed(ActionEvent ae) {

// Can only be the save menu

saveContent();

}



public void loadContent() {

try {

FileReader fr = new FileReader(filename);

ta.read(fr, null);

fr.close();

} catch (Exception e) {

System.err.println("Could not load page: " + filename);

}

}



public void saveContent() {

try {

FileWriter fw = new FileWriter(filename);

ta.write(fw);

fw.close();

} catch(Exception e) {

System.err.println("Could not save page: " + filename);

}

}



public void cutText() { ta.cut(); }

public void copyText() { ta.copy(); }

public void pasteText() { ta.paste(); }

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS