SourceForge.net Logo
/*
 * UserInterFace2.java
 *
 * Created on November 20, 2000, 3:29 PM
 */
 


/** 
 *
 * @author  Administrator
 * @version 
 */
import javax.swing.*;       

import java.awt.*;

import java.awt.geom.*;

import java.net.*;

import java.util.*;

import java.awt.event.*;



import java.awt.font.FontRenderContext;

import java.awt.font.LineBreakMeasurer;

import java.awt.font.TextLayout;

import java.util.Hashtable;

import java.text.AttributedCharacterIterator;

import java.text.AttributedString;

import java.awt.font.TextAttribute;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent; 



import java.io.*;   //reading input



public class UserInterFace2 extends javax.swing.JApplet {
  
//Line draw

  
  boolean gotdata=false;
      // The LineBreakMeasurer used to line-break the paragraph.

    private LineBreakMeasurer myLine;

    // The index in the LineBreakMeasurer of the first character

    // in the paragraph.

    private int paragraphStart;

    // The index in the LineBreakMeasurer of the first character

    // after the end of the paragraph.

    private int paragraphEnd;

    private static final Hashtable map = new Hashtable();
    static {
        map.put(TextAttribute.SIZE, new Float(12.0));
    }  

   
  
  
  
  
  
  
  
  
String fb2;
mURL murl_1 = new mURL();
CmToken cmToken = new CmToken();


int rnum=0;
  
  
  int radioN=5;
  
  
  java.awt.TextField textField1 = new java.awt.TextField ();
  java.awt.Button button1 = new java.awt.Button ();
  
  java.awt.CheckboxGroup cg = new java.awt.CheckboxGroup();
  Checkbox[] cb= new Checkbox[radioN]; 
  
  
  
  
int mi=3;
  
  final static BasicStroke sStroke = new BasicStroke(1.0f);
  /** Creates new form UserInterFace0 */
  public UserInterFace2() {
    initComponents ();
    initMyComponents();
  }

  
  
  private void initMyComponents(){
  
// begin line stuff  

    /*
          AttributedCharacterIterator paragraph = vanGogh.getIterator();
          paragraphStart = paragraph.getBeginIndex();
          paragraphEnd = paragraph.getEndIndex();

          // Create a new LineBreakMeasurer from the paragraph.
          myLine = new LineBreakMeasurer(paragraph, 
                                new FontRenderContext(null, false, false));
*/
    //end line stuff

    
    
    
    
    
    
    
    String s[] = new String[radioN];
    s[0]="A)    Glioblastoma multiforme ";
    s[1]="B)    Herpes simplex encephalitis";
    s[2]="C)    Arteriovenous malformation ";
    s[3]="D)    Cerebral abscess ";
    s[4]="E)    Acute infarction ";
    for(int i=0;i < radioN; i++){
    cb[i]= new java.awt.Checkbox();
    cb[i].setName("checkbox"+i);
    cb[i].setBackground(java.awt.Color.white);
    cb[i].setLabel(s[i]);
    cb[i].setBounds(10,100+20*i,500,20);
    cb[i].setCheckboxGroup(cg);
  }
    
    
    
  
    button1.setName("button1");
    button1.setBackground(java.awt.Color.cyan);
    button1.setLabel("Submit");
    button1.setBounds(10,40,50,20);
    button1.addActionListener (new java.awt.event.ActionListener () {
      public void actionPerformed (java.awt.event.ActionEvent evt) {
        button1ActionPerformed (evt);
      }
    }
    );
    
    textField1.setBackground (java.awt.Color.white);
    textField1.setText ("");
    textField1.setForeground (java.awt.Color.black);
    textField1.setName ("textfield1");
    textField1.setFont (new java.awt.Font ("Dialog", 0, 11));
    textField1.setBounds(10,10,100,20);
    textField1.addActionListener (new java.awt.event.ActionListener () {
      public void actionPerformed (java.awt.event.ActionEvent evt) {
        textField1ActionPerformed (evt);
      }
    }
    );
    getContentPane().setLayout(null);
    getContentPane ().add (textField1, java.awt.BorderLayout.CENTER);
    getContentPane ().add (button1, java.awt.BorderLayout.CENTER);
    for(int i=0; i < radioN; i++){
      getContentPane ().add (cb[i], java.awt.BorderLayout.CENTER);
        }

  }
  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the FormEditor.
   */
  private void initComponents () {

  }
  private void textField1ActionPerformed (java.awt.event.ActionEvent evt) {
// Add your handling code here:

  }
   private void button1ActionPerformed (java.awt.event.ActionEvent evt) {
// Add your handling code here:

   
    Post_and_grab_data(textField1.getText(),0);
    textField1.setText ("");
    /*
     private static AttributedString vanGogh = new AttributedString(
        "Many people believe that Vincent van Gogh painted his best works " +
        "during the two-year period he spent in Provence. Here is where he " +
        "painted The Starry Night--which some consider to be his greatest " +
        "work of all. However, as his artistic brilliance reached new heights " +
        "in Provence, his physical and mental health plummeted. ", map);
*/
    
    
      AttributedString Parsedfb2DATA = new AttributedString(cmToken.parse(fb2,"<toprint>","</toprint>",0), map);
      gotdata=true;

        AttributedCharacterIterator paragraph = Parsedfb2DATA.getIterator();
          paragraphStart = paragraph.getBeginIndex();
          paragraphEnd = paragraph.getEndIndex();

          // Create a new LineBreakMeasurer from the paragraph.

          myLine = new LineBreakMeasurer(paragraph, 
                                new FontRenderContext(null, false, false));
   
    repaint();
  }


