Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-05-2012, 02:00 PM   PM User | #1
Samer898
New to the CF scene

 
Join Date: May 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Samer898 is an unknown quantity at this point
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
Samer898 is offline   Reply With Quote
Old 05-05-2012, 03:18 PM   PM User | #2
dan-dan
Regular Coder

 
dan-dan's Avatar
 
Join Date: Aug 2009
Location: England
Posts: 483
Thanks: 22
Thanked 79 Times in 78 Posts
dan-dan is on a distinguished road
I find it pretty hard to understand what you're saying. Can you post your code?
dan-dan is offline   Reply With Quote
Old 05-05-2012, 04:52 PM   PM User | #3
Samer898
New to the CF scene

 
Join Date: May 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Samer898 is an unknown quantity at this point


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..
Samer898 is offline   Reply With Quote
Old 05-06-2012, 01:37 PM   PM User | #4
dan-dan
Regular Coder

 
dan-dan's Avatar
 
Join Date: Aug 2009
Location: England
Posts: 483
Thanks: 22
Thanked 79 Times in 78 Posts
dan-dan is on a distinguished road
Can you post what code you have so far?
dan-dan is offline   Reply With Quote
Old 05-07-2012, 08:39 AM   PM User | #5
Bushman
New Coder

 
Join Date: Apr 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Bushman is an unknown quantity at this point
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.
Bushman is offline   Reply With Quote
Old 05-07-2012, 09:34 PM   PM User | #6
Samer898
New to the CF scene

 
Join Date: May 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Samer898 is an unknown quantity at this point
what is the code exactly??
Samer898 is offline   Reply With Quote
Old 05-08-2012, 05:45 AM   PM User | #7
Bushman
New Coder

 
Join Date: Apr 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Bushman is an unknown quantity at this point
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..
Bushman is offline   Reply With Quote
Reply

Bookmarks

Tags
gui, java, jframe, netbeans

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:42 AM.


Advertisement
Log in to turn off these ads.