import java.applet.Applet; import java.awt.*; ************************** /** Eight ungrouped buttons in an Applet using FlowLayout. * */ public class ButtonTest1 extends Applet { public void init() { String[] labelPrefixes = { "Start", "Stop", "Pause", "Resume" }; for (int i=0; i<4; i++) { add(new Button(labelPrefixes[i] + " Thread1")); } for (int i=0; i<4; i++) { add(new Button(labelPrefixes[i] …
Category: FromSitesTree.com
May 07
Eight buttons: four each in two panels #Programming Code Examples #Java/J2EE/J2ME #AWT Components
import java.applet.Applet; import java.awt.*; *************************** /** Eight buttons: four each in two panels. * */ public class ButtonTest2 extends Applet { public void init() { String[] labelPrefixes = { "Start", "Stop", "Pause", "Resume" }; Panel p1 = new Panel(); for (int i=0; i<4; i++) { p1.add(new Button(labelPrefixes[i] + " Thread1")); } Panel p2 = new …
May 07
NumFormat.java Formats real numbers with DecimalFormat. #Programming Code Examples #Java/J2EE/J2ME #Basic Java
import java.text.*; /** Formatting real numbers with DecimalFormat. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * © 2001 Marty Hall and Larry Brown; * may be freely used or adapted. */ public class NumFormat { public static void main (String[] args) { DecimalFormat science = …
May 07
StringTest.java Demonstrates various methods of the String class. #Programming Code Examples #Java/J2EE/J2ME #Basic Java
/** Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * © 2001 Marty Hall and Larry Brown; * may be freely used or adapted. */ public class StringTest { public static void main (String[] args) { String str = ""; if (args.length > 0) { str = args[0]; …
May 07
DropBall.java Uses a while loop to determine how long it takes a ball to fall from the top of the Washington Monument to the ground #Programming Code Examples #Java/J2EE/J2ME #Basic Java
DropBall.java Uses a while loop to determine how long it takes a ball to fall from the top of the Washington Monument to the ground ************************************************************ /** Simulating dropping a ball from the top of the Washington * Monument. The program outputs the height of the ball each * second until the ball hits the …
May 07
Basic Hello World application #Programming Code Examples #Java/J2EE/J2ME #Basic Java
******************* HelloWorld.java Basic Hello World application. ******************* */ public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world."); } } /* Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10397 Categories:Programming Code Examples, Java/J2EE/J2ME, Basic JavaTags:Java/J2EE/J2MEBasic Java Post Data:2017-01-02 16:04:39 Shop Online: https://www.ShopForSoul.com/ (Big Data, Cloud, Security, Machine Learning): …
May 07
Application that reports all command-line arguments #Programming Code Examples #Java/J2EE/J2ME #Basic Java
****************** ShowArgs.java Application that reports all command-line arguments. ****************** */ public class ShowArgs { public static void main(String[] args) { for(int i=0; i<args .length; i++) { System.out.println("Arg " + i + " is " + args[i]); } } } /* Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10398 Categories:Programming Code …
May 07
HelloWWW.java Basic Hello World (Wide Web) Applet #Programming Code Examples #Java/J2EE/J2ME #Basic Java
********************* import java.applet.Applet; import java.awt.*; ********************* public class HelloWWW extends Applet { private int fontSize = 40; public void init() { setBackground(Color.black); setForeground(Color.white); setFont(new Font("SansSerif", Font.BOLD, fontSize)); } public void paint(Graphics g) { g.drawString("Hello, World Wide Web.", 5, fontSize+5); } } < <<<<<<<<<<<<<<<<<<<< Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: …
May 06
TreeTest.java Builds a binary tree and prints the contents of the nodes. Uses the following classes: #Programming Code Examples #Java/J2EE/J2ME #Basic Java
Treetest.java /** A NodeOperator that prints each node. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * © 2001 Marty Hall and Larry Brown; * may be freely used or adapted. */ class PrintOperator implements NodeOperator { public void operateOn(Node node) { System.out.println(node.getNodeValue()); } } /** …
May 06
ModificationTest.java Demonstrates changing fields of an object. Inherits from ReferenceTest.java. #Programming Code Examples #Java/J2EE/J2ME #Basic Java
/** Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * © 2001 Marty Hall and Larry Brown; * may be freely used or adapted. */ import java.awt.Point; public class ModificationTest extends ReferenceTest { public static void main(String[] args) { Point p1 = new Point(1, 2); // Assign Point …
