program for factorial

program for factorial

how to set size of buttons on frame

View Answers

November 15, 2010 at 1:14 PM

Hi Friend,

Using the setPreferredSize(new Dimension(40,15)); method, you can set the button size in awt in java.

Here is your required code:

import java.awt.*;
import java.awt.event.*;
import java.util.regex.*;
class ButtonSize extends Frame{
    Label l;
    ButtonSize(){
        Label lab=new Label("Enter number to find its factorial: ");
        final TextField text=new TextField(20);
        Button b=new Button("Find");
        Panel p=new Panel();
        l=new Label();
        Panel pan=new Panel();
        pan.add(l);
        b.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                String input=text.getText();
    Pattern p = Pattern.compile("[A-Z,a-z,&%$#@!()*^]");
    Matcher m = p.matcher(input);
if(m.find()){
    l.setText("*Enter only numeric value!");
    l.setSize(250,20);
    l.setForeground(Color.RED);
    ltext.setText("");
    }
else if(input.equals("")){
    l.setText("*Enter value!");
    l.setSize(250,20);
    l.setForeground(Color.RED);
    }
else{

    int num=Integer.parseInt(input);
    long fac=num;
    for(int i=num;i>1;i--){
        fac=fac*(i-1);
         }
         System.out.println(fac);
    l.setText("Factorial Of Number "+input+" is: "+Long.toString(fac));
    l.setSize(250,20);
    l.setForeground(Color.BLUE);
}
            }
        });
        p.add(lab);
        p.add(text);
        p.add(b);
        b.setPreferredSize(new Dimension(40,15));     
        add(p,BorderLayout.NORTH);
        add(pan,BorderLayout.SOUTH);
        pack();
        setVisible(true);
    }
    public static void main(String[] args){
        new ButtonSize();
    }
}

Thanks









