Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners program for factorial
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Suraj Arun Nalawade
program for factorial
1 Answer(s)      3 years and 11 months ago
Posted in : Java Beginners


how to set size of buttons on frame


Advertisement
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... exception". Example of Factorial program in Java: import java.io.*; class... 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
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
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
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
; factorial* temp and keep on decreasing the value of temp by l. Code of the Program...Finding a Factorial using while loop      In this example we are going to find out the factorial of 12 by using
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  
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
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"
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
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
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
program
program  any program of hotel or school management
program
program  write a program different between to dates in terms of days in java
program
program  write a html program in show table and this word in box
program
program  write a javascript program to create a application form with validation
program
program  program of jdbc using ms access for creating table
program
program  WAP a java program to form 1/2+3/4+5/6+7/8 series
program
program  develop a servlet to insert the data in the database from our program in the table stored in the database
program
program  write a program reversee a string. input-hi this is roseindia output-roseindia is this hi
program
program   Write a program to find the difference between sum of the squares and the square of the sums of n numbers
Advertisements
 

 

 

DMCA.com