  public void Post_and_grab_data(String s0, int i0){
          String vName[] = new String[2];
          String vValue[] = new String[2];
      
            //vName[0]="Name";

          
          Graphics g = this.getGraphics();
          g.drawString(s0,0,150);
            //vValue[0]="Pear";

            //vName[1]="Size";

            //vValue[1]="big";

            vName[0]="Name";
            vValue[0]=s0;
            vName[1]="Size";
            vValue[1]="big";
            murl_1.postURL("http://localhost/cu2000/java/databasein.asp",vName,vValue);
 
    
  }
  
  
  
   public void paint(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setBackground(Color.white);
        int mwidth=100;
        int mheight=100;
        int msx=50,msy=50;
        Color fg3D = Color.blue;

       
          g2.setPaint(fg3D);
          g2.draw3DRect(msx, msy, mwidth - 1, mheight - 1, true);
          g2.draw3DRect(msx+3, msy+3, mwidth - 7, mheight - 7, false);
          msx+=50;
          msy+=50;
      
      
      g2.setStroke(sStroke);
      for(int i=0; i < 200; i+=20){
        
      g2.draw(new Arc2D.Double(50+i, 50,
                         100,
                         100+i,
                         90, 120+i,
                         Arc2D.OPEN));
    }

      
    
    /*
    FontRenderContext frc = g2.getFontRenderContext();
Font f = new Font("Helvetica",Font.BOLD, 24);
String s = new String("24 Pont Helvetica Bold");
TextLayout tl = new TextLayout(s, f, frc);
Dimension theSize=getSize();
g2.setColor(Color.green);
tl.draw(g2, theSize.width/30, theSize.height/2);
*/

        
        float formatWidth = 500;

        float drawPosY = 250;
        
        myLine.setPosition(paragraphStart);

        // Get lines from myLine until the entire

        // paragraph has been displayed.

        g2.drawString("this is fb2"+fb2,0,178);
        if(gotdata){
        while (myLine.getPosition() < paragraphEnd) {

            // Retrieve next layout.

            TextLayout layout = myLine.nextLayout(formatWidth);
            // Move y-coordinate by the ascent of the layout.

            drawPosY += layout.getAscent();

            // Compute pen x position.  If the paragraph is 

            // right-to-left, we want to align the TextLayouts

            // to the right edge of the panel.

            float drawPosX;
            if (layout.isLeftToRight()) {
                drawPosX = 0;
            }
            else {
                drawPosX = formatWidth - layout.getAdvance();
            }

            // Draw the TextLayout at (drawPosX, drawPosY).

            layout.draw(g2, drawPosX, drawPosY);
            
            

            // Move y-coordinate in preparation for next layout.

            drawPosY += layout.getDescent() + layout.getLeading();
        }
      } //end if


    
    
    
    
    
    
    
    
    
    
    
  } // End Paint