Related Tutorials/Questions & Answers:
program for factorial
program for factorial  how to set size of buttons on frame
program for factorial
program for factorial  how to set size of buttons on frame
Advertisements
program on factorial of a given number in java
program on factorial of a given number in java  please tell me, how to write program on factorial of a given number in java
program on factorial of a given number in java
program on factorial of a given number in java  please tell me, how to write program on factorial of a given number in java
Factorial Program in Java
Factorial program in Java helps programmer to write factors of any given... of bounds exception". Example of Factorial program in Java: import java.io.... execution of the program. BufferReader is defined under the Java I/O package
Write a program to calculate factorial of any given number
program to calculate factorial of any given number. First of all define a class... Factorial Examples - Java Factorial Example to calculate factorial of any.... As in this program we are going to insert certain instruction by creating buffer reader
Write a program to find a factorial in any given number
Write a program to find a factorial in any given number This programming tutorial will teach you how to write a factorial of any given number... that is equal to 24, and factorial of  0! is 0 always.Example : A program to find
ModuleNotFoundError: No module named 'factorial'
ModuleNotFoundError: No module named 'factorial'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'factorial' How to remove the ModuleNotFoundError: No module named '
find the factorial
find the factorial  how to find the factorial through the while loop...) { int value = 5, factorial = 1, temp = value; while (temp > 0) { factorial *= temp; temp
factorial of fibonacci
factorial of fibonacci   A code for the factorial of a fibonacci series. Example when the user enters 6, the fibonacci series is 8 and the factorial will be 8! or 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1. So if the user enters the number 6
ModuleNotFoundError: No module named 'factorial-hunan'
ModuleNotFoundError: No module named 'factorial-hunan'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'factorial-hunan' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'factorial_qxj'
ModuleNotFoundError: No module named 'factorial_qxj'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'factorial_qxj' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'factorial-hunan'
ModuleNotFoundError: No module named 'factorial-hunan'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'factorial-hunan' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'factorial_qxj'
ModuleNotFoundError: No module named 'factorial_qxj'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'factorial_qxj' How to remove the ModuleNotFoundError: No module named
factorial - Java Beginners
factorial Example in Java  The factorial method is used frequently in probability problems. The factorial of a positive integer n (written as n!) is equal... class Factorial Example{ public static long factorial(int n){ if(n <
How to get factorial in mysql
How to get factorial in mysql  Hi, In order to improve the speed... alot for a function in mysql to find factorial numbers of a number and couldn't.... example: for 1155, the factorial numbers would be: 3, 5, 7, 11 Thank you
Calculate factorial of a number.
Calculate factorial of a number.  How to calculate factorial...; import java.io.InputStreamReader; public class Factorial { public static...; } System.out.println(result); } } Description: - Factorial of any
program
program  write a java program to input a no. and print wheather the no. is a special no or not. (special no. are those no whose factorial of the sum of digit of the no is same as the original
Finding a Factorial using while loop
Finding a Factorial using while loop   ... are going to find out the factorial of 12 by using the while loop. In while loop... the scriptlet to calculate the factorial of 12. In the scriptlet we generally writes
factorial using recursive
factorial using recursive  can please give this code !i am going to do a factorial function using recursion definition and then . my professor told me that we are going to create a three screen. the first screen should be input
Finding a Factorial using while loop
Finding a Factorial using while loop      In this example we are going to find out the factorial of 12 by using... gets true. We are using the scriptlet to calculate the factorial of 12
Calculate factorial Using Recursion
by using recursion in jsp. To make a program on factorial, firstly it must... a program on factorial by using recursion in jsp we are going to design a html page...Calculate factorial Using Recursion  
Calculating factorial in JRuby
Calculating factorial in JRuby   ... program" example you must be aware with the way to run JRuby program. Now in this example you will know to "Calculate Factorial in JRuby"
Java Swing Compute Factorial
Java Swing Compute Factorial In this section, we are going to find the factorial of a given number. Here an user is allowed to enter a number into the text field whose factorial is to be determined. On pressing the button the value
find factorial of any number using recursion
find factorial of any number using recursion  error in 14 line ; expected int rec( int a) ^ how to resolve this.please correct the code. import java.io.*; class Fact { public static void main(String[]arg)throws IOException
Java Program - Java Beginners
Java Program  Write a program to find the Factorial of a number using Recursion. Factorial can be defined as Factorial(n) = 1 * 2 * 3 ‚?¶.* (n-1... FactorialUsingRecursion(); System.out.println("Factorial of 2 = " + f.findFactorial(2
program
program  any program of hotel or school management
program
program  program of jdbc using ms access for creating table
program
program  write a javascript program to create a application form with validation
program
program  write a html program in show table and this word in box
program
program  write a program different between to dates in terms of days in java
program
program  WAP a java program to form 1/2+3/4+5/6+7/8 series
program
program   Write a program to find the difference between sum of the squares and the square of the sums of n numbers
program
program  write a program reversee a string. input-hi this is roseindia output-roseindia is this hi
program
program  develop a servlet to insert the data in the database from our program in the table stored in the database
program
program   An old-style movie theater has a simple profit program. Each customer pays $5 per ticket. Every performance costs the theater $20, plus $.50 per attendee. Develop the program calculateTotalProfit that consumes
program
program  Develop the program calculateCylinderArea, which accepts radius of the cylinder's base disk and its height and computes surface area of the cylinder
program
program  explanation of program on extending thread class   Hi Friend, Please go through the following link:ADS_TO_REPLACE_1 Java Threads Thanks
program
program  Develop a program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time, and the Pythagorean
program
program  how to improve programming skills plss tell some tips..i am understanding concepts but unable to write program so,pls give some guideness plsss
Program
Program  a program to prove that default constructor of super class is available to subclass by default. Define a parameterize constructor for super class to store name = ‚??Tommy‚?? age=‚??23‚?? and call this constructor
Program
Program  a program to create two classes Commercial and Domestic. Override the method calculatebill() of Commercial class(Rs.8 per unit) into Domestic class(Rs 6 per unit) to compute electricity bill for both classes
program
program  no i want a program that shows how merge sort algorithm works in graphical representations like numbers are taken in circles and computation... in rectangles or circles wat ever it may be. the theme of program is to show algorithm
program
program  . Develop a program that accepts an initial amount of money (called the principal), a simple annual interest rate, and a number of months will compute the balance at the end of that time. Assume that no additional
program
program  Write a JSP Program, which displays a web page containing the name of the Courses, Courses being offered currently, number of students enrolled in each course, new courses to be offered, eligibility criteria for taking
program
program  i want a progra in java to print a sentence in alphabetic order, taking the input from the user.the program should writen without using the array for example : if input= this is a cat then output sould = a cat
program
program  Utopias tax accountants always use programs that compute income taxes even though the tax rate is a solid, never-changing 15%. Define the program calculateTax which determines the tax on the gross pay. Define
program
program  Write a JSP Program, which displays a web page containing two web links one for your profiling and other for the schedule of theory of practical classes of your Batch. When one click on link for getting your profile
program
program  Write a program to print details of a week for a particular day using array of objects Integer and String. OUTPUT: First Day of Week is Monday Second Day of Week is Tuesday Third Day of Week is Wednesday Forth Day
java program code
java program code  can any one write a program (class) which will have two methods Fibonacci and Factorial, which will be a void and a return respectively. i will be glad if it can have a good display results

Ads