Lists.java #Programming Code Examples #Java/J2EE/J2ME #AWT Components

Lists.java Inherits from CloseableFrame.java. 
/./././././././././
import java.awt.*;

/*****************/

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

  public Lists() {
    super("Lists");
    setLayout(new FlowLayout());
    setBackground(Color.lightGray);
    setFont(new Font("SansSerif", Font.BOLD, 18));
    List list1 = new List(3, false);
    list1.add("Vanilla");
    list1.add("Chocolate");
    list1.add("Strawberry");
    add(list1);
    List list2 = new List(3, true);
    list2.add("Colored Sprinkles");
    list2.add("Cashews");
    list2.add("Kiwi");
    add(list2);
    pack();
    setVisible(true);
  }
}

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

ChoiceTest2 #Programming Code Examples #Java/J2EE/J2ME #AWT Components

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

/***********************/

public class ChoiceTest2 extends Applet 
                         implements ItemListener {
  private Choice choice;

  public void init() {
    setFont(new Font("SansSerif", Font.BOLD, 36));
    choice = new Choice();
    choice.addItem("Choice 1");
    choice.addItem("Choice 2");
    choice.addItem("Choice 3");
    choice.addItemListener(this);
    add(choice);
  }

  public void itemStateChanged(ItemEvent event) {
    Choice choice = (Choice)event.getSource();
    String selection = choice.getSelectedItem();
    if (selection.equals("Choice 1")) {
      doChoice1Action();
    } else if (selection.equals("Choice 2")) {
      doChoice2Action();
    } else if (selection.equals("Choice 3")) {
      doChoice3Action();
    }
  }

  private void doChoice1Action() {
    System.out.println("Choice 1 Action");
  }

  private void doChoice2Action() {
    System.out.println("Choice 2 Action");
  }

  private void doChoice3Action() {
    System.out.println("Choice 3 Action");
  }
}

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

ChoiceTest #Programming Code Examples #Java/J2EE/J2ME #AWT Components

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

/*******/

public class ChoiceTest extends Applet {
  private Choice choice;

  public void init() {
    setFont(new Font("SansSerif", Font.BOLD, 36));
    choice = new Choice();
    choice.addItem("Choice 1");
    choice.addItem("Choice 2");
    choice.addItem("Choice 3");
    add(choice);
  }
}

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

CheckboxGroups #Programming Code Examples #Java/J2EE/J2ME #AWT Components

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

////////////////////
 
public class CheckboxGroups extends Applet {
  public void init() {
    setLayout(new GridLayout(4, 2));
    setBackground(Color.lightGray);
    setFont(new Font("Serif", Font.BOLD, 16));
    add(new Label("Flavor", Label.CENTER));
    add(new Label("Toppings", Label.CENTER));
    CheckboxGroup flavorGroup = new CheckboxGroup();
    add(new Checkbox("Vanilla", flavorGroup, true));
    add(new Checkbox("Colored Sprinkles"));
    add(new Checkbox("Chocolate", flavorGroup, false));
    add(new Checkbox("Cashews"));
    add(new Checkbox("Strawberry", flavorGroup, false));
    add(new Checkbox("Kiwi"));
  }
}

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

ButtonExample.java Uses the following #Programming Code Examples #Java/J2EE/J2ME #AWT Components

/./././././././././
# ButtonExample.java Uses the following classes:

    * CloseableFrame.java
    * FgReporter.java
    * BgReporter.java
    * SizeReporter.java
******************
ButtonExample.java 
******************
import java.awt.*;
import java.awt.event.*;

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

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

  public ButtonExample() {
    super("Using ActionListeners");
    setLayout(new FlowLayout());
    Button b1 = new Button("Button 1");
    Button b2 = new Button("Button 2");
    Button b3 = new Button("Button 3");
    b1.setBackground(Color.lightGray);
    b2.setBackground(Color.gray);
    b3.setBackground(Color.darkGray);
    FgReporter fgReporter = new FgReporter();
    BgReporter bgReporter = new BgReporter();
    SizeReporter sizeReporter = new SizeReporter();
    b1.addActionListener(fgReporter);
    b2.addActionListener(fgReporter);
    b2.addActionListener(bgReporter);
    b3.addActionListener(fgReporter);
    b3.addActionListener(bgReporter);
    b3.addActionListener(sizeReporter);
    add(b1);
    add(b2);
    add(b3);
    setSize(350, 100);
    setVisible(true);
  }
}
/./././././././././
FgReporter.java
***************
import java.awt.event.*;
import java.awt.*;

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

public class FgReporter implements ActionListener {
  public void actionPerformed(ActionEvent event) {
    Component c = (Component)event.getSource();
    System.out.println("Foreground: " + c.getForeground());
  }
}
****************
BgReporter.java
****************
/././././././././
import java.awt.event.*;
import java.awt.*;

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

public class BgReporter implements ActionListener {
  public void actionPerformed(ActionEvent event) {
    Component c = (Component)event.getSource();
    System.out.println("Background: " + c.getBackground());
  }
}
/././././././././././
SizeReporter.java
***********************

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

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