  // Variables declaration - do not modify

  // End of variables declaration


  
  //*********************************************************************************

  // Beginning of Local Classes

  //*********************************************************************************

  
  
  //*********************************************************************************

  // Local Class mURL

  //  Created Mike Chirico mchirico@users.sourceforge.net

  //  

  //  Interfaces:

  //  postURL  

  //  

  //*********************************************************************************

  
class mURL {
  private String fb;
  
  public void postURL(String url,String[] vName,String[] vData)
  {
    
    Graphics g=getGraphics();
     try{
  URL serv=new URL (url); 
  URLConnection urlConn= serv.openConnection(); 
  urlConn.setDoInput (true); 
  urlConn.setDoOutput (true); 
  urlConn.setUseCaches (false); 
  urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
  DataOutputStream pstream = new DataOutputStream (urlConn.getOutputStream ());

  String sconst="";
  String sDelim="";
  if(vName.length == vData.length && vName.length > 0){
  for(int i=0; i < vName.length; i++){
    sconst+=sDelim + vName[i] +"=" + URLEncoder.encode(vData[i]); 
    sDelim="&";
  }}

/*  Ignore this .. for Mike Chirico to refresh memory
String sconst = "information="+URLEncoder.encode("Size of it" + vName.length + vName[0]); 
sconst+= "&information2="+URLEncoder.encode("the second part of it will go in here"); 
String s="this is an example of text \n";
s+="there is more text as well in here \n";
s+="this is the final spot";
sconst+= "&information3="+URLEncoder.encode(s);
*/
  pstream.writeBytes (sconst);
  pstream.flush ();
  pstream.close ();

  // Getting Response Yes, getting the data here

                BufferedReader in  = new BufferedReader(
                                           new InputStreamReader(
                                              urlConn.getInputStream() ));
                      String buffer;
                      fb2="#";
                      while(!(null==(buffer=in.readLine()))){
                            fb2+=buffer;        
                        }

                      in.close();       



      }
                  catch(MalformedURLException e)
                  {
                   g.drawString("Error in URL",200,200); 
                  }
                  catch(IOException e)
                  {
                   g.drawString("Error in IO m",200,200); 
                  }
    
    
    
    
  }
  public void sendURL(String url)
  {
  // url= "http://130.91.97.82/Evaluations/Mod4/admin/java/testjava2.asp?Q=Fred&Q=Sally"

  // this.getDocumentBase();  

                    Graphics g=getGraphics();
                    try{
                     int k=0; 
                    URL sURL = new URL(url);
                 //   URL sURL = new URL("http://130.91.97.82/Evaluations/Mod4/admin/java/testjava2.asp?Q=Fred&Q=Sally");

                    
                    BufferedReader in  = new BufferedReader(
                                         new InputStreamReader(
                                            sURL.openStream()));
                    String buffer;
                    fb="#";
                    while(!(null==(buffer=in.readLine()))){
                          fb+=buffer;        
                      }
                      
                    in.close();
                    
                  }
                  catch(MalformedURLException e)
                  {
                   g.drawString("Error in URL",200,200); 
                  }
                  catch(IOException e)
                  {
                   g.drawString("Error in IO m",200,200); 
                  }
                     
  }
} // END of mURL Class



//Beginning of CmToken Class for parsing the data

class CmToken {
    private int LastIdx=0,LastNF=0;
    private  int mstart,mend;
    public String parse(String inpt,String t0,String t1){
    mstart=inpt.indexOf(t0);
    mend=inpt.indexOf(t1);
    if(mstart == -1 || mend == -1 || mstart >= mend )  {
            LastNF=-1;
            return "-1";
          }
    
      this.LastNF=1;
      this.LastIdx=inpt.indexOf(t1)+1;
      return inpt.substring(inpt.indexOf(t0)+t0.length(),inpt.indexOf(t1));
   }
  
public String parse(String inpt,String t0,String t1,int startIdx){
    
    
    mstart=inpt.indexOf(t0,startIdx);
    mend=inpt.indexOf(t1,startIdx);
    if(mstart == -1 || mend == -1 || mstart >= mend )  {
            LastNF=-1;
            return "-1";
          }
      this.LastNF=1;    
      this.LastIdx=inpt.indexOf(t1,startIdx)+1;
      return inpt.substring(inpt.indexOf(t0,startIdx)+t0.length(),inpt.indexOf(t1,startIdx));
     }
    
