Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Keybourd in java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


didar sham
Keybourd in java
1 Answer(s)      3 years and 5 months ago
Posted in : Java Beginners


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?


Advertisement
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
java
java  diff bt core java and java
java
java  what is java
Java
Java   Whether Java is pure object oriented Language
JAVA
JAVA  how the name came for java language as "JAVA
java
java  different between java & core java
java
java  explain technologies are used in java now days and structure java
java
java   why iterator in java if we for loop
java
java  what is java reflection
java
java  is java open source
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   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
Java
Java  how to draw class diagrams in java
java
java  explain object oriented concept in java
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  what are JAVA applications development tools
java
java  why to set classpath in java
java
java  give a simple example for inheritance in java
java
java  Does java allows multiline comments
java
java   What is ?static? keyword
java
java  write a java program using filenotfoundexception
java
java   difference between class and interface
java
java  why multiple inheritance is not possible in java
java
java  is java purely object oriented language
java
java  how use java method
java
java  send me java interview questions
java
java  write a program in java to acess the email
java
java  Write a java code to print "ABABBABCABABBA
java
java  why to set classpath in java
java
java  why to set classpath in java
 

 

 

DMCA.com