Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy I need help on net beans

    i am trying to make a simple exam using GUI

    i have jtextfield and i have another jfram with 3 questions
    i need to enter how many questions i need in the jtextfield like 2 question and the other frame show 2 question..
    can any body help me?? plzzzzz

  • #2
    Regular Coder dan-dan's Avatar
    Join Date
    Aug 2009
    Location
    England
    Posts
    483
    Thanks
    22
    Thanked 79 Times in 78 Posts
    I find it pretty hard to understand what you're saying. Can you post your code?

  • #3
    New to the CF scene
    Join Date
    May 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts


    i have this frame..
    when u enter the number of questions it show u the questions.. like 2 questions

    what i need is what is the code to show random questions.. ??
    and im sorry for my english its not good..

  • #4
    Regular Coder dan-dan's Avatar
    Join Date
    Aug 2009
    Location
    England
    Posts
    483
    Thanks
    22
    Thanked 79 Times in 78 Posts
    Can you post what code you have so far?

  • #5
    New Coder
    Join Date
    Apr 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Consider this.
    1.Place each menu's stuff on different panels.
    eg. panel1 ..add question entrance stuff
    panel2 ..add question showing result stuff
    Then make sure to set panel 2 visible to false first.


    Then when you click Ok button on panel1, set it's visibility to false,
    and set panel 2's visibility to true.

  • #6
    New to the CF scene
    Join Date
    May 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what is the code exactly??

  • #7
    New Coder
    Join Date
    Apr 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is the frame:
    import javax.swing.JFrame;
    import java.awt.Dimension;


    PHP Code:
    public class SimpleUiFrame
    {
        public static 
    void main String [ ] args )
        {
           
    //establish panel
           
    SimpleUi_Panel panel = new SimpleUi_Panel ( );
           
           
    //establish frame
           
    JFrame frame = new JFrame ( );
           
    frame.add panel );
           
    frame.setDefaultCloseOperation JFrame.EXIT_ON_CLOSE );
           
    frame.setPreferredSize ( new Dimension 800600 ) );
           
    frame.pack ( );
           
    frame.setVisible true ); 
        }


    This is the panel:
    PHP Code:
    import javax.swing.JPanel
    import javax.swing.JRadioButton;
    import javax.swing.JOptionPane;
    import javax.swing.JButton;
    import javax.swing.JTextField;
    import javax.swing.BoxLayout;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.Color;

    public class 
    SimpleUi_Panel extends JPanel
    {
        
    //attributes
            //initilize stuff for panel 0
                //radio buttons
                
    private JTextField textField0 null;
                private 
    JRadioButton radioButtons [ ] = null;
                private 
    int numRadioButtons 2;
                
    //radio button container
                
    private JPanel panel0_subContainer0 = new JPanel ( ), panel0_subContainer1 = new JPanel ( ), panel0_container = new JPanel ( );  
                
    //a button to go to panel 1
                
    private JButton proceed_button = new JButton "go to question info(OK)" );
                private 
    JButton cancel_button = new JButton "cancel" );
            
    //initialise stuff for panel 1
                //textboxxes
                
    private JTextField textField1 null;
                private 
    JButton exit_button = new JButton "exit question info" );
                private 
    JPanel panel1_subContainer = new JPanel ( ), panel1_container = new JPanel ( );
           
                
        
    //constructor
        
    public SimpleUi_Panel ( )
        {
            
    //setup panel 0 stuff
                //initialise text field
                
    textField0 = new JTextField "Enter num questions : " );
                
    panel0_subContainer0.add textField0 );
                
    //layout the contents of panel0_subContainer using box layout
                
    panel0_subContainer0.setLayout ( new BoxLayout panel0_subContainer0BoxLayout.X_AXIS ) );
                
    //add action listener to button
                
    proceed_button.addActionListener ( new actionListening ( ) );
                
    cancel_button.addActionListener ( new actionListening ( ) );            
                
    //add radio button panel + proceed button to this panel
                
    panel0_subContainer1.add proceed_button );
                
    panel0_subContainer1.add cancel_button );
                
    //layout the contents of panel0_subContainer using box layout
                
    panel0_subContainer1.setLayout ( new BoxLayout panel0_subContainer1BoxLayout.X_AXIS ) );
                
    //add buttons to sub container 1
                
    panel0_container.add panel0_subContainer0 );
                
    panel0_container.add panel0_subContainer1 );

                
    //layout the contents of panel0_container using box layout
                
    panel0_container.setLayout ( new BoxLayout panel0_containerBoxLayout.Y_AXIS ) );
                
    add panel0_container );
         
                    
            
    //setup panel 1 stuff 
                //initialise text field
                
    textField1 = new JTextField "LostWind" );
                
    panel1_container.add textField1 );
                
    panel1_container.add exit_button );
                
    panel1_container.setLayout ( new BoxLayout panel1_containerBoxLayout.Y_AXIS ) );
                
    //add action listener to button
                
    exit_button.addActionListener ( new actionListening ( ) );
                
    add panel1_container );
                
    panel1_container.setVisible false ); //initially disable the first panel
                
            //enable focus on this panel
            
    setFocusable true );
        }
        
        
    //action listener
        
    private class actionListening implements ActionListener
        
    {
            public 
    void actionPerformed ActionEvent aEvent )
            {
                
    Object event aEvent.getSource ( );
         
                if ( 
    event == proceed_button )
                {
                    
    textField1.setText "There are " textField0.getText ( ) + " questions " );
                    
    panel0_container.setVisible false );
                    
    panel1_container.setVisible true );
                }
                if ( 
    event == cancel_button )
                {
                    
    System.exit ( );
                }
                
                if ( 
    event == exit_button )
                {
                    
    panel1_container.setVisible false );
                    
    panel0_container.setVisible true );
                }
                
    repaint ( ); //repaint this panel
            
    }
        }
        



    This was done in BLUEJ.
    Last edited by Bushman; 05-08-2012 at 06:02 AM.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •