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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ocean Pearl
java
1 Answer(s)      2 years and 9 months ago
Posted in : JDBC


I Want my jTextfield not to accept any keys from key board but display the calculation part in it ....can you plez help me.....

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    if(jTextField2.getText().equals("")||jTextField3.getText().equals(""))
    {
        JOptionPane.showMessageDialog(null,"Please enter the fields to Calculate","Error",0);
    }
    else
    {

     String total=jTextField2.getText();
        String paid=jTextField3.getText();
     int i = Integer.parseInt(total);  
     int j = Integer.parseInt(paid);
     int k=i-j;
      String balance = new Integer(k).toString();
      jTextField4.setText(balance);
    }
}

This coding is done to calculate balance in which i want jTextfield4 not to accept any keys from key board but display the calculation part in it ....can you plez help me.....its urgent cos i want to submit my project on 25 Feb.......thank you


Advertisement
View Answers

February 22, 2012 at 11:42 AM


Use jTextField4.setEditable(false);

Here is an example:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class TextFieldEditable 
{
    public static void main(String[] args) 
    {
        JTextField jTextField1=new JTextField(20);
        final JTextField jTextField2=new JTextField(20);
        final JTextField jTextField3=new JTextField(20);
        final JTextField jTextField4=new JTextField(20);
        JButton b=new JButton("Calculate");
        JPanel p=new JPanel(new GridLayout(5,1));

        b.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evt){
    if(jTextField2.getText().equals("")||jTextField3.getText().equals(""))
    {
        JOptionPane.showMessageDialog(null,"Please enter the fields to Calculate","Error",0);
    }
    else
    {

     String total=jTextField2.getText();
        String paid=jTextField3.getText();
     int i = Integer.parseInt(total);  
     int j = Integer.parseInt(paid);
     int k=i-j;
      String balance = new Integer(k).toString();
      jTextField4.setText(balance);
    }
            }
        });
        jTextField4.setEditable(false);
        p.add(jTextField1);
        p.add(jTextField2);
        p.add(jTextField3);
        p.add(jTextField4);
        p.add(b);

        JFrame f=new JFrame();
        f.add(p);
        f.setVisible(true);
        f.pack();
    }
}


Related Tutorials/Questions & Answers:
java
java  diff bt core java and java
java
java  what is java
Advertisements
Java
Java   Whether Java is pure object oriented Language
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  how the name came for java language as "JAVA
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  write a java program using filenotfoundexception
Java
Java  how to draw class diagrams in java
java
java   difference between class and interface
java
java  why multiple inheritance is not possible in java
java
java  explain object oriented concept in java
java
java  is java purely object oriented language
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  what are JAVA applications development tools
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
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  give a simple example for inheritance in java
java
java  give a simple example for inheritance in java
Java
Java  how to do java in command prompt
java
java  Does java allows multiline comments
Advertisements
 

 

 

DMCA.com