Five buttons arranged by FlowLayout #Programming Code Examples #Java/J2EE/J2ME #Layout Managers

FlowTest.java 
*************
FlowTest.java Five buttons arranged by FlowLayout
By default, FlowLayout arranges components in rows, left to right, and centered. 
/././././././././././././
import java.applet.Applet;
import java.awt.*;

/** FlowLayout puts components in rows.
 *
 ************************************
public class FlowTest extends Applet {
  public void init() {
    for(int i=1; i<6; i++) {
      add(new Button("Button " + i));
    }
  }
}

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10344
Categories:Programming Code Examples, Java/J2EE/J2ME, Layout Managers
Tags:Java/J2EE/J2MELayout Managers
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

An applet that permits freehand drawing #Programming Code Examples #Java/J2EE/J2ME #Mouse and Keyboard Events

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

/** An applet that lets you perform freehand drawing.
 *  

**************** public class SimpleWhiteboard extends Applet { protected int lastX=0, lastY=0; public void init() { setBackground(Color.white); setForeground(Color.blue); addMouseListener(new PositionRecorder()); addMouseMotionListener(new LineDrawer()); } protected void record(int x, int y) { lastX = x; lastY = y; } // Record position that mouse entered window or // where user pressed mouse button. private class PositionRecorder extends MouseAdapter { public void mouseEntered(MouseEvent event) { requestFocus(); // Plan ahead for typing record(event.getX(), event.getY()); } public void mousePressed(MouseEvent event) { record(event.getX(), event.getY()); } } // As user drags mouse, connect subsequent positions // with short line segments. private class LineDrawer extends MouseMotionAdapter { public void mouseDragged(MouseEvent event) { int x = event.getX(); int y = event.getY(); Graphics g = getGraphics(); g.drawLine(lastX, lastY, x, y); record(x, y); } } }

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10369
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

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