JavaTextField.java #Programming Code Examples #Java/J2EE/J2ME #Mouse and Keyboard Events

import java.applet.Applet;
import java.awt.*;

/** Lets the user enter the name of any
 *  good programming language. Or does it?
 *  

********************* public class JavaTextField extends Applet { public void init() { setFont(new Font("Serif", Font.BOLD, 14)); setLayout(new GridLayout(2, 1)); add(new Label("Enter a Good Programming Language", Label.CENTER)); LanguageField langField = new LanguageField(); Font langFont = new Font("SansSerif", Font.BOLD, 18); langField.setFont(langFont); add(langField); } }

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10368
Categories:Programming Code Examples, Java/J2EE/J2ME, Mouse and Keyboard Events
Tags:Java/J2EE/J2MEMouse and Keyboard Events
Post Data:2017-01-02 16:04:35

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

A TextField that uses key events to correct the spelling of the names of computer languages entered into it #Programming Code Examples #Java/J2EE/J2ME #Mouse and Keyboard Events

import java.awt.*;
import java.awt.event.*;

/** A spelling-correcting TextField for entering
 *  a language name.
 *  

******************* public class LanguageField extends TextField { private String[] substrings = { "", "J", "Ja", "Jav", "Java" }; public LanguageField() { addKeyListener(new SpellingCorrector()); addActionListener(new WordCompleter()); addFocusListener(new SubliminalAdvertiser()); } // Put caret at end of field. private void setCaret() { setCaretPosition(5); } // Listener to monitor/correct spelling as user types. private class SpellingCorrector extends KeyAdapter { public void keyTyped(KeyEvent event) { setLanguage(); setCaret(); } // Enter partial name of good programming language that // most closely matches what they've typed so far. private void setLanguage() { int length = getText().length(); if (length < = 4) { setText(substrings[length]); } else { setText("Java"); } setCaret(); } } // Listener to replace current partial name with // most closely-matching name of good language. private class WordCompleter implements ActionListener { // When they hit RETURN, fill in the right answer. public void actionPerformed(ActionEvent event) { setText("Java"); setCaret(); } } // Listener to give the user a hint. private class SubliminalAdvertiser extends FocusAdapter { public void focusGained(FocusEvent event) { String text = getText(); for(int i=0; i<10; i++) { setText("Hint: Java"); setText(text); } } } }

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10367
Categories:Programming Code Examples, Java/J2EE/J2ME, Mouse and Keyboard Events
Tags:Java/J2EE/J2MEMouse and Keyboard Events
Post Data:2017-01-02 16:04:35

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Applet that uses processXxx methods to print detailed reports on mouse events. Illustrates low-level alternative to handling events with listeners. #Programming Code Examples #Java/J2EE/J2ME #Mouse and Keyboard Events

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*; 

/** Prints non-detailed reports of mouse events.
 *  Uses the low-level processXxxEvent methods instead
 *  of the usual event listeners.
 *  

***************** public class MouseReporter extends Applet { public void init() { setBackground(Color.blue); // So you can see applet in page enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK); } public void processMouseEvent(MouseEvent event) { System.out.println("Mouse enter/exit or click at (" + event.getX() + "," + event.getY() + ")."); // In case there are MouseListeners attached: super.processMouseEvent(event); } public void processMouseMotionEvent(MouseEvent event) { System.out.println("Mouse move/drag at (" + event.getX() + "," + event.getY() + ")."); // In case there are MouseMotionListeners attached: super.processMouseMotionEvent(event); } }

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10366
Categories:Programming Code Examples, Java/J2EE/J2ME, Mouse and Keyboard Events
Tags:Java/J2EE/J2MEMouse and Keyboard Events
Post Data:2017-01-02 16:04:35

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Applet that uses a anonymous nested class to handle mouse events and draw circles. Variation on third approach to event-handling: using inner classes. #Programming Code Examples #Java/J2EE/J2ME #Mouse and Keyboard Events

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

/** Draw circles centered where the user clicks.
 *  Uses anonymous inner classes.
 *  

********************** public class CircleDrawer4 extends Applet { public void init() { setForeground(Color.blue); addMouseListener (new MouseAdapter() { private int radius = 25; public void mousePressed(MouseEvent event) { Graphics g = getGraphics(); g.fillOval(event.getX()-radius, event.getY()-radius, 2*radius, 2*radius); } }); } } *******************

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10365
Categories:Programming Code Examples, Java/J2EE/J2ME, Mouse and Keyboard Events
Tags:Java/J2EE/J2MEMouse and Keyboard Events
Post Data:2017-01-02 16:04:35

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

CircleDrawer3.java Applet that uses a named nested class to handle mouse events and draw circles. Illustrates third approach to event-handling with listeners: using inner classes. #Programming Code Examples #Java/J2EE/J2ME #Mouse and Keyboard Events

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

/** Draw circles centered where the user clicks.
 *  Uses named inner classes.
 *  

****************** public class CircleDrawer3 extends Applet { public void init() { setForeground(Color.blue); addMouseListener(new CircleListener()); } private class CircleListener extends MouseAdapter { private int radius = 25; public void mousePressed(MouseEvent event) { Graphics g = getGraphics(); g.fillOval(event.getX()-radius, event.getY()-radius, 2*radius, 2*radius); } } }

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10364
Categories:Programming Code Examples, Java/J2EE/J2ME, Mouse and Keyboard Events
Tags:Java/J2EE/J2MEMouse and Keyboard Events
Post Data:2017-01-02 16:04:35

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Tiny applet that uses CircleListener to handle mouse events. #Programming Code Examples #Java/J2EE/J2ME #Mouse and Keyboard Events

import java.applet.Applet;
import java.awt.*;

/** Draw circles centered where the user clicks.
 *  Uses an external listener.
 *  

*********** public class CircleDrawer1 extends Applet { public void init() { setForeground(Color.blue); addMouseListener(new CircleListener()); } }

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10362
Categories:Programming Code Examples, Java/J2EE/J2ME, Mouse and Keyboard Events
Tags:Java/J2EE/J2MEMouse and Keyboard Events
Post Data:2017-01-02 16:04:35

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

A simple applet that uses the ClickListener class #Programming Code Examples #Java/J2EE/J2ME #Mouse and Keyboard Events

ClickReporter.java A simple applet that uses the ClickListener class to handle mouse events.
***************
import java.applet.Applet;
import java.awt.*;

/** Prints a message saying where the user clicks.
 *  Uses an external listener.
 *  

****** public class ClickReporter extends Applet { public void init() { setBackground(Color.yellow); addMouseListener(new ClickListener()); } }

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10360
Categories:Programming Code Examples, Java/J2EE/J2ME, Mouse and Keyboard Events
Tags:Java/J2EE/J2MEMouse and Keyboard Events
Post Data:2017-01-02 16:04:35

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Applet handle mouse events #Programming Code Examples #Java/J2EE/J2ME #Mouse and Keyboard Events

%%%%%%%%%%%%%%
ClickReporter.java A simple applet that uses the class to handle mouse events
%%%%%%%%%%%%%%
import java.applet.Applet;
import java.awt.*;

/** Prints a message saying where the user clicks.
* Uses an external listener.
*

*******************

public class ClickReporter extends Applet {
public void init() {
setBackground(Color.yellow);
addMouseListener(new ClickListener());
}
}
%%%%%%%%%%%%%%

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017

From: http://sitestree.com/?p=10359
Categories:Programming Code Examples, Java/J2EE/J2ME, Mouse and Keyboard Events
Tags:Java/J2EE/J2MEMouse and Keyboard Events
Post Data:2017-01-02 16:04:35

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Subclass of MouseAdapter #Programming Code Examples #Java/J2EE/J2ME #Mouse and Keyboard Events

!!!!!!!!!!!!
ClickListener.java A simple subclass of MouseAdapter that reports where the mouse was pressed. When attached to an applet, look for the report in the Java Console.
!!!!!!!!!!!!
import java.awt.event.*;

/** The listener used by ClickReporter.
 *  

************** public class ClickListener extends MouseAdapter { public void mousePressed(MouseEvent event) { System.out.println("Mouse pressed at (" + event.getX() + "," + event.getY() + ")."); } } < <<<<<<<<<<<<<

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10358
Categories:Programming Code Examples, Java/J2EE/J2ME, Mouse and Keyboard Events
Tags:Java/J2EE/J2MEMouse and Keyboard Events
Post Data:2017-01-02 16:04:35

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

# RMI Example – Numerical Integration, a more realistic RMI example that sends an evaluatable object (function) from a client to a server for numerical integration. #Programming Code Examples #Java/J2EE/J2ME #Network Programming

# RMI Example - Numerical Integration, a more realistic RMI example that sends an evaluatable object (function) from a client to a server for numerical integration. 

Integral.java  Performs actual numerical integration of the function (evaluatable object).

/** A class to calculate summations and numeric integrals. The
 *  integral is calculated according to the midpoint rule.
 *
 *  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 Integral {
  /** Returns the sum of f(x) from x=start to x=stop, where the
   *  function f is defined by the evaluate method of the
   *  Evaluatable object.
   */

  public static double sum(double start, double stop,
                           double stepSize,
                           Evaluatable evalObj) {
    double sum = 0.0, current = start;
    while (current  0) ? args[0] : "localhost";
      RemoteIntegral remoteIntegral =
        (RemoteIntegral)Naming.lookup("rmi://" + host +
                                      "/RemoteIntegral");
      for(int steps=10; steps 0) ? args[0] : "localhost";
      RemoteIntegral remoteIntegral =
        (RemoteIntegral)Naming.lookup("rmi://" + host +
                                      "/RemoteIntegral");
      for(int steps=10; steps< =10000; steps*=10) {
        System.out.println
          ("Approximated with " + steps + " steps:" +
           "n  Integral from 0 to pi of sin(x)=" +
           remoteIntegral.integrate(0.0, Math.PI,
                                    steps, new Sin()) +
           "n  Integral from pi/2 to pi of cos(x)=" +
           remoteIntegral.integrate(Math.PI/2.0, Math.PI,
                                    steps, new Cos()) +
           "n  Integral from 0 to 5 of x^2=" +
           remoteIntegral.integrate(0.0, 5.0, steps,
                                    new Quadratic()));
      }
      System.out.println
        ("`Correct' answer using Math library:" +
         "n  Integral from 0 to pi of sin(x)=" +
         (-Math.cos(Math.PI) - -Math.cos(0.0)) +
         "n  Integral from pi/2 to pi of cos(x)=" +
         (Math.sin(Math.PI) - Math.sin(Math.PI/2.0)) +
         "n  Integral from 0 to 5 of x^2=" +
         (Math.pow(5.0, 3.0) / 3.0));
    } catch(RemoteException re) {
      System.out.println("RemoteException: " + re);
    } catch(NotBoundException nbe) {
      System.out.println("NotBoundException: " + nbe);
    } catch(MalformedURLException mfe) {
      System.out.println("MalformedURLException: " + mfe);
    }
  }
}

rmiclient.policy  Policy file for the client. Grants permissions for the client to connect to the RMI server and Web server. 

//  Taken from Core Web Programming from
//  Prentice Hall and Sun Microsystems Press,
//  .
//  © 2001 Marty Hall and Larry Brown;
//  may be freely used or adapted.

grant {
  // rmihost - RMI registry and the server
  // webhost - HTTP server for stub classes
  permission java.net.SocketPermission 
    "rmihost:1024-65535", "connect";
  permission java.net.SocketPermission 
    "webhost:80", "connect";
};



Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10239
Categories:Programming Code Examples, Java/J2EE/J2ME, Network Programming
Tags:Java/J2EE/J2MENetwork Programming
Post Data:2017-01-02 16:04:28

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada