DashedStrokeExample.java Draws a circle with a dashed line segment (border). Inherits from FontExample.java. #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

>>>>>>>>>>>>>>>>>
import java.awt.*;

/** An example of creating a custom dashed line for drawing.
 *
 *********************
public class DashedStrokeExample extends FontExample {
  public void paintComponent(Graphics g) {
    clear(g);
    Graphics2D g2d = (Graphics2D)g;
    drawGradientCircle(g2d);
    drawBigString(g2d);
    drawDashedCircleOutline(g2d);
  }

  protected void drawDashedCircleOutline(Graphics2D g2d) {
    g2d.setPaint(Color.blue);
    // 30-pixel line, 10-pixel gap, 10-pixel line, 10-pixel gap
    float[] dashPattern = { 30, 10, 10, 10 };
    g2d.setStroke(new BasicStroke(8, BasicStroke.CAP_BUTT,
                                  BasicStroke.JOIN_MITER, 10,
                                  dashPattern, 0));
    g2d.draw(getCircle());
  }

  public static void main(String[] args) {
    WindowUtilities.openInJFrame(new DashedStrokeExample(),
                                 380, 400);
  }
}
< <<<<<<<<<<<<<

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

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

Adds typing to the freehand drawing. #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

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

/** A better whiteboard that lets you enter
 *  text in addition to freehand drawing.
 *  

****************** public class Whiteboard extends SimpleWhiteboard { protected FontMetrics fm; public void init() { super.init(); Font font = new Font("Serif", Font.BOLD, 20); setFont(font); fm = getFontMetrics(font); addKeyListener(new CharDrawer()); } private class CharDrawer extends KeyAdapter { // When user types a printable character, // draw it and shift position rightwards. public void keyTyped(KeyEvent event) { String s = String.valueOf(event.getKeyChar()); getGraphics().drawString(s, lastX, lastY); record(lastX + fm.stringWidth(s), lastY); } } }

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

draws a circle wherever mouse was pressed #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

CircleListener.java A subclass of MouseAdapter that draws a circle wherever mouse was pressed. Illustrates first approach to event-handling with listeners: attaching a separate listener
***********
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

/** The listener used by CircleDrawer1. Note call
 *  to getSource to obtain reference to the applet.
 *  

*************** public class CircleListener extends MouseAdapter { private int radius = 25; public void mousePressed(MouseEvent event) { Applet app = (Applet)event.getSource(); Graphics g = app.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=10361
Categories:Programming Code Examples, Java/J2EE/J2ME, Advanced Swing
Tags:Java/J2EE/J2MEAdvanced Swing
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 demo providing multiple buttons to select a playing card-A Panel, using CardLayout control which of four possible subpanels, holding a different card, to display #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

#######################
# CardDemo.java A demo providing multiple buttons to select a playing card. A Panel, using CardLayout control which of four possible subpanels, holding a different card, to display.Uses the following class and images:
    * CardPanel.java A Panel that displays a playing card.
    * ImageLabel.java A Canvas for displaying images.
    * Ace.gif, King.gif, Queen.gif, Jack.gif.
#####################
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

/** An example of CardLayout. The right side of the window holds
 *  a Panel that uses CardLayout to control four possible
 *  subpanels (each of which is a CardPanel that shows a
 *  picture of a playing card). The buttons on the left side
 *  of the window manipulate the "cards" in this layout by
 *  calling methods in the right-hand panel's layout manager.
 *
 *********************************

public class CardDemo extends Applet implements ActionListener {
  private Button first, last, previous, next;
  private String[] cardLabels = { "Jack","Queen","King","Ace" };
  private CardPanel[] cardPanels = new CardPanel[4];
  private CardLayout layout;
  private Panel cardDisplayPanel;

  public void init() {
    setBackground(Color.white);
    setLayout(new BorderLayout());
    addButtonPanel();
    addCardDisplayPanel();
  }

  private void addButtonPanel() {
    Panel buttonPanel = new Panel();
    buttonPanel.setLayout(new GridLayout(9, 1));
    Font buttonFont = new Font("SansSerif", Font.BOLD, 18);
    buttonPanel.setFont(buttonFont);
    for(int i=0; i<cardlabels .length; i++) {
      Button button = new Button(cardLabels[i]);
      button.addActionListener(this);
      buttonPanel.add(button);
    }
    first = new Button("First");
    first.addActionListener(this);
    last = new Button("Last");
    last.addActionListener(this);
    previous = new Button("Previous");
    previous.addActionListener(this);
    next = new Button("Next");
    next.addActionListener(this);
    buttonPanel.add(new Label("------------", Label.CENTER));
    buttonPanel.add(first);
    buttonPanel.add(last);
    buttonPanel.add(previous);
    buttonPanel.add(next);
    add(buttonPanel, BorderLayout.WEST);
  }

  private void addCardDisplayPanel() {
    cardDisplayPanel = new Panel();
    layout = new CardLayout();
    cardDisplayPanel.setLayout(layout);
    String cardName;
    for(int i=0; i<cardLabels.length; i++) {
      cardName = cardLabels[i];
      cardPanels[i] =
        new CardPanel(cardName, getCodeBase(),
                      "images/" + cardName + ".gif");
      cardDisplayPanel.add(cardPanels[i], cardName);
    }
    add(cardDisplayPanel, BorderLayout.CENTER);
  }

  public void actionPerformed(ActionEvent event) {
    Button source = (Button)event.getSource();
    if (source == first)
      layout.first(cardDisplayPanel);
    else if (source == last)
      layout.last(cardDisplayPanel);
    else if (source == previous)
      layout.previous(cardDisplayPanel);
    else if (source == next)
      layout.next(cardDisplayPanel);
    else
      layout.show(cardDisplayPanel, source.getLabel());
    return;
  }
}
******************
CardPanel.java A Panel that displays a playing card. 
&&&&&&&&&&&&&&&&&&
import java.awt.*;
import java.net.*;

/** A Panel that displays a playing card. This window does
 *  not use CardLayout. Rather, instances of CardPanel
 *  are contained in another window used in the CardDemo
 *  example. It is this enclosing window that uses CardLayout
 *  to manipulate which CardPanel it shows.
 *
 *************************

public class CardPanel extends Panel {
  private Label name;
  private ImageLabel picture;

  public CardPanel(String cardName,
                   URL directory, String imageFile) {
    setLayout(new BorderLayout());
    name = new Label(cardName, Label.CENTER);
    name.setFont(new Font("SanSerif", Font.BOLD, 50));
    add(name, BorderLayout.NORTH);
    picture = new ImageLabel(directory, imageFile);
    Panel picturePanel = new Panel();
    picturePanel.add(picture);
    add(picturePanel, BorderLayout.CENTER);
    setSize(getPreferredSize());
  }

  public Label getLabel() {
    return(name);
  }

  public ImageLabel getImageLabel() {
    return(picture);
  }
}
*******************
ImageLabel.java A Canvas for displaying images.
*******************
import java.awt.*;
import java.net.*; 

/** A class for displaying images. It places the Image
 *  into a canvas so that it can moved around by layout
 *  managers, will get repainted automatically, etc.
 *  No mouseXXX or action events are defined, so it is
 *  most similar to the Label Component.
 *  

* By default, with FlowLayout the ImageLabel takes * its minimum size (just enclosing the image). The * default with BorderLayout is to expand to fill * the region in width (North/South), height * (East/West) or both (Center). This is the same * behavior as with the builtin Label class. If you * give an explicit setSize or * setBounds call before adding the * ImageLabel to the Container, this size will * override the defaults. *

* Here is an example of its use: *

*

 *  public class ShowImages extends Applet {
 *    private ImageLabel image1, image2;
 *
 *    public void init() {
 *      image1 = new ImageLabel(getCodeBase(),
 *                              "some-image.gif");
 *      image2 = new ImageLabel(getCodeBase(),
 *                              "other-image.jpg");
 *      add(image1);
 *      add(image2);
 *    }
 *  }
 *  

*
*/

