For some reason my program isn't working. I want to display a button and when the button is clicked the user could input a number then the program will calculate and output the anaswer.
Java: |
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Factorial.java
*
* Created on May 22, 2010, 10:20:58 AM
*/
/**
*
* @author Daniel
*/
public class Factorial extends javax. swing. JFrame {
/** Creates new form Factorial */
public Factorial () {
initComponents ();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings ("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents () {
jPopupMenu1 = new javax. swing. JPopupMenu();
jButton1 = new javax. swing. JButton();
jTextField1 = new javax. swing. JTextField();
setDefaultCloseOperation (javax. swing. WindowConstants. EXIT_ON_CLOSE);
jButton1. setText("Factorial: Find the factorial of any number");
jButton1. addActionListener(new java. awt. event. ActionListener() {
public void actionPerformed (java. awt. event. ActionEvent evt ) {
jButton1ActionPerformed (evt );
}
});
jTextField1. setText("jTextField1");
jTextField1. addActionListener(new java. awt. event. ActionListener() {
public void actionPerformed (java. awt. event. ActionEvent evt ) {
jTextField1ActionPerformed (evt );
}
});
javax. swing. GroupLayout layout = new javax. swing. GroupLayout(getContentPane ());
getContentPane (). setLayout(layout );
layout. setHorizontalGroup(
layout. createParallelGroup(javax. swing. GroupLayout. Alignment. LEADING)
. addGroup(layout. createSequentialGroup()
. addContainerGap()
. addComponent(jButton1 )
. addGap(18, 18, 18)
. addComponent(jTextField1, javax. swing. GroupLayout. PREFERRED_SIZE, javax. swing. GroupLayout. DEFAULT_SIZE, javax. swing. GroupLayout. PREFERRED_SIZE)
. addContainerGap(78, Short. MAX_VALUE))
);
layout. setVerticalGroup(
layout. createParallelGroup(javax. swing. GroupLayout. Alignment. LEADING)
. addGroup(layout. createSequentialGroup()
. addGap(20, 20, 20)
. addGroup(layout. createParallelGroup(javax. swing. GroupLayout. Alignment. BASELINE)
. addComponent(jButton1 )
. addComponent(jTextField1, javax. swing. GroupLayout. PREFERRED_SIZE, javax. swing. GroupLayout. DEFAULT_SIZE, javax. swing. GroupLayout. PREFERRED_SIZE))
. addContainerGap(257, Short. MAX_VALUE))
);
pack ();
}// </editor-fold>
private void jButton1ActionPerformed (java. awt. event. ActionEvent evt ) {
//IMPRTANRDFDDG
int input = Interger. parstInt. tempTextField. getText
int factors= 1;
int count=input;
try
{
while (count> 1) //Starts a loop when count is greater than 1
{
factors*=count;
count--;
}
}catch(IOException ignored ){}
System. out. println("Answer"+input+ "!="+factors ); //Outputs the answer
}
private void jTextField1ActionPerformed (java. awt. event. ActionEvent evt ) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main (String args []) {
java. awt. EventQueue. invokeLater(new Runnable() {
public void run () {
new Factorial (). setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax. swing. JButton jButton1;
private javax. swing. JPopupMenu jPopupMenu1;
private javax. swing. JTextField jTextField1;
// End of variables declaration
}
|
Mod Edit: Edited title and added code tags. |