Miscellaneous Code Dump

Mama-I-just-wanna-learn-Java or the Gosh-Java-is-soooo-simple ! types. However, if you don't mind lurking in the techno-wilderness of a Programming Language that's spreading like wild fire, hoping to catch a flicker yourself, read on....


Program 1
import java.applet.*;
import java.awt.*;
public class zzz extends Applet {
	public void paint(Graphics g)
	{
		showStatus(g.getClipRect().toString());
	}
}

Program 2 import java.applet.*; import java.awt.*; public class zzz extends Applet { Color d; Color c; public void init() { c = getBackground(); d = new Color(255,0,0); setBackground(d); } public void paint(Graphics g) { showStatus(c.toString()); } }

Program 3 import java.applet.*; import java.awt.*; public class zzz extends Applet { public void paint(Graphics g) { showStatus(g.toString()); } }

Program 4 import java.applet.*; import java.awt.*; public class zzz extends Applet { public boolean mouseDown(Event e, int x,int y) { Graphics g = getGraphics(); g.setColor(Color.red); g.drawLine(0,0,x,y); return true; } }

Program 5 import java.applet.*; import java.awt.*; public class zzz extends Applet { Button b; public void init() { b =new Button("hell"); add(b); } public boolean mouseDown(Event e, int x,int y) { Toolkit t1 = b.getToolkit(); Toolkit t = getToolkit(); showStatus("size "+t.getScreenSize()+ "button " + t1.getScreenSize()); return true; } }

Program 6 import java.applet.*; import java.awt.*; public class zzz extends Applet { Button b; public void init() { b =new Button("hell"); add(b); add(new Button("hi")); } public boolean mouseDown(Event e, int x,int y) { Component c = b.getParent(); c.hide(); return true; } }

Program 7 import java.applet.*; import java.awt.*; public class zzz extends Applet { Button b; public void init() { b =new Button("hell"); add(b); add(new Button("hi")); } public boolean mouseDown(Event e, int x,int y) { Component c; c = getComponent(1); Button j; j = (Button ) c; showStatus(j.getLabel()); return true; } }

Program 8 import java.applet.*; import java.awt.*; public class zzz extends Applet { Button b; public void init() { b =new Button("hell"); add(b); add(new Button("hi")); } public boolean mouseDown(Event e, int x,int y) { showStatus(b.bounds().toString() + ".." + b.location().toString()); return true; } }

Program 9 import java.applet.*; import java.awt.*; public class zzz extends Applet { Button b; public void init() { b =new Button("hell"); add(b); add(new Button("hi")); } public boolean mouseDown(Event e, int x,int y) { showStatus(preferredSize().toString()); return true; } }

Program 10 import java.applet.*; import java.awt.*; public class zzz extends Applet { Scrollbar s; public void init() { setLayout(new BorderLayout()); s = new Scrollbar(Scrollbar.HORIZONTAL,10,5,1,100); add("North",s); } public boolean mouseDown(Event e, int x,int y) { s.setValue(s.getValue()+5); showStatus("value " + s.getValue()); return true; } }

Program 11 import java.applet.*; import java.awt.*; public class zzz extends Applet { Button b; public void init() { b = new Button("hell"); add(b); } public void paint(Graphics g) { showStatus(b.getClass().getName() + "..." + b.getClass().toString()); } }

Program 12 import java.applet.*; import java.awt.*; public class zzz extends Applet { Button b;Class c;Class d; public void init() { b = new Button("hell"); c = b.getClass(); d = c.getSuperclass(); add(b); } public void paint(Graphics g) { showStatus(d.getName()); } }

Program 13 import java.applet.*; import java.awt.*; public class zzz extends Applet { Button b; Class c; Button b1; public void init() { b = new Button("hell"); c = b.getClass(); try b1 = ( Button ) c.newInstance(); catch ( Exception e) { showStatus("error"); } add(b); b1.setLabel("good"); add(b1); } }

Program 14 import java.lang.*; import java.applet.*; import java.awt.*; import java.net.*; public class zzz extends Applet { SecurityManager s;Object o;Class c; public void init() { s = System.getSecurityManager(); o = s.getSecurityContext(); c = o.getClass(); } public void paint(Graphics g) { showStatus(c.getName()); } }

Program 15 import java.lang.*; import java.applet.*; import java.awt.*; import java.net.*; public class zzz extends Applet { SecurityManager s;URL u; public void init() { s = System.getSecurityManager(); u = (URL ) s.getSecurityContext(); } public void paint(Graphics g) { showStatus(u.toString()+".."+u.getProtocol()+".."+u.getHost()+".."+u.getRef()); } }

Program 16 import java.lang.*; import java.applet.*; import java.awt.*; import java.net.*; public class zzz extends Applet { SecurityManager s; public void init() { s = System.getSecurityManager(); } public void paint(Graphics g) { boolean b = s.checkTopLevelWindow(this); if ( b ) showStatus("true"); else showStatus("false"); } }

Program 17 import java.lang.*; import java.applet.*; import java.awt.*; import java.net.*; public class zzz extends Applet { SecurityManager s; public void init() { s = System.getSecurityManager(); } public void paint(Graphics g) { try s.checkPackageAccess("java.net"); catch (SecurityException e ) { showStatus("error");} } }

Program 18 import java.lang.*; import java.applet.*; import java.awt.*; import java.net.*; public class zzz extends Applet { SecurityManager s; public void init() { s = System.getSecurityManager(); } public void paint(Graphics g) { try s.checkRead("a.txt"); catch (SecurityException e ) { showStatus("error");} } }