public class ImageLabel extends Canvas {
// Instance variables.

// The actual Image drawn on the canvas.
private Image image;

// A String corresponding to the URL of the image you will
// get if you call the constructor with no arguments.
private static String defaultImageString
= "http://java.sun.com/lib/images/" +
"logo.java.color-transp.55x60.gif";

// The URL of the image. But sometimes we will use an existing
// image object (e.g. made by createImage) for which this info
// will not be available, so a default string is used here.
private String imageString = "";

// Turn this on to get verbose debugging messages.
private boolean debug = false;

/** Amount of extra space around the image. */

private int border = 0;

/** If there is a non-zero border, what color should it be?
* Default is to use the background color of the Container.
*/

private Color borderColor = null;

// Width and height of the Canvas. This is the
// width/height of the image plus twice the border.
private int width, height;

/** Determines if it will be sized automatically. If the user
* issues a setSize() or setBounds()call before adding the
* label to the Container, or if the LayoutManager resizes
* before drawing (as with BorderLayout), then those sizes
* override the default, which is to make the label the same
* size as the image it holds (after reserving space for the
* border, if any). This flag notes this, so subclasses that
* override ImageLabel need to check this flag, and if it is
* true, and they draw modified image, then they need to draw
* them based on the width height variables, not just blindly
* drawing them full size.
*/

private boolean explicitSize = false;
private int explicitWidth=0, explicitHeight=0;

// The MediaTracker that can tell if image has been loaded
// before trying to paint it or setSize based on its size.
private MediaTracker tracker;

// Used by MediaTracker to be sure image is loaded before
// paint & setSize, since you can't find out the size until it
// is done loading.
private static int lastTrackerID=0;
private int currentTrackerID;
private boolean doneLoading = false;

private Container parentContainer;

/** Create an ImageLabel with the default image.
*
* @see #getDefaultImageString
* @see #setDefaultImageString
*/
// Remember that the funny "this()" syntax calls
// constructor of same class
public ImageLabel() {
this(defaultImageString);
}

/** Create an ImageLabel using the image at URL
* specified by the string.
*
* @param imageURLString A String specifying the
* URL of the image.
*/

public ImageLabel(String imageURLString) {
this(makeURL(imageURLString));
}

/** Create an ImageLabel using the image at URL
* specified.
*
* @param imageURL The URL of the image.
*/

public ImageLabel(URL imageURL) {
this(loadImage(imageURL));
imageString = imageURL.toExternalForm();
}

/** Create an ImageLabel using the image in the file
* in the specified directory.
*
* @param imageDirectory Directory containing image
* @param file Filename of image
*/

public ImageLabel(URL imageDirectory, String file) {
this(makeURL(imageDirectory, file));
imageString = file;
}

/** Create an ImageLabel using the image specified. The other
* constructors eventually call this one, but you may want
* to call it directly if you already have an image (e.g.
* created through createImage).
*
* @param image The image
*/

public ImageLabel(Image image) {
this.image = image;
tracker = new MediaTracker(this);
currentTrackerID = lastTrackerID++;
tracker.addImage(image, currentTrackerID);
}

/** Makes sure that the Image associated with the Canvas is
* done loading before returning, since loadImage spins off
* a separate thread to do the loading. Once you get around
* to drawing the image, this will make sure it is loaded,
* waiting if not. The user does not need to call this at
* all, but if several ImageLabels are used in the same
* Container, this can cause several repeated layouts, so
* users might want to explicitly call this themselves before
* adding the ImageLabel to the Container. Another
* alternative is to start asynchronous loading by calling
* prepareImage on the ImageLabel's image (see getImage).
*
* @param doLayout Determines if the Container should be
* re-laid out after you are finished waiting. This
* should be true when called from user functions
,
* but is set to false when called from getPreferredSize
* to avoid an infinite loop. This is needed when using
* BorderLayout, which calls getPreferredSize
* before calling paint.
*/

public void waitForImage(boolean doLayout) {
if (!doneLoading) {
debug("[waitForImage] - Resizing and waiting for "
+ imageString);
try { tracker.waitForID(currentTrackerID); }
catch (InterruptedException ie) {}
catch (Exception e) {
System.out.println("Error loading "
+ imageString + ": "
+ e.getMessage());
e.printStackTrace();
}
if (tracker.isErrorID(0))
new Throwable("Error loading image "
+ imageString).printStackTrace();
doneLoading = true;
if (explicitWidth != 0)
width = explicitWidth;
else
width = image.getWidth(this) + 2*border;
if (explicitHeight != 0)
height = explicitHeight;
else
height = image.getHeight(this) + 2*border;
setSize(width, height);
debug("[waitForImage] - " + imageString + " is "
+ width + "x" + height + ".");

// If no parent, you are OK, since it will have
// been resized before being added. But if
// parent exists, you have already been added,
// and the change in size requires re-layout.
if (((parentContainer = getParent()) != null)
&& doLayout) {
setBackground(parentContainer.getBackground());
parentContainer.doLayout();
}
}
}

/** Moves the image so that it is centered at
* the specified location, as opposed to the setLocation
* method of Component which places the top left
* corner at the specified location.
*

* Note: The effects of this could be undone
* by the LayoutManager of the parent Container, if
* it is using one. So this is normally only used
* in conjunction with a null LayoutManager.
*
* @param x The X coord of center of the image
* (in parent's coordinate system)
* @param y The Y coord of center of the image
* (in parent's coordinate system)
* @see java.awt.Component#setLocation
*/

public void centerAt(int x, int y) {
debug("Placing center of " + imageString + " at ("
+ x + "," + y + ")");
setLocation(x - width/2, y - height/2);
}

/** Determines if the x and y (in the ImageLabel's
* own coordinate system)
is inside the
* ImageLabel. Put here because Netscape 2.02 has
* a bug in which it doesn't process contains() and
* locate() tests correctly.
*/

public synchronized boolean contains(int x, int y) {
return((x >= 0) && (x = 0) && (y < = height));
}

/** Draws the image. If you override this in a
* subclass, be sure to call super.paint.
*/

public void paint(Graphics g) {
if (!doneLoading)
waitForImage(true);
else {
if (explicitSize)
g.drawImage(image, border, border,
width-2*border, height-2*border,
this);
else
g.drawImage(image, border, border, this);
drawRect(g, 0, 0, width-1, height-1,
border, borderColor);
}
}

/** Used by layout managers to calculate the usual
* size allocated for the Component. Since some
* layout managers (e.g. BorderLayout) may
* call this before paint is called, you need to
* make sure that the image is done loading, which
* will force a setSize, which determines the values
* returned.
*/
public Dimension getPreferredSize() {
if (!doneLoading)
waitForImage(false);
return(super.getPreferredSize());
}

/** Used by layout managers to calculate the smallest
* size allocated for the Component. Since some
* layout managers (e.g. BorderLayout) may
* call this before paint is called, you need to
* make sure that the image is done loading, which
* will force a setSize, which determines the values
* returned.
*/
public Dimension getMinimumSize() {
if (!doneLoading)
waitForImage(false);
return(super.getMinimumSize());
}

// LayoutManagers (such as BorderLayout) might call
// setSize or setBounds with only 1 dimension of
// width/height non-zero. In such a case, you still
// want the other dimension to come from the image
// itself.

/** Resizes the ImageLabel. If you don't setSize the
* label explicitly, then what happens depends on
* the layout manager. With FlowLayout, as with
* FlowLayout for Labels, the ImageLabel takes its
* minimum size, just enclosing the image. With
* BorderLayout, as with BorderLayout for Labels,
* the ImageLabel is expanded to fill the
* section. Stretching GIF/JPG files does not always
* result in clear looking images. So just as
* with builtin Labels and Buttons, don't
* use FlowLayout if you don't want the Buttons to
* get resized. If you don't use any
* LayoutManager, then the ImageLabel will also
* just fit the image.
*

* Note that if you setSize explicitly, you must do
* it before the ImageLabel is added to the
* Container. In such a case, the explicit size
* overrides the image dimensions.
*
* @see #setBounds
*/

public void setSize(int width, int height) {
if (!doneLoading) {
explicitSize=true;
if (width > 0)
explicitWidth=width;
if (height > 0)
explicitHeight=height;
}
super.setSize(width, height);
}

/** Resizes the ImageLabel. If you don't setSize the
* label explicitly, then what happens depends on
* the layout manager. With FlowLayout, as with
* FlowLayout for Labels, the ImageLabel takes its
* minimum size, just enclosing the image. With
* BorderLayout, as with BorderLayout for Labels,
* the ImageLabel is expanded to fill the
* section. Stretching GIF/JPG files does not always
* result in clear looking images. So just as
* with builtin Labels and Buttons, don't
* use FlowLayout if you don't want the Buttons to
* get resized.
If you don't use any
* LayoutManager, then the ImageLabel will also
* just fit the image.
*

* Note that if you setSize explicitly, you must do
* it before the ImageLabel is added to the
* Container. In such a case, the explicit size
* overrides the image dimensions.
*
* @see #setSize
*/

public void setBounds(int x, int y,
int width, int height) {
if (!doneLoading) {
explicitSize=true;
if (width > 0)
explicitWidth=width;
if (height > 0)
explicitHeight=height;
}
super.setBounds(x, y, width, height);
}

// You can't just set the background color to
// the borderColor and skip drawing the border,
// since it messes up transparent gifs. You
// need the background color to be the same as
// the container.

/** Draws a rectangle with the specified OUTSIDE
* left, top, width, and height.
* Used to draw the border.
*/

protected void drawRect(Graphics g,
int left, int top,
int width, int height,
int lineThickness,
Color rectangleColor) {
g.setColor(rectangleColor);
for(int i=0; i<linethickness ; i++) {
g.drawRect(left, top, width, height);
if (i < lineThickness-1) { // Skip last iteration
left = left + 1;
top = top + 1;
width = width - 2;
height = height - 2;
}
}
}

/** Calls System.out.println if the debug variable
* is true; does nothing otherwise.
*
* @param message The String to be printed.
*/

protected void debug(String message) {
if (debug)
System.out.println(message);
}

// Creates the URL with some error checking.

private static URL makeURL(String s) {
URL u = null;
try { u = new URL(s); }
catch (MalformedURLException mue) {
System.out.println("Bad URL " + s + ": " + mue);
mue.printStackTrace();
}
return(u);
}

private static URL makeURL(URL directory,
String file) {
URL u = null;
try { u = new URL(directory, file); }
catch (MalformedURLException mue) {
System.out.println("Bad URL " +
directory.toExternalForm() +
", " + file + ": " + mue);
mue.printStackTrace();
}
return(u);
}

// Loads the image. Needs to be static since it is
// called by the constructor.

private static Image loadImage(URL url) {
return(Toolkit.getDefaultToolkit().getImage(url));
}

/** The Image associated with the ImageLabel. */

public Image getImage() {
return(image);
}

/** Gets the border width. */

public int getBorder() {
return(border);
}

/** Sets the border thickness. */

public void setBorder(int border) {
this.border = border;
}

/** Gets the border color. */

public Color getBorderColor() {
return(borderColor);
}

/** Sets the border color. */

public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
}

