Friday 14 June 2013

reverse program in java swing


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class myframe1 extends JFrame implements ActionListener
{
    JButton b1,b2;
    JTextField tx,tx1;
    JLabel l1,l2,l3;
    Container c;
    myframe1()
    {
        c=getContentPane();
        c.setBackground(Color.pink);
        c.setLayout(null);

        l1=new JLabel("Enter any number");
        l1.setBounds(50,50,100,50);
        l1.setForeground(Color.red);
        c.add(l1);

        l3=new JLabel("Application for Reverse");
        l3.setBounds(125,0,225,50);
        l3.setForeground(Color.blue);
        c.add(l3);

        tx=new JTextField();
        tx.setBounds(200,50,150,30);
        c.add(tx);

        l2=new JLabel("Answer");
        l2.setBounds(50,150,50,50);
        l2.setForeground(Color.red);
        c.add(l2);

        tx1=new JTextField();
        tx1.setBounds(200,150,150,30);
        c.add(tx1);

        b1=new JButton("Check");
        b1.addActionListener(this);
        b1.setBounds(100,200,90,50);
        c.add(b1);

        b2=new JButton("Cancel");
        b2.addActionListener(this);
        b2.setBounds(250,200,90,50);
        c.add(b2);

    }
    public void actionPerformed(ActionEvent ae)
    {
        String str=ae.getActionCommand();
        int no,rev=0,rem;
        if(str=="Check")
        {
            no=Integer.parseInt(tx.getText());
            while(no!=0)
            {
                rem=no%10;
                rev=rev*10+rem;
                no=no/10;
            }
            tx1.setText(String.valueOf(rev));
        }
        if(str=="Cancel")
        {
            System.exit(0);
        }
    }

}
class reverse
{
    public static void main(String args[])
    {
        myframe1 f=new myframe1();

        f.setTitle("Reverse");
        f.setSize(400,400);
        f.setVisible(true);
    }
}

1 comment:

Unknown said...

its not running .it gives error Error: Main method not found in class myframe1, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application