Breaking

Search

Wednesday, July 1, 2020

how to button creation in java and check box creation in java program

Button Creation and Checkbox Creation in java programming

 

how to button creation in java and check box creation in java program

  • Button Creation steps

The write a java program to demonstrate the concept of Button Creation.

 

The Following Button Creation Procedure Steps:


  • Step 1: Import Java . awt , applet and out Event package.
  • Step 2: Define a Class by name “ BUTTON DEMO ” that Extend “ Applet ” Class and implements Action list interface.
  • Step 3:  Declare int () and object to “ Button ” Class.
  • Step 4: Odd Button to applet object add ()
  • Step 5: Add action listener to the object of the button red button Add action listener this.
  • Step 6: One ride the  action Performed ( Active )
  • Step 7: Invoke get Action Commands
  • Step 8: using if block check the condition and Execute the result.
  • Step 9: The write HTML applet tag to view in applet viewer.

For Example: Button Creation Program

Import java.awt.*;

Import java.applet.*;

Import java.awt.event.ActionEvent;

Import java.awt.event.ActionListener;

/*              <applet code=”BUTTONDEMO” width=400 height=400>

</applet>      */

Public class ButtonDemo extends Applet implements ActionListener

{

Public void init()

{
Button redButton = new Button(“red”);

Button blueButton = new Button(“blue”);

Button greenButton = new Button(“Green”);

Button removeColorButton = new Button(“Remove Color”);

add(redButton);

add(blueButton);

add(greenButton);

add(removeColorButton);

 

redButton.addActionListener(this);

blueButton.addActionListener(this);

greenButton.addActionListener(this);

removeColorButton.addActionListener(this);

}

Public void actionPerformed(ActionEvent ae)

{

String action=ae.getActionCommand();

If(action.equals(“Red”))

{

setBackground(Color.red);

}

If (action . equals (“Blue”))

{

setBackground (Color.blue);

}

If (action . equals (“Green”))

{

setBackground (Color.green);

}


if (action . equal(“Remove color”))

{

setBackground (Color.white);

}
}
}

[ OUTPUT: ]

E:\AR\java>javac ButtonDemo.java

E:\AR\java>appletviewer ButtonDemo.java


how to button creation in java and check box creation in java program

RESULT:

[ Thus the Program Successfully Executed. ]

 

The Following  Checkbox Creation steps

The write a java program to Demonstrate the concept of Checkbox Creation.

  • Checkbox Creation procedure step:-

Step 1: import  java awt , applet and out event package.

Step 2: Define a class by name “ Check Box Demo ” that Extends “ Applet “class and implements item interface.

Step 3: Declare int () and create object to Choose box class and in taker two parameters Check Box (“ C programming ” , false )

Step 4: Add the Check box to applet using add()

Step 5: Invoke  add tem listener (this) to add the item listener to the Check box.

Step 6:  Declare paint Graphic

Step 7: Invoke g .draw string (c box c. get ) + ” :  “ +  c box c get state () 50 , 80 ); to display the status of the Check box.

Step 8: one ride on the method of interface item changed (Item enter I e)

Step 9: Declare re paint();

Step 10: The write HTML tag to view in applet View.

For Example: Checkbox Creation program

Import java.awt.*;

Import java.applet.*;

Import java.awt.event.*;

/*           <applet code=”Checkboxdemo” width=600 height=400>

</applet>        */

Public class CheckboxDemo extends Applet implements itemListener

{

Checkbox cboxC =null;

Checkbox cboxCpp =null;

Checkbox cboxjava =null;

Checkbox cboxDotNet =null;

Checkbox cboxphp =null;

Public void init()

{

CboxC = new Checkbox(“C programming”, false);

CboxCpp = new Checkbox(“C++ programming”, false);

CboxJava =new Checkbox(“Java programming”, false);

CboxDotNet = new Checkbox(“Dot Net”, false);

Cboxphp = new Checkbox(“PHP”, false);

add(cboxC);

add(cboxCpp);

add(cboxJava);

add(cboxDotNet);

add(cboxphp);

cboxC.additemListener(this);

cboxCpp.additemListener(this);

cboxJava.additemListener(this);

cboxDotNet.additemListener(this);

cboxphp.additemListener(this);

}

Public void paint(Graphics g)

{

g . drawString(cboxC.getLabel() + ” : ” + cboxC.getState(),150,80 );

g . drawString(cboxCpp.getLabel() + ” : ” + cboxCpp.getState(), 150, 120 );

g . drawString(cboxJava.getLabel() + ” : ” + cboxJava.getState(),150,160 );

g . drawString(cboxDotNet.getLabel() + ” : ” + cboxNet.getState(),150,200 );

g . drawString(cboxphpetLabel()  +  ” : ” + cboxphp.getState(),150,240 );

}

Public void itemStateChanged(itemEvent ie)

{

Repaint();

}
}

[ OUTPUT : ]

E: \AR\java>javac CheckboxDemo.java

E: \AR\java>appletviewer CheckboxDemo.java

 

how to button creation in java and check box creation in java program

RESULT:

[ Thus the Program Successfully Executed. ]

 

 Click Now: Java programming

 

 

 

 

 

 

 

 

 

 

 



 

 

No comments:

Post a Comment