// You could just call size().width and size().height,
// but since we've overridden setSize to record
// this, we might as well use it.

/** Gets the width (image width plus twice border). */

public int getWidth() {
return(width);
}

/** Gets the height (image height plus 2x border). */

public int getHeight() {
return(height);
}

/** Has the ImageLabel been given an explicit size?
* This is used to decide if the image should be
* stretched or not. This will be true if you
* call setSize or setBounds on the ImageLabel before
* adding it to a Container. It will be false
* otherwise.
*/

protected boolean hasExplicitSize() {
return(explicitSize);
}

/** Returns the string representing the URL that
* will be used if none is supplied in the
* constructor.
*/

public static String getDefaultImageString() {
return(defaultImageString);
}

/** Sets the string representing the URL that
* will be used if none is supplied in the
* constructor. Note that this is static,
* so is shared by all ImageLabels. Using this
* might be convenient in testing, but "real"
* applications should avoid it.
*/

public static void setDefaultImageString(String file) {
defaultImageString = file;
}

/** Returns the string representing the URL
* of image.
*/

protected String getImageString() {
return(imageString);
}

/** Is the debugging flag set? */

public boolean isDebugging() {
return(debug);
}

/** Set the debugging flag. Verbose messages
* will be printed to System.out if this is true.
*/
public void setIsDebugging(boolean debug) {
this.debug = debug;
}
}
***********************

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

