Keybourd in java
I have wrote a GUI java program which acts as a keyboard, in the program I have used a JTextfield and a collection of Buttons in my program. when the user click to any of the Button the result appears in the Textfield, I want to modify my Keyboard program to make it possible of displaying the result of the pressed buttons in any other input page for example in notepad or microsoft words. I mean How can I use my my keyboard program for writing on notepad?
one more thing I want to ask about is adding the backspace button, which instruction I need to write for the backspace button?
View Answers
April 27, 2011 at 5:43 PM
To create a backspace key function, try this:
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.border.*;
public class SpaceKey extends JPanel implements ActionListener
{
static final String st = "ABCDE";
JButton buttonList[];
String buffer = "";
JTextField text;
JButton backspace;
public void key() {
text = new JTextField(20);
text.setActionCommand(""+ buffer);
add(text);
int n = st.length();
buttonList = new JButton[n];
for (int i = 0; i < n; i++) {
buttonList[i] = new JButton( "" + st.charAt(i) );
add(buttonList[i]);
buttonList[i].addActionListener(this);
}
backspace = new JButton("BackSpace Key");
add(backspace);
backspace.addActionListener(this);
}
public void actionPerformed( ActionEvent e) {
int n = st.length();
if (e.getSource() == backspace) {
buffer = buffer.substring(0,buffer.length()-1);
text.setText("" + buffer);
}
else{
for (int i = 0; i < n; i++){
if (e.getSource() == buttonList[i]){
buffer += st.toLowerCase().charAt(i);
text.setText(""+ buffer);
break;
}
}
}
}
public SpaceKey(){
JPanel pane = new JPanel();
add(pane);
}
public static void main(String s[])
{
JFrame frame = new JFrame();
SpaceKey keys= new SpaceKey();
frame.getContentPane().add(keys,"Center");
keys.key();
frame.setSize(500,100);
frame.setVisible(true);
}
}
April 27, 2011 at 7:53 PM
Related Tutorials/Questions & Answers:
Keybourd in javaKeybourd in java I have wrote a GUI
java program which acts as a keyboard, in the program I have used a JTextfield and a collection of Buttons in my program. when the user click to any of the Button the result appears
Keybourd in javaKeybourd in java I have wrote a GUI
java program which acts as a keyboard, in the program I have used a JTextfield and a collection of Buttons in my program. when the user click to any of the Button the result appears
Advertisements
about ALT ,CTRL and SHIFTabout ALT ,CTRL and SHIFT hi all
dear freind : how can create ALT ,SHIFT and CTRL button that work in run time ? in my
keybourd program i wont crete
keybourd like in windows,, please help me please
about ALT ,CTRL and SHIFTabout ALT ,CTRL and SHIFT hi all
dear freind : how can create ALT ,SHIFT and CTRL button that work in run time ? in my
keybourd program i wont crete
keybourd like in windows,, please help me please
javajava diff bt core
java and
java JAVAJAVA how the name came for
java language as "
JAVA java java why iterator in
java if we for loop
Java Java Whether
Java is pure object oriented Language
javajava explain technologies are used in
java now days and structure
java javajava different between
java & core
java javajava is
java open source
javajava what is
java reflection
java java in
java does not pointers concept but what is nullpointers in
java?
nullpointer is a runtime Exception
javawhat is the size of array in
java ? what is the size of array in
java ?
what is the mean of finalize in
java javajava give a simple example for inheritance in
java javajava give a simple example for inheritance in
java javajava why to set classpath in
java javajava why to set classpath in
java javajava why to set classpath in
java javajava why to set classpath in
java java java What is ?static? keyword
javajava RARP implementation using
java socket
javajava sample code for RARP using
java javajava Does
java allows multiline comments
JavaJava how to do
java in command prompt
javajava Write a
java code to print "ABABBABCABABBA
javajava write a program in
java to acess the email
javajava send me
java interview questions
javajava how use
java method
javajava what are
JAVA applications development tools
JavaJava Whether
Java is Programming Language or it is SOftware
javajava is
java purely object oriented language
javajava why multiple inheritance is not possible in
java javajava explain object oriented concept in
java java java difference between class and interface
JavaJava how to draw class diagrams in
java javajava write a
java program using filenotfoundexception
java java How to set
java Policy for applet using jdk 6
javajava pattern code for a given words
java pattern code for a given words pattern
javajava dear,
i want a field for date picker using
java/
java script
javajava create
java program for delete and update the details,without using database, just a normal
java program
javajava why methods in
java raise exceptions
Have a look at the following link:
Java Exceptions
javajava code to search the nodes how to write the
java code to search the nodes using routers
javajava online telephone directory i need coding for online telephone directory..by using
java....pls help me
javajava how to edit text document by using
java
then how to edit starting and ending of text document by using
java javajava different between
java & core
java
print("code sample
javajava different between
java & core
java
print("code sample
java java how can use sleep in
java
which book learn of
java language