Program 19 import java.lang.*; import java.applet.*; import java.awt.*; import java.net.*; public class zzz extends Applet { SecurityManager s; public void init() { s = System.getSecurityManager(); } public void paint(Graphics g) { try s.checkExec("DIR"); catch (SecurityException e ) { showStatus("error");} } }

Program 20 import java.lang.*; import java.applet.*; import java.awt.*; import java.net.*; public class zzz extends Applet { public void paint(Graphics g) { showStatus(System.getProperty("java.vendor")); } }

Program 21 import java.lang.*; import java.applet.*; import java.awt.*; import java.net.*; import java.util.*; public class zzz extends Applet implements Runnable { Class c; Class c1; String s; Frame w; int n=0; Button b; Label l; Thread t; public void init() { setLayout(new GridLayout(2,0)); add(b=new Button("Click here to bring up a zzz Window")); b.setFont(new Font("Helvetica", Font.PLAIN, 14)); add(l = new Label("", Label.CENTER)); try c = Class.forName("zzz"); catch (Exception e) { l.setText("Can't create window:Couldn't find class zzz "); b.disable(); return; } System.out.println(c.getName()); c1 = c; s = c1.getName(); while (!(s.equals("java.lang.Object")||s.equals("java.awt.Frame"))) { c1 = c1.getSuperclass(); s = c1.getName(); System.out.println(c1.getName() + "..." + s); } if ( (s == null) || s.equals("java.lang.Object") ) { l.setText("Can't create window:zzz isn't a Frame subclass."); b.disable(); return ; } t = new Thread(this, "Bringing Up zzz Window"); t.start(); } public synchronized void run() { while ( true ) { System.out.println("Before Try"); try wait(); catch (InterruptedException e) {} System.out.println("After Try"); try w = (Frame)c.newInstance(); catch (Exception e) { l.setText("Couldn't create instance of class zzz"); return ; } w.setTitle("Window no " + n ); n++; w.show(); l.setText(""); } } public synchronized boolean action(Event e, Object o) { if (e.target instanceof Button) { l.setText("Please wait while the window comes up..."); notify(); return true; } return false; } } class zzz extends Frame { }

Program 22 import java.lang.*; import java.applet.*; import java.awt.*; import java.net.*; import java.util.*; public class zzz extends Applet { public void paint(Graphics g) { String s = "Hello how are you"; StringTokenizer t = new StringTokenizer(s); while ( t.hasMoreTokens() ) { String s1 = t.nextToken(); System.out.println(s1); } } }

Program 23 import java.lang.*; import java.applet.*; import java.awt.*; import java.net.*; import java.util.*; public class zzz extends Applet { Panel z; public void init() { setLayout(new BorderLayout()); Panel p = new Panel(); Choice c = new Choice(); c.addItem("Button"); c.addItem("Text"); p.add(c); add("North",p); z = new Panel(); z.setLayout(new CardLayout()); Panel p1 = new Panel(); p1.add(new Button("Button 1")); p1.add(new Button("Button 2")); p1.add(new Button("Button 3")); Panel p2 = new Panel(); p2.add(new TextField("TextField", 20)); z.add("Button", p1); z.add("Text", p2); add("Center", z); } public boolean action(Event e, Object o) { if (e.target instanceof Choice) { CardLayout cl; cl = (CardLayout)z.getLayout(); cl.show(z, (String) o); showStatus((String) o); return true; } return false; } }

Program 24 import java.applet.*; import java.awt.*; public class zzz extends Applet { Scrollbar s; public void init() { setLayout(new BorderLayout()); s = new Scrollbar(Scrollbar.HORIZONTAL,20,5,1,100); add("North",s); } public boolean mouseDown(Event e, int x,int y) { s.setValue(s.getValue()+5); showStatus("value " + s.getValue()); return true; } }

Program 25 import java.lang.*; import java.applet.*; import java.awt.*; import java.net.*; import java.util.*; public class zzz extends Applet implements Runnable { Class c; Class c1; String s; Frame w; int n=0; Button b; Label l; Thread t; public void init() { setLayout(new GridLayout(2,0)); add(b=new Button("Click here to bring up a zzz Window")); b.setFont(new Font("Helvetica", Font.PLAIN, 14)); add(l = new Label("", Label.CENTER)); try c = Class.forName("zzz"); catch (Exception e) { l.setText("Can't create window:Couldn't find class zzz1 "); b.disable(); return; } System.out.println(c.getName()); c1 = c; s = c1.getName(); while (!(s.equals("java.lang.Object")||s.equals("java.awt.Frame"))) { c1 = c1.getSuperclass(); s = c1.getName(); System.out.println(c1.getName() + "..." + s); } if ( (s == null) || s.equals("java.lang.Object") ) { l.setText("Can't create window:zzz1 isn't a Frame subclass."); b.disable(); return ; } t = new Thread(this, "Bringing Up zzz1 Window"); t.start(); } public synchronized void run() { while ( true ) { System.out.println("Before Try"); try wait(); catch (InterruptedException e) {} System.out.println("After Try"); try w = (Frame)c.newInstance(); catch (Exception e) { l.setText("Couldn't create instance of class zzz"); return ; } w.setTitle("Window no " + n ); n++; w.show(); l.setText(""); } } public synchronized boolean action(Event e, Object o) { if (e.target instanceof Button) { l.setText("Please wait while the window comes up..."); notify(); return true; } return false; } } class zzz1 extends Frame { }


If all this glop didn't want you wanting to hibernate, rush on to the next topic "The C++ Connection" or now that you are here, take out a couple of minutes and toss your comments, feedback, suggestions etc. to us (we'll love the etc. )


Vijay Mukhi's Computer Institute
B-13, Everest Building, Tardeo, Bombay 400 034, India.
http://www.neca.com/~vmis
e-mail : vmukhi@giasbm01.vsnl.net.in