Six buttons arranged in a 2 row x 3 column grid by GridLayout #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

/././././././
GridTest.java Six buttons arranged in a 2 row x 3 column grid by GridLayout.GridLayout divides the window into equal-sized rectangles based upon the number of rows and columns specified. 
******************
import java.applet.Applet;
import java.awt.*;

/** An example of GridLayout.
 *
 /./././././.

public class GridTest extends Applet {
  public void init() {
    setLayout(new GridLayout(2,3)); // 2 rows, 3 cols
    add(new Button("Button One"));
    add(new Button("Button Two"));
    add(new Button("Button Three"));
    add(new Button("Button Four"));
    add(new Button("Button Five"));
    add(new Button("Button Six"));
  }
}

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

BorderLayout divides the window into five regions #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

# BorderTest.java Five buttons arranged by BorderLayout
BorderLayout divides the window into five regions: NORTH, SOUTH, EAST, WEST, and CENTER. 
/./././././././././././././
import java.applet.Applet;
import java.awt.*;

/** An example of BorderLayout.
 *
 &&&&&&&&&&&&&&&&&&&&&&&&&&&

public class BorderTest extends Applet {
  public void init() {
    setLayout(new BorderLayout());
    add(new Button("Button 1"), BorderLayout.NORTH);
    add(new Button("Button 2"), BorderLayout.SOUTH);
    add(new Button("Button 3"), BorderLayout.EAST);
    add(new Button("Button 4"), BorderLayout.WEST);
    add(new Button("Button 5"), BorderLayout.CENTER);
  }
}
&&&&&&&&&&&&&&&&&&&&

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

ListEvent2.java #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

# ListEvents.java Uses the following classes:

    * CloseableFrame.java
    * SelectionReporter.java
    * ActionReporter.java
/././././././././././././
import java.awt.event.*;

/././././././

public class ListEvents2 extends ListEvents {
  public static void main(String[] args) {
    new ListEvents2();
  }

  /** Extends ListEvents with the twist that
   *  typing any of the letters of "JAVA" or "java"
   *  over the language list will result in "Java"
   *  being selected
   */

  public ListEvents2() {
    super();
    // Create a KeyAdapter and attach it to languageList.
    // Since this is an inner class, it has access
    // to nonpublic data (such as the ListEvent's
    // protected showJava method).
    KeyAdapter javaChooser = new KeyAdapter() {
      public void keyPressed(KeyEvent event) {
        int key = event.getKeyChar();
        if ("JAVAjava".indexOf(key) != -1) {
          showJava();
        }
      }
    };
    languageList.addKeyListener(javaChooser);
  }
}

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

