gui question
design a gui application for me and write its code in which the user enters a no. in a textfield and onn clicking the button the sum of the digits of the no. should be displayed. hint: suppose the user enters 12 the output should be 6(1+2+3).
View Answers
August 2, 2011 at 5:10 PM
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class SumOfDigits{
public static void main(String[] args){
Frame f=new Frame();
Label label1=new Label("Enter Number: ");
Label label2=new Label("Sum of Digits: ");
final TextField text1=new TextField(20);
final TextField text2=new TextField(20);
Button b=new Button("Find");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String v1=text1.getText();
int sum=0;
int n = Integer.parseInt(v1);
int t = n;
while (n > 0) {
int p = n % 10;
sum = sum + p;
n = n / 10;
}
text2.setText(Integer.toString(sum));
}
});
Panel p=new Panel(new GridLayout(3,2));
p.add(label1);
p.add(text1);
p.add(label2);
p.add(text2);
p.add(b);
f.add(p);
f.setVisible(true);
f.pack();
}
}
Ads
Related Tutorials/Questions & Answers:
gui question
gui question design a
gui application for me and write its code in which the user enters a no. in a textfield and onn clicking the button the sum of the digits of the no. should be displayed. hint: suppose the user enters 12
gui question
gui question design a
gui application and write code to accept a string from the user in a textfeild and print using option pane whether it is a palindrome or not. hint: abba is a palindrome
import java.awt.*;
import
Advertisements
GUI
GUI How to
GUI in Net-beans ... ??
Please visit the following link:
http://www.roseindia.net/java/java-tips/background/30java_tools/netbeans.shtml
GUI
GUI Write a
GUI application for the WebBuy Company that allows a user to compose the three parts of a complete email message: the â??To:â??, â??Subject:â?? and â??Message:â?? text. The â??To:â??, and â??Subject:â?? Text areas
question
question sir plz tell me what should i give in title box. just i want java program for the
question typed in this area
question
question sir plz tell me what should i give in title box. just i want java program for the
question typed in this area
Question
Question When there is an exception in my program how java runtime system handles
question
question dear sir/madam
my
question is how to compare two text format in java..we are java beginners..so we need the complete source code for above mentioned
question...we have to compare each and every word
question
question Dear sir
i had some typing mistake at previous
question
so its my humble request to let me know the steps to start the tomcat6 under the tomcat directory
Java GUI
Java GUI 1) Using Java
GUI, create a rectangular box that changes color each time a user click a change color button.
2) Modify
Question 1 to include a new button named insert image, that allow user to insert a bitmap image
Question?
Question? My
question is how to:
Add a menu bar to the program with a File menu.
In the File menu, add a submenu (JMenuItem) called About.
When the user clicks on the About menu item, display a JOptionPane message dialog
GUI problem
GUI problem Create a class called CDProgram and write a
GUI program to compute the amount of a certificate of deposit on maturity. The sample data follows:
Amount deposited: 80000.00
Years: 15
Interest Rate: 7.75
Hint
java gui
java
gui friends... good day..
i have doubt in java
gui.
? i created 1 java
gui application. That has two text fields jtext1,jtext2.
case: user entered value in first textfield(jtext1) and pressed the enter key . the cursor
GUI problem
GUI problem How do I make a Jbutton which is shaped like a circle. This button needs to be clicked in order to change color.
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class
ModuleNotFoundError: No module named 'gui'
ModuleNotFoundError: No module named '
gui' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
gui'
How to remove the ModuleNotFoundError: No module named '
gui' error
Question on pooling
Question on pooling which server supports pooling?Application server or web server