I have a hand held scanner that can read GS1-DataMatrix codes(like the ones in the supermarket). I can scan codes in Notepad++ and I can see FNC1 characters are transmited(the GS before 2210, 1D in HEX - first image)
Now I'm trying to read the same GS1 code from Java but isn't working, the FNC1 is not seen by Java.
In Java I only see "01095011010209171719050810ABCD12342110".
I transformed the string to HEX but the result is the same, FNC1 is not in HEX either(second image).
This is the test code:
package gs1.datamatrix;
import java.awt.Font;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
public class GS1DataMatrix {
public static void main(String[] args) {
JFrame f=new JFrame();//creating instance of JFrame
Font font = new Font("Courier New", Font.PLAIN, 16);
JTextArea jtf2 = new JTextArea(); // used to hold the HEX data
jtf2.setBounds(10,250,900, 200);
jtf2.setFont( font.deriveFont( 24.0f) );
jtf2.setLineWrap(true);
f.add(jtf2);//adding button in JFrame
JTextArea jtf1 = new JTextArea(); // scan area for the DataMatrix scanner
jtf1.setBounds(10,10,900, 200);
jtf1.setFont( font.deriveFont( 24.0f) );
jtf1.getDocument().addDocumentListener(new DocumentListener() {
#Override
public void insertUpdate(DocumentEvent e) { update(e); }
#Override
public void removeUpdate(DocumentEvent e) { update(e); }
#Override
public void changedUpdate(DocumentEvent e) { update(e); }
public void update(DocumentEvent e) {
try {
Document doc = (Document)e.getDocument();
String hex = String.format("%040x", new BigInteger(1, doc.getText(0, doc.getLength()).getBytes("UTF8"))); // transform to HEX
jtf2.setText(java.util.Arrays.toString(hex.split("(?<=\\G..)"))); // split hex data by 2 characters
jtf1.selectAll();
} catch (Exception ex) {
Logger.getLogger(GS1DataMatrix.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
f.add(jtf1);//adding button in JFrame
f.setSize(1000,500);
f.setLayout(null);
f.setVisible(true);
}
}
First image: this is how Notepad++ reads FNC1(GS special character on black background):
Second image: this is Java result:
Third image: Notepad++ hex dump showing FNC1 as 1D in HEX at every scan:
Later edit
I think there has been a confusion caused by my original post: I don't parse images, the scanner has build in hardware that does this for me and I only receive a text and some special characters(FNC1's).
Some guesses after reading around a bit:
FNC1 does not have a standard representation.
This stackoverflow answer suggests that there is no way to directly encode FNC1 in the default Latin-1 encoding used for transmission.
As a workaround, most readers seem to default to the ASCII control character "Group Separator" (GS, 29, 0x1d).
You are using a swing control to display and work with the data.
Swing is primarily intended for displaying purposes, not for correct data handling purposes.
I assume what happens is that swing strips the non-printable GS character when it's set within the content of the JTextArea
Considering that you're not terribly explicit about how exactly your scanner transfers the data, but you mention "It's more like a keyboard", I assume the scanner transfers the data by pretending to be a keyboard.
You'd be selecting the input, pressing a button on the scanner and it would send data as keypresses.
Now if that is the case, you won't be able to use Swing's DocumentListener/Document to solve this.
The following Stack Overflow question basically refers to the same problem that you have (with the difference that they're using a qrcode instead of a barcode): ASCII Non printable characters in textcomponent
Now the question I linked suggests that you can use a KeyBinding or a KeyListener to fix this. Note that this will in some way break the hexadecimal representation, if you want to print the non-printable character.
UTF-8 does have a special codepoint for ASCII non-printable character representations.
The "Symbol for Group Separator" is located at \u241d. An option to handle this would then be:
jtf1.getInputMap().put(KeyStroke.getKeyStroke(29), "handleGS");
jtf1.getActionMap().put("handleGS", new AbstractAction() {
#Override
public void actionPerformed(ActionEvent e) {
jtf1.setText(jtf1.getText() + "\u241d");
}
}
That way the hexadecimal representation should become:
.. , 33, 34, e2, 90, 9d, 32, 31, 31, 30]
Note that because we remapped the GS to Unicode's "SYMBOL_FOR_GS", we get e2, 90, 9d instead of 1d.
Related
I have a simple program just need to set the character whose Unicode value larger the character data type (supplementary character) on JTextField when the button is click .Tell me i am really fed up and how i will do it .This problem have already taken my 4 days.
//importing the packages
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.*;
//My own custom class
public class UnicodeTest implements ActionListener
{
JFrame jf;
JLabel jl;
JTextField jtf;
JButton jb;
UnicodeTest()
{
jf=new JFrame();// making a frame
jf.setLayout(null); //seting the layout null of this frame container
jl=new JLabel("enter text"); //making the label
jtf=new JTextField();// making a textfied onto which a character will be shown
jb=new JButton("enter");
//setting the bounds
jl.setBounds(50,50,100,50);
jtf.setBounds(50,120,400,100);
jb.setBounds(50, 230, 100, 100);
jf.add(jl);jf.add(jtf);jf.add(jb);
jf.setSize(400,400);
jf.setVisible(true); //making frame visible
jb.addActionListener(this); // registering the listener object
}
public void actionPerformed(ActionEvent e) // event generated on the button click
{ try{
int x=66560; //to print the character of this code point
jtf.setText(""+(char)x);// i have to set the textfiled with a code point character which is supplementary in this case
}
catch(Exception ee)// caughting the exception if arrived
{ ee.printStackTrace(); // it will trace the stack frame where exception arrive
}
}
// making the main method the starting point of our program
public static void main(String[] args)
{
//creating and showing this application's GUI.
new UnicodeTest();
}
}
Since you are not giving enough information on what's wrong, I can only guess that either or both:
You are not using a font that can display the character.
You are not giving the text field the correct string representation of the text.
Setting a font that can display the character
Not all fonts can display all characters. You have to find one (or more) that can and set the Swing component to use that font. The fonts available to you are system dependent, so what works for you might not work for others. You can bundle fonts when you deploy your application to ensure it works for everyone.
To find a font on your system that can display your character, I used
Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
for (Font f : fonts) {
if (f.canDisplay(66560)) {
System.out.println(f);
textField.setFont(f.deriveFont(20f));
}
}
The output (for me) is a single font, so I allowed myself to set it in the loop:
java.awt.Font[family=Segoe UI Symbol,name=Segoe UI Symbol,style=plain,size=1]
as also noted in the comments to the question by Andrew Thompson.
Giving the text field the correct string representation
The text fields require UTF-16. Supplementary characters in UTF-16 are encoded in two code units (2 of these: \u12CD). Assuming you start from a codepoint, you can convert it to characters and then make a string from them:
int x = 66560;
char[] chars = Character.toChars(x); // chars [0] is \uD801 and chars[1] is \uDC00
textField.setText(new String(chars)); // The string is "\uD801\uDC00"
// or just
textField.setText(new String(Character.toChars(x)));
as notes by Andrew Thompson in the comments to this answer (previously I used a StringBuilder).
This question has to do with a game console I'm working on, and right now I am trying to write a Java program to simulate the console's DSP. That way, I know exactly what to do when I port it to actual hardware. But I am having trouble finding the right sound library. What I need is basically this: I have my own sound format, and I feed it into the DSP. It then decodes the data, processes post decode effects (echo, amplify, etc.), and splits the results into two sound waves for stereo output. I have everything planned out except a way to get my sound waves to my computer's sound card. So basically a more advanced version of a sine wave generator. And a little code sample to get me started would help. If I need to clarify anything, than let me know.
EDIT: Okay, so just to be clear the sound wave data will be stored in chunks in a byte array. So I need a way of playing sounds from there. And I don't want to dump the audio to a file and then play the file, that would take too long.
Here is one way to generate a sound using java.
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.sound.midi.Instrument;
import javax.sound.midi.MidiChannel;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Synthesizer;
import javax.swing.*;
public class SimpleSound extends JFrame{
Synthesizer syn;
MidiChannel[] midChannel;
Instrument[] instrument;
public SimpleSound() {
this.setLayout(new BorderLayout());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
JButton button1 = new JButton("Try");
this.add(panel);
panel.add(button1);
this.pack();
try {
syn = MidiSystem.getSynthesizer();
syn.open();
midChannel = syn.getChannels();
instrument = syn.getDefaultSoundbank().getInstruments();
syn.loadInstrument(instrument[90]);
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
makeASound();
}
});
} catch (MidiUnavailableException ex) {
ex.printStackTrace();
}
}
void makeASound() {
this.midChannel[5].noteOn(55,550);
// this.midChannel[5].noteOn(70,700);
// this.midChannel[5].noteOn(30,400);
}
public static void main(String[] args) {
new SimpleSound().setVisible(true);
}
}
You can experiment on the values in the code this.midChannel[5].noteOn(55,550);
You can find more explanations here: http://patater.com/gbaguy/javamidi.htm and here: https://docs.oracle.com/javase/tutorial/sound/MIDI-synth.html
Update:
I found another source from here http://www.automatic-pilot.com/midifile.html. It is a simple program demonstrating the creation of MIDI sound and then save it to a file. I made a modification to the last part so that the sound will be written to a byte array instead.
// write to byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
MidiSystem.write(s,1,baos);
byte[] bytes = baos.toByteArray();
But I just think that the byte array contents may not have the same format as you what you already have in mind. May I know what is the format of the sound data that is usable to you?
This page pretty much covers all of what I needed. http://www.developer.com/java/other/article.php/2226701/Java-Sound-Creating-Playing-and-Saving-Synthetic-Sounds.htm
I've written a GUI for a simulation project that I'm doing, and in the event handling code of the window, I have, for instance,
private void timestepKeyTyped(java.awt.event.KeyEvent evt) {
String text = timestep.getText();
AMEC.steptime = Integer.parseInt(text);
}
where I would like to assign any input typed into field timestep to be assigned to AMEC.steptime. I do this for all textfields.
However, my simulation doesn't run properly when passed these parameters, and upon debugging I found that only the first character gets parsed to int. For instance, if I type "31", then the value assigned to AMEC.steptime becomes 3 instead of 31.
How do I fix this?
The problem you are facing is that you are using a KeyListener. Just don't use it, use an ActionListener and when you hit ENTER actionPerformed is executed. Then you can put the same code an will run like a charm.
Use swing not awt.
Example how to use it:
import first:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JTextField;
Then in somewhere in your code
JTextField textfield = new JTextField();
textfield.addActionListener(new ActionListener(){
#Override
public void actionPerformed(ActionEvent e) {
JTextField timestep =(JTextField) e.getSource();// you could use this or just your variable.
String text = timestep.getText();
AMEC.steptime = Integer.parseInt(text);
}
});
As a side note, you would be interested in only allowing in this textfield number values. Read more in how to make it in this previous question.
Restricting JTextField input to Integers
Basically Swing JComponents are able to display numbers in fractions in this form 2 2/3. How can I paint fraction in the nicest form, for example 2⅔?
.
EDIT
.
as see I have only one way JTable inside JSpinner with one TableColumn and TableRow (that could simulated plain JtextField too), where TableRenderer could be some of JTextComponent formatted by using Html and on TableCellEdit event the TableEditor to swith to the plain JFormattedTextField,
is there another way, could it be possible with plain J(Formatted)TextField too ???
On reflection, Unicode fractions among the Latin-1 Supplement and Number Forms offer limited coverage, and fancy equations may be overkill. This example uses HTML in Swing Components.
Addendum: The approach shown lends itself fairly well to rendering mixed numbers. For editing, key bindings to + and / could be added for calculator-style input in a text component. I've used org.jscience.mathematics.number.Rational to model rational numbers, and this parser could be adapted to evaluating rational expressions.
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
/** #see https://stackoverflow.com/questions/7448216 */
public class HTMLFractions extends JPanel {
private static int N = 8;
public HTMLFractions() {
this.setLayout(new GridLayout(N, N, N, N));
this.setBorder(BorderFactory.createEmptyBorder(N, N, N, N));
for (int r = 0; r < N; r++) {
for (int c = 0; c < N; c++) {
this.add(create(r + N, r + 1, c + 2));
}
}
}
private JLabel create(int w, int n, int d) {
StringBuilder sb = new StringBuilder();
sb.append("<html><body>");
sb.append(w);
sb.append("<sup>");
sb.append(n);
sb.append("</sup>");
sb.append("<font size=+1>/<font size=-1>");
sb.append("<sub>");
sb.append(d);
sb.append("</sub>");
sb.append("</html></body>");
JLabel label = new JLabel(sb.toString(), JLabel.CENTER);
label.setBorder(BorderFactory.createLineBorder(Color.lightGray));
return label;
}
private void display() {
JFrame f = new JFrame("HTMLFractions");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
new HTMLFractions().display();
}
});
}
}
Use the Java2D API. The is an excellent book on it from O'Reilly.
1- Use the font you like.
2- Convert the Glyphs you need (e.g. "2" "/" and "3") into Java2D shapes.
3- Use the Java#d method to scales and place the shapes together
4- This part depends on the component. I think a lot of components take some kind of image instead of text. Convert your shapes into whatever fits into the components you w ant.
5- This should look really professional if you do a good job :)
Come on give me 50!!!
=============
Thanks so much for the points. Here is an example of how to do the first step. It'll show how to get an instance of enter code here Shape from a character in the font of your choice.
Once you have your Shape You can use Graphics2D to create the image you want (scale, compose, etc). All the swing components are different but all have a graphics context. Using the graphics content you can draw on any Swing Component. You can also make transparent layers and stick a transport JPanel over anything you want. If you just want to display a fraction on a label that's easy. If you had some sort of word processor in mind that's hard.
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.Shape;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
public class Utils {
public static Shape generateShapeFromText(Font font, char ch) {
return generateShapeFromText(font, String.valueOf(ch));
}
public static Shape generateShapeFromText(Font font, String string) {
BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = img.createGraphics();
try {
GlyphVector vect = font.createGlyphVector(g2.getFontRenderContext(), string);
Shape shape = vect.getOutline(0f, (float) -vect.getVisualBounds().getY());
return shape;
} finally {
g2.dispose();
}
}
}
You can use the approach based on this
http://java-sl.com/fraction_view.html
The only difference is positioning subviews for numerator and denominator.
Unicode has a set of characters that will let you produce fractions without having to do special formatting, e.g., ⁴⁄₉ or ⁵⁶⁄₁₀₀.
You could set up an array of superscript digits, and an array of subscript digits, and convert your numbers to strings of these digits, and then combine them with the fraction slash in between.
Advantages are that it's more general (you can use the code in other contexts), and the result will tend to look better than if you tried to reproduce it using HTML formatting. Of course, you need to have Unicode fonts on your system, but most systems do these days.
A possible implementation in code:
public String diagonalFraction(int numerator, int denominator) {
char numeratorDigits[] = new char[]{
'\u2070','\u00B9','\u00B2','\u00B3','\u2074',
'\u2075','\u2076','\u2077','\u2078','\u2079'};
char denominatorDigits[] = new char[]{
'\u2080','\u2081','\u2082','\u2083','\u2084',
'\u2085','\u2086','\u2087','\u2088','\u2089'};
char fractionSlash = '\u2044';
String numeratorStr = new String();
while(numerator > 0){
numeratorStr = numeratorDigits[numerator % 10] + numeratorStr;
numerator = numerator / 10;
}
String denominatorStr = new String();
while(denominator > 0){
denominatorStr = denominatorDigits[denominator % 10] + denominatorStr;
denominator = denominator / 10;
}
return numeratorStr + fractionSlash + denominatorStr;
}
You would have to find a font that prints fractions in what you're calling nicest form, then write a method to convert the character string of your fraction into the character code of the corresponding nicest form fraction.
Special fonts method:
The special fonts method might be a really good solution too.
You are going to need a good font editor.
Create ten numbers just for the top number of the fraction, a special slash or line symbol for the middle, and ten numbers just for bottom digits.
The only problem is that it's got to look good and that requires that the spacing of the top/slash/and button all close to together, actually overlapping horizontally. The good news is fonts support this, and a good font editor will. The swing text components probably don't. You need to write your own text component of find a component that already lets you fine position the fonts. This is the different between test editing/ word processing and text typography.
But I also have another idea :)
You could do fractions with a horizontal bar instead of a diagonal slash.
123
---
456
This way font need not overlap and can be laid out by the editor in the standard way. The trick is to have the above be three characters next to each other.
1 2 3
- - -
4 5 6
So that's one hundred different characters you need for all combinations.
The only problem with this (in addition to having to create 100 characters) is if you have and odd number of digits in the top and even in the bottom or vise verse it will look like this:
12
---
456
We are replacing a legacy C application originally written for MSDOS (yes, believe it or not!). This application uses a specially remapped keyboard which intercepts the DOS keyboard interrupt (remember that??!) to sometimes alter the scan codes of the keys pressed by the user so that different processing would occur. Special labels were then placed on the keys telling the users the "new" meaning of these keys.
The new Java version is required to preserve this keyboard layout which the targeted group of users is very familiar with.
An example of what we are trying to do is as follows:
You may never have thought about this, but the numeric keypad of a modern telephone is reversed from the numeric keypad of a computer keyboard. On the former 1-2-3 is on the top row and on the latter it is on the bottom row. We are required to make the keyboard's numeric keypad look like the telephone. Let's say, when the user types "7" on the numeric keypad, we want it look as though he typed a "1", when he types an "8", we want a "2", when he types a "3" we want a "9".
There is much more that we have to do to emulate the DOS application, but we can't even solve this simple case now. I have been all over Key Binding, KeyAdapters, KeyListeners, and even KeyEventDispatchers, and I cannot make this work. I am pretty sure we have to work on the lowest level we are allowed to work by Java to come as close as possible to what the legacy app does. And needless to say, we want the cleanest implementation possible, so that the application level code is not littered with inputMaps and actionMaps etc. As much as possible this needs to be handled globally. Can anyone help?
If I were doing this, I would write the Java App without worrying about the key bindings. Assume that when a component gets a keyevent for #7 its #7, don't worry about whether the 7 or 1 was really typed. The app shouldn't care about how keys are mapped on the keyboard. This should let you start developing the app immediately.
As far as overriding key bindings, this seems like where you want to look: http://download.oracle.com/javase/7/docs/api/java/awt/KeyEventDispatcher.html
It sounds like you can write your own KeyEventDispatcher to handle all the key mapping logic and it prevents mapping logic from messing up the rest of the logic in your application.
This is hacky, and I'll admit I haven't used it myself, but you could subclass KeyEvent and override the fields as needed. So yourSubclass.VK_NUMPAD1 is the integer value of KeyEvent.VK_NUMPAD7, yourSubclass.VK_NUMPAD2 is the integer value of KeyEvent.VK_NUMPAD8, etcetera. Then use your subclass everywhere KeyEvent is normally used.
I also agree that the KeyEventDispatcher should work. But if this a version/platform issue, then maybe you can use a custom Event Queue. See Global Event Dispatching
My stack overfloweth!
The answer was here:
http://download.oracle.com/javase/6/docs/api/java/awt/event/KeyEvent.html
which says:
For key pressed and key released
events, the getKeyCode method returns
the event's keyCode. For key typed
events, the getKeyCode method always
returns VK_UNDEFINED.
My original attempt thought it could get a keyCode on KEY_TYPED. It could not, and it was the KEY_TYPED event that was clobbering the mapping done in KEY_PRESSED.
Here is a working implementation:
import static java.awt.event.KeyEvent.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class KeyboardDispatcherDemo extends JFrame {
/**
* This class shows how to map numeric keypad keys.
* It performs two conversions:
* 1. lower-to-uppercase
* 2. if numeric keypad 7-9 is typed, 1-3 appears and vice versa.
*
* This is modified from the code at
* http://www.exampledepot.com/egs/java.awt/DispatchKey.html#comment-51807
* which demoes the lower-to-upper conversion.
*
* It doesn't yet handle modified numeric keypad keys.
*
*/
public KeyboardDispatcherDemo() {
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(
new KeyEventDispatcher() {
private char lastMappedKey;
private final Map<Integer, Character> keyMap =
new HashMap<Integer, Character>() {
{
put(VK_NUMPAD1, '7');
put(VK_NUMPAD2, '8');
put(VK_NUMPAD3, '9');
put(VK_NUMPAD7, '1');
put(VK_NUMPAD8, '2');
put(VK_NUMPAD9, '3');
}};
public boolean dispatchKeyEvent(KeyEvent e) {
System.out.println(String.format("INPUT: %s", e.toString()));
boolean dispatch = false;
switch (e.getID()) {
case KeyEvent.KEY_PRESSED:
dispatch = dispatchKeyPressed(e);
break;
case KeyEvent.KEY_TYPED:
dispatch = dispatchKeyTyped(e);
break;
case KeyEvent.KEY_RELEASED:
dispatch = dispatchKeyReleased(e);
break;
default:
throw new IllegalArgumentException();
}
System.out.println(String.format("OUTPUT: %s", e.toString()));
System.out.println();
return dispatch;
}
private boolean dispatchKeyPressed(KeyEvent e) {
char k = e.getKeyChar();
if (k != CHAR_UNDEFINED) {
if (Character.isLetter(k)) {
e.setKeyChar(Character.toUpperCase(e.getKeyChar()));
} else if (e.getModifiers() == 0){
Character mapping = keyMap.get(e.getKeyCode());
if (mapping != null) {
e.setKeyChar(mapping);
}
}
// save the last mapping so that KEY_TYPED can use it.
// note we don't do this for modifier keys.
this.lastMappedKey = e.getKeyChar();
}
return false;
}
// KEY_TYPED events don't have keyCodes so we rely on the
// lastMappedKey that was saved on KeyPressed.
private boolean dispatchKeyTyped(KeyEvent e) {
char k = e.getKeyChar();
if (k != CHAR_UNDEFINED) {
e.setKeyChar(lastMappedKey);
}
return false;
}
private boolean dispatchKeyReleased(KeyEvent e) {
char k = e.getKeyChar();
if (k != CHAR_UNDEFINED) {
e.setKeyChar(lastMappedKey);
this.lastMappedKey=CHAR_UNDEFINED;
}
return false;
}
});
setTitle("KeyboardDispatcherDemo");
JPanel panel = new JPanel();
panel.setBackground(new Color(204, 153, 255));
panel.setLayout(new BorderLayout());
getContentPane().add(panel, BorderLayout.CENTER);
JTextArea staticText = new JTextArea();
staticText.setText("This demonstrates how to map numeric keypad keys. It uppercases all letters and converts Numeric Keypad 1-3 to 7-9 and vice versa. Try it.");
staticText.setLineWrap(true);
staticText.setWrapStyleWord(true);
panel.add(staticText, BorderLayout.NORTH);
staticText.setFocusable(false);
JTextField textField = new JTextField();
textField.setText("");
textField.setHorizontalAlignment(SwingConstants.LEFT);
panel.add(textField, BorderLayout.SOUTH);
textField.setColumns(10);
textField.setFocusable(true);
setSize(getPreferredSize());
setVisible(true);
}
/**
* #param args
*/
public static void main(String[] args) {
new KeyboardDispatcherDemo();
}
#Override
public Dimension getPreferredSize() {
// TODO Auto-generated method stub
return new Dimension(400,300);
}
}
Thanks to all who nudged me toward the answer.
which brings me to my next question ... stay tuned.