/** A class to demonstrate list selection/deselection
 *  and action events.
 *
 /*******************/.>

public class ListEvents extends CloseableFrame {
  public static void main(String[] args) {
    new ListEvents();
  }

  protected List languageList;
  private TextField selectionField, actionField;
  private String selection = "[NONE]", action;

  /** Build a Frame with list of language choices
   *  and two textfields to show the last selected
   *  and last activated items from this list.
   */
  public ListEvents() {
    super("List Events");
    setFont(new Font("Serif", Font.BOLD, 16));
    add(makeLanguagePanel(), BorderLayout.WEST);
    add(makeReportPanel(), BorderLayout.CENTER);
    pack();
    setVisible(true);
  }

  // Create Panel containing List with language choices.
  // Constructor puts this at left side of Frame.
  
  private Panel makeLanguagePanel() {
    Panel languagePanel = new Panel();
    languagePanel.setLayout(new BorderLayout());
    languagePanel.add(new Label("Choose Language"), 
                      BorderLayout.NORTH);
    languageList = new List(3);
    String[] languages =
      { "Ada", "C", "C++", "Common Lisp", "Eiffel",
        "Forth", "Fortran", "Java", "Pascal",
        "Perl", "Scheme", "Smalltalk" };
    for(int i=0; i<languages .length; i++) {
      languageList.add(languages[i]);
    }
    showJava();
    languagePanel.add("Center", languageList);
    return(languagePanel);
  }