public class SizeReporter implements ActionListener {
  public void actionPerformed(ActionEvent event) {
    Component c = (Component)event.getSource();
    Dimension d = c.getSize();
    System.out.println("Size: " + d.width + "x" + d.height);
  }
}
********************

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

Batton’s java #Programming Code Examples #Java/J2EE/J2ME #AWT Components

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

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

public class Buttons extends Applet {
  private Button button1, button2, button3;
  
  public void init() {
    button1 = new Button("Button One");
    button2 = new Button("Button Two");
    button3 = new Button("Button Three");
    add(button1);
    add(button2);
    add(button3);
  }
}
/././././././././.

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

Handling Events #Programming Code Examples #Java/J2EE/J2ME #AWT Components

***********************************    
* ActionExample1.java Inherits from CloseableFrame.java and uses SetSizeButton.java.
    * ActionExample2.java Inherits from CloseableFrame.java.
    **********************************************************
ActionExample1.java
*******************
import java.awt.*;

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

  public ActionExample1() {
    super("Handling Events in Component");
    setLayout(new FlowLayout());
    setFont(new Font("Serif", Font.BOLD, 18));
    add(new SetSizeButton(300, 200));
    add(new SetSizeButton(400, 300));
    add(new SetSizeButton(500, 400));
    setSize(400, 300);
    setVisible(true);
  }
}
********************
CloseableFrame.java 
********************
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);
    }
  }
}
**********************
SetSizeButton.java
**********************
import java.awt.*;
import java.awt.event.*;

///////////////////////
public class SetSizeButton extends Button 
                           implements ActionListener {
  private int width, height;

  public SetSizeButton(int width, int height) {
    super("Resize to " + width + "x" + height);
    this.width = width;
    this.height = height;
    addActionListener(this);
  }

  public void actionPerformed(ActionEvent event) {
    getParent().setSize(width, height);
    getParent().invalidate();
    getParent().validate();
  }
}
***********************
ActionExample2.java
***********************
import java.awt.*;
import java.awt.event.*;

/***********/
public class ActionExample2 extends CloseableFrame
                            implements ActionListener {
  public static void main(String[] args) {
    new ActionExample2();
  }

  private Button button1, button2, button3;

  public ActionExample2() {
    super("Handling Events in Other Object");
    setLayout(new FlowLayout());
    setFont(new Font("Serif", Font.BOLD, 18));
    button1 = new Button("Resize to 300x200");
    button2 = new Button("Resize to 400x300");
    button3 = new Button("Resize to 500x400");
    button1.addActionListener(this);
    button2.addActionListener(this);
    button3.addActionListener(this);
    add(button1);
    add(button2);
    add(button3);
    setSize(400, 300);
    setVisible(true);
  }

  public void actionPerformed(ActionEvent event) {
    if (event.getSource() == button1) {
      updateLayout(300, 200);
    } else if (event.getSource() == button2) {
      updateLayout(400, 300);
    } else if (event.getSource() == button3) {
      updateLayout(500, 400);
    }
  }
  
  private void updateLayout(int width, int height) {
    setSize(width, height);
    invalidate();
    validate();
  }
}
****************/>
CloseableFrame.java.
****************/>< 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=10332
Categories:Programming Code Examples, Java/J2EE/J2ME, AWT Components
Tags:Java/J2EE/J2MEAWT Components
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

Uses a FileDialog to choose the file to display #Programming Code Examples #Java/J2EE/J2ME #AWT Components

DisplayFile.java 
****************
import java.awt.*;
import java.awt.event.*;
import java.io.*;

/** Uses a FileDialog to choose the file to display. 
 ***************
 
public class DisplayFile extends CloseableFrame 
                         implements ActionListener {
                                
  public static void main(String[] args) {
    new DisplayFile();
  }

  private Button loadButton;
  private TextArea fileArea;
  private FileDialog loader;

  public DisplayFile() {
    super("Using FileDialog");
    loadButton = new Button("Display File");
    loadButton.addActionListener(this);
    Panel buttonPanel = new Panel();
    buttonPanel.add(loadButton);
    add(buttonPanel, BorderLayout.SOUTH);
    fileArea = new TextArea();
    add("Center", fileArea);
    loader = new FileDialog(this, "Browse", FileDialog.LOAD);
    // Default file extension: .java.
    loader.setFile("*.java");
    setSize(350, 450);
    setVisible(true);
  }

  /** When the button is clicked, a file dialog is opened. When 
   * the file dialog is closed, load the file it referenced.
   */
  
  public void actionPerformed(ActionEvent event) {
      loader.show();
      displayFile(loader.getFile());
  }

  public void displayFile(String filename) {
    try {
      File file = new File(filename);
      FileInputStream in = new FileInputStream(file);
      int fileLength = (int)file.length();
      byte[] fileContents = new byte[fileLength];
      in.read(fileContents);
      String fileContentsString = new String(fileContents);
      fileArea.setText(fileContentsString);
    } catch(IOException ioe) {
      fileArea.setText("IOError: " + ioe);
    }
  }
}
*************
CloseableFrame.java. 
*************
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=10331
Categories:Programming Code Examples, Java/J2EE/J2ME, AWT Components
Tags:Java/J2EE/J2MEAWT Components
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 uses the Confirm dialog to verify quit #Programming Code Examples #Java/J2EE/J2ME #AWT Components

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

