Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 

PageFrame Java code example - Click here to copy ->>>

   Can't find what you're looking for? Try our search:

Really working examples categorized by API, package, class. You can compile and run our examples right away! Not from source code for Java projects - only working examples! Copy, compile and run!

A simple extension of the JInternalFrame class that contains a list object. Elements of the list represent HTML pages for a web site.



Code:


 
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(); }
}




 
 



References.

The list of classes which were used on this page you can find below. The links to Java API contain official SUN documentation about all used classes.




[ Go Back ]



Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy