Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: regarding programing  (Read 3333 times)

0 Members and 1 Guest are viewing this topic.

khushi

    Topic Starter


    Starter

    regarding programing
    « on: August 30, 2008, 06:21:38 AM »
    i have one problem.  :((how to make button in swing which come in a single column,and gap  in every button like   
    .....................button 1...............

    ....................button2............ .......

    .....................button3........... .......



    ....plz give the solution...

    r3ynz_t4nz



      Beginner
    • A programmer is a king
      Re: regarding programing
      « Reply #1 on: August 31, 2008, 04:33:58 AM »
      you can  try this code.,.,. i cant give you the full JAVA Source codes of your problem,.,.,
      but you can, make my code as a sample.,.,

      r3ynz_t4nz



        Beginner
      • A programmer is a king
        Re: regarding programing
        « Reply #2 on: August 31, 2008, 04:34:54 AM »
        /* A program that ddetermined if the second Number is a multiple of the first
         * Programmer: Reynante C. Tancio
         * Proram Title: Multiple.java
         */

        import java.awt.*;
        import java.awt.event.*;
        import javax.swing.*;



             public class Multiple extends JFrame {

                     int num1;
                     int num2;

                   private JLabel numLabel,Labelnum;
                   private JTextField numField,Fieldnum,print;
                   private JButton testButton;


               public Multiple() {

                  super( "\t MULTIPLE NUMBERS" );

                      Container tanz = getContentPane();

                    tanz.setLayout( new FlowLayout() );

                    numLabel = new JLabel( "First integer:");
                    numField = new JTextField(4);


                    tanz.add ( numLabel );
                    tanz.add ( numField );


                    Labelnum = new JLabel( "Second integer:");
                  Fieldnum = new JTextField(4);
                        tanz.add ( Labelnum );
                            tanz.add ( Fieldnum );


                      testButton = new JButton("Test");
                      testButton.addActionListener(
                     new ActionListener() {
                        public void actionPerformed( ActionEvent e ) {

                                           String num1,num2;
                                          int n1, n2;

                                            num1 = numField.getText();
                                            num2 = numField.getText();

                                n1 = Integer.parseInt(num1);
                                   n2 = Integer.parseInt(num2);


                                     if ( n2 % n1 == 0 ) {

                                       print.setText("The second number is multiple of the first.");

                                 }


                             else {
                                    print.setText("The second number is not a multiple of the first.");
                              }
                          }
                        }
                     );


                     tanz.add(testButton);

                     print = new JTextField(25);
                     print.setEditable (false);
                     tanz.add(print);


              }


               public static void main ( String [] reynz ) {

                  Multiple my = new Multiple();

                  my.setSize(300,150);
                  my.show();

             }

          }


        no try = no how