Create Textbox and Radio Buttons in Java

Create Textbox and Radio Buttons in Java. Deal with Textbox and Radio Buttons in Java and Advance Java.. Find Complete Program to deal with java textboxes and Radio Buttons.

Here you will get how to deal with java textboxes and their association with Radio Buttons.

A complete java program in which you learn how to create Java Super frame window, and then how to declare different variables in java. After this you would also learn that how to create java textbox , How to use addWindowListener.

Working of this program is given below
This program will get values in textbox 1 and Textbox 2. After entering the values in textbox 1 and 2, you will click on any of the Radio Button given below heaving associated with their functionality (Addition, Subtraction, Multiplication and Division).

Then their is also a textbox at the end that will show result according to your selection in Radio Button.

You would also learn how you can import different java libraries in java. How to Create class MyFrame. How to declare different variables, checkbox groups, Textfields and labels in java.

import java.awt.*;
import java.awt.event.*;
class MyFrame extends Frame implements ItemListener
{
 Checkbox add,sub,mul,div;
 CheckboxGroup grp;
 TextField t1,t2,t3;
 Label l1,l2,l3,l4;

 MyFrame()
{
super(“Dealing with Checkbox and Textboxes”);
 setLayout(null);
 setBounds(200,100,500,400);
 setBackground(new Color(255,25,125));

addWindowListener(new WindowAdapter() is a piece of coding that is used to add window closing event. It mean that when you press close icon your open window of java programe should be close.

 addWindowListener(new WindowAdapter()
                   {
                     public void windowClosing(WindowEvent we)
                     {
                       System.exit(0);
                      }
                   });

In this section you will learn that how to declare a checkbox group? How to Assign them different name according to their uses? How to set checkboxes bounds? How to set Font Style and Font weight and in the end how to add item listener for checkbox,

 grp=new CheckboxGroup();

add=new Checkbox(“Add”,grp,false);
add.setBounds(40,120,75,25);
   add.setFont(new Font(“Monotype Corsiva”,Font.BOLD,20));
   add.addItemListener(this);

   sub=new Checkbox(“Subtract”,grp,false);
   sub.setBounds(115,120,100,25);
   sub.setFont(new Font(“Monotype Corsiva”,Font.BOLD,20));
   sub.addItemListener(this);

   mul=new Checkbox(“Multiply”,grp,false);
   mul.setBounds(220,120,90,25);
   mul.setFont(new Font(“Monotype Corsiva”,Font.BOLD,20));
   mul.addItemListener(this);

   div=new Checkbox(“Divide”,grp,false);
   div.setBounds(315,120,90,25);
   div.setFont(new Font(“Monotype Corsiva”,Font.BOLD,20));
   div.addItemListener(this);

   t1=new TextField(25);
   t1.setBounds(150,40,120,25);
   t1.setFont(new Font(“Monotype Corsiva”,Font.BOLD,18));

   t2=new TextField(25);
   t2.setBounds(150,80,120,25);
   t2.setFont(new Font(“Monotype Corsiva”,Font.BOLD,18));

   t3=new TextField(45);
   t3.setBounds(150,160,120,25);
   t3.setFont(new Font(“Monotype Corsiva”,Font.BOLD,18));

   l1=new Label(“1st Value: “);
   l1.setBounds(40,40,90,25);
   l1.setFont(new Font(“Monotype Corsiva”,Font.BOLD,18));

   l2=new Label(“2nd Value: “);
   l2.setBounds(40,80,90,25);
   l2.setFont(new Font(“Monotype Corsiva”,Font.BOLD,18));

   l3=new Label(“Result =”);
   l3.setBounds(40,160,80,25);
   l3.setFont(new Font(“Monotype Corsiva”,Font.BOLD,20));

   l4=new Label(“MUHAMMAD  KALEEM”);
   l4.setBounds(70,230,300,35);
   l4.setFont(new Font(“Monotype Corsiva”,Font.BOLD,26));
  l4.setForeground(new Color(55,255,251));

   add(l1);
   add(t1);
   add(l2);
   add(t2);
   add(add);
   add(sub);
   add(mul);
   add(div);
   add(l3);
   add(t3);
   add(l4);

   setVisible(true);
  }
  public void itemStateChanged(ItemEvent ie)
   {
   String s=””;
   if(ie.getSource()==add)
   {      t3.setText(s.valueOf(Integer.parseInt(t1.getText())+Integer.parseInt(t2.getText())));
    }
   if(ie.getSource()==sub)
    {
     t3.setText(s.valueOf(Integer.parseInt(t1.getText())-
Integer.parseInt(t2.getText())));
    }

   if(ie.getSource()==mul)
   {     t3.setText(s.valueOf(Integer.parseInt(t1.getText())*Integer.parseInt(t2.getText())));
   } 
  if(ie.getSource()==div)
   {     t3.setText(s.valueOf(Integer.parseInt(t1.getText())/Integer.parseInt(t2.getText())));
   } 
 }
}

class p1
{
  public static void main(String str[])
  {
   MyFrame f=new MyFrame();
   }
 }

You May also Like

  1. How to connect java with database|Using JDBC-ODBC Connection string
  2. How to Create combo box in java|Complete Coding
  3. Java program to calculate Age from Date of birth
  4. How to create a Recruitment or job announcement page in asp.net | Complete front end designing and backend coding
  5. How to Add multiple textbox values and showing their sum
  6. Employee Registration form | Creation of Registration form in visual studio using c# and asp.net
  7. How add new webpage in a website using C#, asp.net in visual studio.
  8. How to create login page using asp.net and C#


We will be happy to hear your thoughts

Leave a reply

eSkillsInstitute
Logo
Register New Account
Shopping cart