Category: FromSitesTree.com

Explicit placement of five buttons with the layout manager turned off #Programming Code Examples #Java/J2EE/J2ME #Layout Managers

NullTest.java Explicit placement of five buttons with the layout manager turned off (set to null) ########################## import java.applet.Applet; import java.awt.*; /** Layout managers are intended to help you, but there * is no law saying you have to use them. * Set the layout to null to turn them off. * ******************* public class NullTest …

Continue reading

Layout of complicated GUI by taking advantage of nested containers #Programming Code Examples #Java/J2EE/J2ME #Layout Managers

################# NestedLayout.java Layout of complicated GUI by taking advantage of nested containers. Uses WindowUtilities.java and ExitListener.java. ################## import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; /** An example demonstrating the use of nested containers * to lay out the components. See GridBagTest.java for * implementation by a single layout manager, GridBagLayout. …

Continue reading

java Nested container where the top-level panels are positioned by hand #Programming Code Examples #Java/J2EE/J2ME #Layout Managers

###################### ButtonCol.java Nested container where the top-level panels are positioned by hand ###################### import java.applet.Applet; import java.awt.*; /** An example of a layout performed manually. The top-level * panels are positioned by hand, after you determine the size * of the applet. Since applets can’t be resized in most * browsers, setting the size once …

Continue reading

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); …

Continue reading

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) …

Continue reading

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 EventsTags:Java/J2EE/J2MEMouse …

Continue reading

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(); …

Continue reading

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); } …

Continue reading

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 …

Continue reading

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: …

Continue reading