    public int lastFind(){
     return this.LastIdx; 
    }
    
    
    
    
    
    public int lastFoundStatus(){
     return this.LastNF; 
    }
    
     public void reset(){
      this.LastNF=0; 
      this.LastIdx=0;
    }
    
    
  }


     
  
  
}  


Tutorials

Linux System Admin Tips: There are over 200 Linux tips and tricks in this article. That is over 100 pages covering everything from NTP, setting up 2 IP address on one NIC, sharing directories among several users, putting running jobs in the background, find out who is doing what on your system by examining open sockets and the ps command, how to watch a file, how to prevent even root from deleting a file, tape commands, setting up cron jobs, using rsync, using screen conveniently with emacs, how to kill every process for a user, security tips and a lot more. These tip grow weekly. The above link will download the text version for easy grep searching. There is also an html version here.

Breaking Firewalls with OpenSSH and PuTTY: If the system administrator deliberately filters out all traffic except port 22 (ssh), to a single server, it is very likely that you can still gain access other computers behind the firewall. This article shows how remote Linux and Windows users can gain access to firewalled samba, mail, and http servers. In essence, it shows how openSSH and Putty can be used as a VPN solution for your home or workplace.

MySQL Tips and Tricks: Find out who is doing what in MySQL and how to kill the process, create binary log files, connect, create and select with Perl and Java, remove duplicates in a table with the index command, rollback and how to apply, merging several tables into one, updating foreign keys, monitor port 3306 with the tcpdump command, creating a C API, complex selects, and much more.

Create a Live Linux CD - BusyBox and OpenSSH Included: These steps will show you how to create a functioning Linux system, with the latest 2.6 kernel compiled from source, and how to integrate the BusyBox utilities including the installation of DHCP. Plus, how to compile in the OpenSSH package on this CD based system. On system boot-up a filesystem will be created and the contents from the CD will be uncompressed and completely loaded into RAM -- the CD could be removed at this point for boot-up on a second computer. The remaining functioning system will have full ssh capabilities. You can take over any PC assuming, of course, you have configured the kernel with the appropriate drivers and the PC can boot from a CD. This tutorial steps you through the whole processes.

SQLite Tutorial : This article explores the power and simplicity of sqlite3, first by starting with common commands and triggers, then the attach statement with the union operation is introduced in a way that allows multiple tables, in separate databases, to be combined as one virtual table, without the overhead of copying or moving data. Next, the simple sign function and the amazingly powerful trick of using this function in SQL select statements to solve complex queries with a single pass through the data is demonstrated, after making a brief mathematical case for how the sign function defines the absolute value and IF conditions.

The Lemon Parser Tutorial: This article explains how to build grammars and programs using the lemon parser, which is faster than yacc. And, unlike yacc, it is thread safe.

How to Compile the 2.6 kernel for Red Hat 9 and 8.0 and get Fedora Updates: This is a step by step tutorial on how to compile the 2.6 kernel from source.

Virtual Filesystem: Building A Linux Filesystem From An Ordinary File. You can take a disk file, format it as ext2, ext3, or reiser filesystem and then mount it, just like a physical drive. Yes, it then possible to read and write files to this newly mounted device. You can also copy the complete filesystem, since it is just a file, to another computer. If security is an issue, read on. This article will show you how to encrypt the filesystem, and mount it with ACL (Access Control Lists), which give you rights beyond the traditional read (r) write (w) and execute (x) for the 3 user groups file, owner and other.

Working With Time: What? There are 61 seconds in a minute? We can go back in time? We still tell time by the sun?



Chirico img Mike Chirico, a father of triplets (all girls) lives outside of Philadelphia, PA, USA. He has worked with Linux since 1996, has a Masters in Computer Science and Mathematics from Villanova University, and has worked in computer-related jobs from Wall Street to the University of Pennsylvania. His hero is Paul Erdos, a brilliant number theorist who was known for his open collaboration with others.


Mike's notes page is souptonuts. For open source consulting needs, please send an email to mchirico@gmail.com. All consulting work must include a donation to SourceForge.net.

SourceForge.net Logo


SourceForge.net Logo