  // Creates Panel with two labels and two textfields.
  // The first will show the last selection in List; the
  // second, the last item activated. The constructor puts
  // this Panel at the right of Frame.

  private Panel makeReportPanel() {
    Panel reportPanel = new Panel();
    reportPanel.setLayout(new GridLayout(4, 1));
    reportPanel.add(new Label("Last Selection:"));
    selectionField = new TextField();
    SelectionReporter selectionReporter =
      new SelectionReporter(selectionField);
    languageList.addItemListener(selectionReporter);
    reportPanel.add(selectionField);
    reportPanel.add(new Label("Last Action:"));
    actionField = new TextField();
    ActionReporter actionReporter = 
      new ActionReporter(actionField);
    languageList.addActionListener(actionReporter);
    reportPanel.add(actionField);
    return(reportPanel);
  }

  /** Select and show "Java". */
  
  protected void showJava() {
    languageList.select(7);
    languageList.makeVisible(7);
  }
}
*********************
SelectionReporter.java
*********************
import java.awt.*;
import java.awt.event.*;

/** Whenever an item is selected, it is displayed
 *  in the textfield that was supplied to the
 *  SelectionReporter constructor.
 *
 *******************************
public class SelectionReporter implements ItemListener {
  private TextField selectionField;

  public SelectionReporter(TextField selectionField) {
    this.selectionField = selectionField;
  }

  public void itemStateChanged(ItemEvent event) {
    if (event.getStateChange() == event.SELECTED) {
      List source = (List)event.getSource();
      selectionField.setText(source.getSelectedItem());
    } else
      selectionField.setText("");
  }
}
*********************
ActionReporter.java
*******************
import java.awt.*;
import java.awt.event.*;

/** Whenever an item is activated, it is displayed
 *  in the textfield that was supplied to the
 *  ActionReporter constructor.
 *
 *************************

public class ActionReporter implements ActionListener {
  private TextField actionField;

  public ActionReporter(TextField actionField) {
    this.actionField = actionField;
  }

  public void actionPerformed(ActionEvent event) {
    List source = (List)event.getSource();
    actionField.setText(source.getSelectedItem());
  }
}

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

Checkboxes #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

Checkboxes.java Inherits from CloseableFrame.java. 
******************
import java.awt.*;

/./././././././././

public class Checkboxes extends CloseableFrame {
  public static void main(String[] args) {
    new Checkboxes();
  }

  public Checkboxes() {
    super("Checkboxes");
    setFont(new Font("SansSerif", Font.BOLD, 18));
    setLayout(new GridLayout(0, 2));
    Checkbox box;
    for(int i=0; i<12; i++) {
      box = new Checkbox("Checkbox " + i);
      if (i%2 == 0) {
        box.setState(true);
      }
      add(box);
    }
    pack();
    setVisible(true);
  }
}

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10335
Categories:Programming Code Examples, Java/J2EE/J2ME, Advanced Swing
Tags:Java/J2EE/J2MEAdvanced Swing
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 Frame that can actually quit #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

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

/** A Frame that you can actually quit. Used as the starting 
 *  point for most Java 1.1 graphical applications.
 *

public class CloseableFrame extends Frame {
  public CloseableFrame(String title) {
    super(title);
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
  }

  /** Since we are doing something permanent, we need
   *  to call super.processWindowEvent first.
   */
  
  public void processWindowEvent(WindowEvent event) {
    super.processWindowEvent(event); // Handle listeners.
    if (event.getID() == WindowEvent.WINDOW_CLOSING) {
      // If the frame is used in an applet, use dispose().
      System.exit(0);
    }
  }
}

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

Places a Panel holding 100 buttons in a ScrollPane #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

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

/** Places a Panel holding 100 buttons in a ScrollPane that is
 *  too small to hold it.
 *
  */

public class ScrollPaneTest extends Applet {
  public void init() {
    setLayout(new BorderLayout());
    ScrollPane pane = new ScrollPane();
    Panel bigPanel = new Panel();
    bigPanel.setLayout(new GridLayout(10, 10));
    for(int i=0; i<100; i++) {
      bigPanel.add(new Button("Button " + i));
    }
    pane.add(bigPanel);
    add(pane, BorderLayout.CENTER);
  }
}

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