Total members 11895 |It is currently Sun Dec 22, 2024 12:55 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Java HTML editor:
on the fist page there is user name and password, and apply button.
from java I want to press the button with given (in java) parameters and get the html code of the next page.
This html Java editor code , it should be helpful to you .

Code:

import java
.awt.*;
import java.awt.event.*;
import java.io.*;

import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import javax.swing.undo.*;
import java.util.*;
import java.net.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;


/**
 * Simple HTML 'editor'

 */

public class HTMLEditor extends JFrame implements ActionListenerDocumentListenerUndoableEditListener {
  
BorderLayout borderLayout1 = new BorderLayout();
  
JPanel jPanel1 = new JPanel();
  
JButton getFileBtn = new JButton();
  
JButton closeBtn = new JButton();
  
JTabbedPane jTabbedPane1 = new JTabbedPane();
  
JScrollPane jScrollPane1 = new JScrollPane();
  
JScrollPane jScrollPane2 = new JScrollPane();
  
JEditorPane edText = new JEditorPane();
  
JEditorPane edHTML = new JEditorPane();
  
Document textDoc=null;
  
ArrayList undoList=new ArrayList();
  
JButton undoBtn = new JButton();

  public 
HTMLEditor() {
    try {
      
jbInit();
      
getFileBtn.addActionListener(this);
      
undoBtn.addActionListener(this);
      
closeBtn.addActionListener(this);
    }
    catch(
Exception e) {
      
e.printStackTrace();
    }
  }
  public 
void loadFile(String fpthrows Exception {

    if (
fp==null) return;
    
String filePath=fp;
    
File f=new File(fp);
    
long av=f.length();
    if (
av==0) {
      
System.out.println("no data");
      return;
    }
    
URL url=new URL("file:"+fp);
    
edHTML.setPage(url);
    
FileReader fr=new FileReader(f);
    
edText.read(fr,null);

    
textDoc=this.edText.getDocument();
    
textDoc.addDocumentListener(this);
    
textDoc.addUndoableEditListener(this);

    
this.validate();
  }

  public static 
void main(String[] args) {
    
HTMLEditor ed = new HTMLEditor();
    
ed.setBounds(20,20,500,400);
    
ed.setVisible(true);
  }
  private 
void jbInit() throws Exception {
    
this.getContentPane().setLayout(borderLayout1);
    
getFileBtn.setText("Get FIle");
    
closeBtn.setText("Close");
    
edText.setText("jEditorPane1");
    
edHTML.setEditable(false);
    
edHTML.setText("jEditorPane2");
    
undoBtn.setEnabled(false);
    
undoBtn.setText("Undo");
    
this.getContentPane().add(jPanel1BorderLayout.SOUTH);
    
jPanel1.add(getFileBtnnull);
    
jPanel1.add(undoBtnnull);
    
jPanel1.add(closeBtnnull);
    
this.getContentPane().add(jTabbedPane1BorderLayout.CENTER);
    
jTabbedPane1.add(jScrollPane1,   "HTML");
    
jScrollPane1.getViewport().add(edHTMLnull);
    
jTabbedPane1.add(jScrollPane2,   "Text");
    
jScrollPane2.getViewport().add(edTextnull);
    
addWindowListener(new WindowAdapter() {
      public 
void windowClosing(WindowEvent e) {
        
System.exit(0);
      }
    });
  }
  public 
void actionPerformed(ActionEvent e) {
    if (
e.getSource() == this.closeBtn)
      
System.exit(0);
    if (
e.getSource() == this.getFileBtn) {
      
FileDialog fd=new FileDialog(this,"Select File",FileDialog.LOAD);
      
fd.setVisible(true);
      
String fName=fd.getFile();
      if (
fName==null) return;
      
String fPath=fd.getDirectory()+fName;
      try {
        
loadFile(fPath);
      }
      catch (
Exception ex) {
        
System.out.println(ex.getMessage());
        
ex.printStackTrace();
      }
    } else if (
e.getSource() == this.undoBtn) {
      
undoLast();
    }
  }
  public 
void undoLast() {
    
int ix=undoList.size()-1;
    if (
ix>=0) {
      
UndoableEdit ue=(UndoableEdit)this.undoList.get(ix);
      
ue.undo();;
      
undoList.remove(ix);
      if (
undoList.size()==0this.undoBtn.setEnabled(false);
    }
  }
  
/**
   * If the undoList has any elements then the document has
   * been changed
   * @return
   */
  
public boolean isFileChanged() {
    return 
this.undoList.size()>0;
  }
  public 
void insertUpdate(DocumentEvent e) {
    
System.out.println("insertUpdate");
  }
  public 
void removeUpdate(DocumentEvent e) {
    
System.out.println("removeUpdate");
  }
  public 
void changedUpdate(DocumentEvent e) {
    
System.out.println("changedUpdate");
  }
  public 
void undoableEditHappened(UndoableEditEvent e) {
    
this.undoList.add(e.getEdit());
    
this.undoBtn.setEnabled(true);
  }
}
  





Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : posting from java to html
 Notifications to Posting in PHPbb3 board     -  
 How to use Java Applets in your HTML     -  
 insert information in html file with java     -  
 What are PHP,PSD to HTML ?     -  
 dfn html tag usage     -  
 I need help with a html code     -  
 How to use HTML with JavaScript     -  
 HTML Editor     -  
 HTML Tags -2     -  
 Usage of xmp html tag     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com