FREEHAFER'S JAVA VERSION 1.2 HELP PAGE
THIS WEB SITE IS BY JOHN RICHARD FREEHAFER.
E-MAIL ADDRESS: nfn12346@naples.net
©1998
The following are complete programs for a Java JDK Version 1.2 compiler:
Java application creates a file, writes to a file, and appends a file!
import java.io.*; class f1 {//This program creates a file c:\temp\test.doc and writes data to it unless another path is entered after the command line java f1. public static void main (String args[]) { String filepath = "c:/temp/test.doc";//default file path System.out.println("\n Enter 'java f1 drive:/filepath/name.extension' or the file\n c:/temp/test.doc is created, writen to and appended\n by default! John Richard Freehafer is cool!"); for (int i = 0; i < args.length; i++) { filepath = args[i]; } System.out.println("\n The file " + filepath + " was opened, written to, and appended!"); try { FileOutputStream fout = new FileOutputStream(filepath); PrintStream OutputToFile = new PrintStream(fout); OutputToFile.println("RÖÄK NOG!\nTINY BUBBLES MAKE ME FEEL FINE!\nMATH IS OUR FRIEND!"); OutputToFile.println(7 + " * " + 3 + " = " + (7 * 3)); OutputToFile.println(15 + " / " + 5 + " = " + (15 / 5)); } catch (IOException e) { System.out.println("Error opening file: " + e); } //append string to file try { RandomAccessFile raf = new RandomAccessFile(filepath, "rw");//open file as both read and write raf.seek(raf.length());//go to end of file raf.writeBytes("\n(C)1998 INNIEA PUBLISHING COMPANY!\n");//write to file } catch (IOException e) { System.out.println("Error opening file: " + e); } } }
Download and try this Java application freeware to create
a file, write to the file, and append the file in *.ZIP format!
After you download and unzip this file change its name to f1.class!
Display a picture that changes size!
import java.awt.*; public class ps extends java.applet.Applet implements Runnable { Image picture; Thread runner; public void start() { if (runner == null) { runner = new Thread(this); runner.start(); } } public void stop() { if (runner != null) { runner.stop(); runner = null; } } public void run() { while (true) { repaint(); try { Thread.sleep(1000); } catch (InterruptedException e) { } } } public void init() { picture = getImage(getCodeBase(), "p1.jpg"); } public void paint (Graphics g) { setBackground(Color.magenta); g.drawString("THIS APPLET DISPLAYS A PICTURE THAT CHANGES SIZE!", 10, 25); int iwidth = picture.getWidth(this); int iheight = picture.getHeight(this); //increase picture size for (int xy = 0; xy < iwidth*iheight; xy+=200){ g.drawImage(picture, 20, 40, xy/iheight, xy/iwidth, this); }//end of for loop //decrease picture size for (int xy = iwidth*iheight; xy > 0; xy-=200){ g.drawImage(picture, 20, 40, xy/iheight, xy/iwidth, this); }//end of for loop } }
TOUCH THIS TO GO BACK TO THE HOME PAGE!