Keybourd in java

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









Related Tutorials/Questions & Answers:
Keybourd in java
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
Keybourd in java
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
Advertisements
about ALT ,CTRL and SHIFT
about 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 SHIFT
about 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
java
java  diff bt core java and java
java
java  what is java
JAVA
JAVA  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
java
java  explain technologies are used in java now days and structure java
java
java  different between java & core java
java
java  is java open source
java
java  what is java reflection
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java  give a simple example for inheritance in java
java
java  give a simple example for inheritance in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java   What is ?static? keyword
java
java  RARP implementation using java socket
java
java  sample code for RARP using java
java
java  Does java allows multiline comments
Java
Java  how to do java in command prompt
java
java  Write a java code to print "ABABBABCABABBA
java
java  write a program in java to acess the email
java
java  send me java interview questions
java
java  how use java method
java
java  what are JAVA applications development tools
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  is java purely object oriented language
java
java  why multiple inheritance is not possible in java
java
java  explain object oriented concept in java
java
java   difference between class and interface
Java
Java  how to draw class diagrams in java
java
java  write a java program using filenotfoundexception
java
java  hi im new to java plz suggest me how to master java[email protected]
java
java   How to set java Policy for applet using jdk 6
java
java pattern code for a given words  java pattern code for a given words pattern
java
java  dear, i want a field for date picker using java/java script
java
java  create java program for delete and update the details,without using database, just a normal java program
java
java  why methods in java raise exceptions   Have a look at the following link: Java Exceptions
java
java code to search the nodes  how to write the java code to search the nodes using routers
java
java online telephone directory  i need coding for online telephone directory..by using java....pls help me
java
java  how to edit text document by using java then how to edit starting and ending of text document by using java
java
java  different between java & core java print("code sample
java
java  different between java & core java print("code sample
java
java  how can use sleep in java   which book learn of java language

Ads