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...
 

Miscellaneous Code Dump (Applets)

Custom Search
Miscellaneous Code Dump (Applets)

[ Return to Shlurrrpp......Java ]




Miscellaneous Code Dump

Miscellaneous Code Dump

 Hi folks! This page is under construction, and full-fledgedly so. As the name suggests, we have used this page as a sort of recycle bin. This page is, therefore, presently meant exclusively for the 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



[ Return to Shlurrrpp......Java ]


Top 10 read Java Articles
 Get free "1000 Java Tips eBook"

 Java Calendar and Date: good to know facts and code examples

 Array vs ArrayList vs LinkedList vs Vector: an excellent overview and examples

 How can I convert any Java Object into byte array? And byte array to file object

 The Java Lesson 1: What is Java?

 How do I compare two dates and times, date between dates, time between times and

 Maven vs Ant or Ant vs Maven?

 How to open, read, write, close file(s) in Java? Examples on move, rename and de

 Java Array

 Java: JLabel font and color


[ More in News Section ]
Java Lessons

The Java Lesson 1:
What is Java?
The Java Lesson 2:
Anatomy of a simple Java program
The Java Lesson 3:
Identifiers and primitive data types
The Java Lesson 4:
Variables, constants, and literals
The Java Lesson 5:
Arithmetic operations, conversions, and casts
The Java Lesson 6:
Boolean expressions and operations
The Java Lesson 7:
Bitwise operations
The Java Lesson 8:
Flow control with if and else
The Java Lesson 9:
switch statements
The Java Lesson 10:
for, while, and do-while statements
The Java Lesson 11:
Using break and continue
The Java Lesson 12:
Class methods and how they are called
The Java Lesson 13:
Using the Math class
The Java Lesson 14:
Creating and calling custom class methods
The Java Lesson 15:
Overloading class methods
The Java Lesson 16:
An introduction to objects and object references
The Java Lesson 17:
The String class
The Java Lesson 18:
The StringBuffer class
The Java Lesson 19:
Initializing and processing arrays of primitives
The Java Lesson 20:
Initializing and processing arrays of objects
The Java Lesson 23:
Inheritance and overriding inherited methods
The Java Lesson 24:
abstract classes and polymorphism
The Java Lesson 25:
Interfaces, instanceof, and object conversion and casting
The Java Lesson 26:
Introduction to graphical programming and the java.awt packa
The Java Lesson 27:
The Component class
The Java Lesson 28:
Containers and simple layout managers
The Java Lesson 29:
The Color and Font classes
The Java Lesson 30:
Drawing geometric shapes
The Java Lesson 31:
Choice, List, and Checkbox controls
The Java Lesson 32:
Using the Scrollbar graphical control
The Java Lesson 33:
Menus and submenus
The Java Lesson 34:
An introduction to applets and the Applet class
The Java Lesson 35:
Essential HTML to launch an applet and pass it parameters
The Java Lesson 36:
Mouse event processing
Java Lesson 37:
Menus and submenus
Java Lesson 38:
The WindowListener interface and the WindowAdapter class
Java Lesson 39:
An introduction to GridBagLayout
Java Lesson 40:
An introduction to the Java Collections API
Java Lesson 41:
Exception handling with try, catch, and finally blocks
Java Lesson 42:
Claiming and throwing exceptions
Java Lesson 43:
Multithreading, the Thread class, and the Runnable interface
Java Lesson 44:
An introduction to I/O and the File and FileDialog classes
Java Lesson 45:
Low-level and high-level stream classes
Java Lesson 46:
Using the RandomAccessFile class
Java Lessons by
Joh Huhtala: Update

Latest articles
 Java Profiler JProbe to Resolve Performance Problems Faster

 SSL with GlassFish v2, page 5

 SSL with GlassFish v2, page 4

 SSL with GlassFish v2, page 3

 SSL with GlassFish v2, page 2

 The Java Lesson 2: Anatomy of a simple Java program, page 2

 New site about Java for robots and robotics: both software and hardware.

 Exceptions -III: What's an exception and why do I care?

 Exceptions -II: What's an exception and why do I care?

 Exceptions: What's an exception and why do I care?

 Double your Java code quality in 10 minutes, here is receipt

 Murach's Java Servlets and JSP

 How to get ascii code from a char in Java?

 Can we just try without catch? Yes!

 Make Tomcat page load faster

 Make your Tomcat More secure - limit network address for certain IP addresses

 New Java book online starts now here...

 Implementing RESTful Web Services in Java

 Firefox trimming from 1 GB to 40 Mb with many tabs opened

 SSL with GlassFish v2

 My request to replublish Tech Tips

 Search JavaFAQ.nu site here

 New Advanced Installer for Java 6.0 brings XML updates and imports 3rd party MSI

 EJB programming restrictions

 Maven vs Ant or Ant vs Maven?

 Why Java does not use default value which it should?

 How to unsign signed bytes in Java - your guide is here

 The Java Lesson 3: Identifiers and primitive data types. Page 2

 The Java Lesson 7: Bitwise operations with good examples, click here! Page 4

 The Java Lesson 7: Bitwise operations with good examples, click here! Page 3


[ More in News Section ]


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