JavaSwing

Ads

 
 
 

Share on Google+Share on Google+

Sahaya Nijo J
JavaSwing
1 Answer(s)      5 years and 6 months ago
Posted in : Java Beginners

I create 4 text box and 3 buttons.button1 is using increment option and button2 using decrement option button3 using reset option.when i click the button1 the value will be increase and the result is shown into the textbox same as button2 and button3.

Ads
View Answers

November 14, 2011 at 12:36 PM


import javax.swing.*;
import java.awt.event.*;
class SwingExample 
{
    public static void main(String[] args) 
    {
        JFrame f=new JFrame();
        final JTextField text1=new JTextField(20);
        JTextField text2=new JTextField(20);
        JTextField text3=new JTextField(20);
        JTextField text4=new JTextField(20);

        f.setLayout(null);
        JButton b1=new JButton("Increment");
        JButton b2=new JButton("Decrement");
        JButton b3=new JButton("Reset");

        text1.setBounds(10,10,150,20);
        text2.setBounds(10,40,150,20);
        text3.setBounds(10,70,150,20);
        text4.setBounds(10,100,150,20);

        b1.setBounds(10,130,100,20);
        b2.setBounds(120,130,100,20);
        b3.setBounds(240,130,100,20);

        f.add(text1);
        f.add(text2);
        f.add(text3);
        f.add(text4);
        f.add(b1);
        f.add(b2);
        f.add(b3);

        b1.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
            int num=Integer.parseInt(text1.getText());
            num=num+1;
            text1.setText(Integer.toString(num));
            }
        });
        b2.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
            int num=Integer.parseInt(text1.getText());
            num=num-1;
            text1.setText(Integer.toString(num));
            }
        });
        b3.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
            text1.setText(" ");
            }
        });
        f.setVisible(true);
        f.setSize(350,200);
            }
        }

Ads









Related Tutorials/Questions & Answers:
Advertisements
Java-mysql coding - Java Beginners
Java-mysql coding  Dear Sir, Suppose I have Employee master file in Mysql table format & I want to update that file thru JavaSwing Input format using JLable, JButton, J TextBox & SubmitButton. Can you tell me, If new
Tutorials   
Java Spring Hibernate Struts Training ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java

Ads

 
Advertisement null

Ads