/** A Frame that uses the Confirm dialog to verify that
 *  users really want to quit.
 *
 
public class ConfirmTest extends Frame {
  public static void main(String[] args) {
    new ConfirmTest();
  }

  public ConfirmTest() {
    super("Confirming QUIT");
    setSize(200, 200);
    addWindowListener(new ConfirmListener());
    setVisible(true);
  }

  public ConfirmTest(String title) {
    super(title);
  }

  private class ConfirmListener extends WindowAdapter {
    public void windowClosing(WindowEvent event) {
      new Confirm(ConfirmTest.this);
    }
  }
}
****************
Confirm.java
****************
dialog box with two buttons: Yes and No
****************
import java.awt.*;
import java.awt.event.*;

/** A modal dialog box with two buttons: Yes and No.
 *  Clicking Yes exits Java. Clicking No exits the
 *  dialog. Used for confirmed quits from frames.
 ********************

class Confirm extends Dialog implements ActionListener {
  private Button yes, no;

  public Confirm(Frame parent) {
    super(parent, "Confirmation", true);
    setLayout(new FlowLayout());
    add(new Label("Really quit?"));
    yes = new Button("Yes");
    yes.addActionListener(this);
    no  = new Button("No");
    no.addActionListener(this);
    add(yes);
    add(no);
    pack();
    setVisible(true);
  }

  public void actionPerformed(ActionEvent event) {
    if (event.getSource() == yes) {
      System.exit(0);
    } else {
      dispose();
    }
  }
}
***************

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10330
Categories:Programming Code Examples, Java/J2EE/J2ME, AWT Components
Tags:Java/J2EE/J2MEAWT Components
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 lets you draw circles with mouse clicks #Programming Code Examples #Java/J2EE/J2ME #AWT Components

SavedFrame.java
****************
A Frame that lets you draw circles with mouse clicks 
//**************
import java.awt.*;
import java.awt.event.*;
import java.io.*;

/** A Frame that lets you draw circles with mouse clicks 
 *  and then save the Frame and all circles to disk.
 *
public class SavedFrame extends CloseableFrame
                        implements ActionListener {
  
  /** If a saved version exists, use it. Otherwise create a 
   *  new one.
   */
                          
  public static void main(String[] args) {
    SavedFrame frame;
    File serializeFile = new File(serializeFilename);
    if (serializeFile.exists()) {
      try {
        FileInputStream fileIn = 
          new FileInputStream(serializeFile);
        ObjectInputStream in = new ObjectInputStream(fileIn);
        frame = (SavedFrame)in.readObject();
        frame.setVisible(true);
      } catch(IOException ioe) {
        System.out.println("Error reading file: " + ioe);
      } catch(ClassNotFoundException cnfe) {
        System.out.println("No such class: " + cnfe);
      }
    } else {
      frame = new SavedFrame();
    }
  }

  private static String serializeFilename ="SavedFrame.ser";
  private CirclePanel circlePanel;
  private Button clearButton, saveButton;

  /** Build a frame with CirclePanel and buttons. */
                          
  public SavedFrame() {
    super("SavedFrame");
    setBackground(Color.white);
    setFont(new Font("Serif", Font.BOLD, 18));
    circlePanel = new CirclePanel();
    add("Center", circlePanel);
    Panel buttonPanel = new Panel();
    buttonPanel.setBackground(Color.lightGray);
    clearButton = new Button("Clear");
    saveButton = new Button("Save");
    buttonPanel.add(clearButton);
    buttonPanel.add(saveButton);
    add(buttonPanel, BorderLayout.SOUTH);
    clearButton.addActionListener(this);
    saveButton.addActionListener(this);
    setSize(300, 300);
    setVisible(true);
  }

  /** If "Clear" clicked, delete all existing circles. If "Save"
   *  clicked, save existing frame configuration (size, 
   *  location, circles, etc.) to disk.
   */
                          
  public void actionPerformed(ActionEvent event) {
    if (event.getSource() == clearButton) {
      circlePanel.removeAll();
      circlePanel.repaint();
    } else if (event.getSource() == saveButton) {
      try {
        FileOutputStream fileOut =
          new FileOutputStream("SavedFrame.ser");
        ObjectOutputStream out = 
          new ObjectOutputStream(fileOut);
        out.writeObject(this);
        out.flush();
        out.close();
      } catch(IOException ioe) {
        System.out.println("Error saving frame: " + ioe);
      }
    }
  }
}
****************

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