WhatRain's Java 2 Examples

WhatRain's Java 2 Examples Radio Buttons

I am just starting to learn Java and have to make an applet. I am totally lost, can anyone help me. I have to create an applet that displays four panels containing information about your own emrolment details at university.

Panel #1
three radio buttons:
button #1 labelled "major"
button #2 labelled "minor"
button #3 labelled "submajor"

Panel #2
two radio buttons:
button #1 labelled "Bankstown"
button #2 labelled "Campbelltown"

Panel #3
three checkboxes
checkbox #1 labelled "fullltime"
checkbox #2 labelled "part time"
checkbox #3 labelled "flexible delivery"

Panel #4
two textfields displaying the results of the selections on panels #1, #2, #3.

Can anyone help me?
Thanks

Radio Buttons


Source

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

/**
 * 	
 * 	An Applet to demostrate radio buttons 
 * 	using the Checkbox and CheckboxGroup classes
 * 	@author	http://www.whatrain.com/
 * 	@version	beta 0.1
 * 	@author		Timothy M. Radonich
 * 	@author		WhatRain Internet Services
 * 	@author		timmy@whatrain.com
 */



public class RadioButtonDemo extends Applet implements 
					ItemListener
{

//  ========================================
//		  APPLET METHODS
//  ========================================


    	public void init()
    	{
        setSize(400,300);
	setBackground( SystemColor.activeCaptionBorder );

	Panel panel1 = new Panel( new FlowLayout () );
	Panel panel2 = new Panel( new FlowLayout () );
	Panel panel3 = new Panel( new FlowLayout () );
	Panel panel4 = new Panel( new FlowLayout () );

	panel1.add( panel1OptionA ) ;
	panel1.add( panel1OptionB ) ;
	panel1.add( panel1OptionC ) ;

	panel2.add( panel2OptionA ) ;
	panel2.add( panel2OptionB ) ;

	panel3.add( panel3CheckA ) ;
	panel3.add( panel3CheckB ) ;
	panel3.add( panel3CheckC ) ;

	output1.setEditable(false) ;
	output2.setEditable(false) ;

	panel4.add( output1  ) ;
	panel4.add( output2  ) ;

	panel1OptionA.addItemListener ( this ) ;  
	panel1OptionB.addItemListener ( this ) ;  
	panel1OptionC.addItemListener ( this ) ;

	panel2OptionA.addItemListener ( this ) ;
	panel2OptionB.addItemListener ( this ) ;

	panel3CheckA.addItemListener ( this ) ;
	panel3CheckB.addItemListener ( this ) ;
	panel3CheckC.addItemListener ( this ) ;
	 


	setLayout(new GridLayout(4,1) );
	add( panel1 );
	add( panel2 );
	add( panel3 );
	add( panel4 );


    	}
//  ========================================
//		  IMPLEMENT ITEMLISTENER
//  ========================================

	public void itemStateChanged ( ItemEvent theEvent )

	{
		String outputText = " " ;

		if( panel1Group.getSelectedCheckbox() != null )
		 outputText = 
		  panel1Group.getSelectedCheckbox().getLabel() ;

		if (panel3CheckA.getState()) 
		 outputText = 
		  outputText + ",  " + panel3CheckA.getLabel() ;

		if (panel3CheckB.getState()) 
		 outputText = 
		  outputText + ",  " + panel3CheckB.getLabel() ;

		if (panel3CheckC.getState()) outputText = 
		 outputText + ",  " + panel3CheckC.getLabel() ;	
		 
		output1.setText( outputText ) ;

		outputText = " " ;

		if( panel2Group.getSelectedCheckbox() != null )
		 outputText = 
		  panel2Group.getSelectedCheckbox().getLabel() ;

		output2.setText( outputText ) ;
	}


//  ========================================
//		  USER INTERFACE
//  ========================================

    	private	CheckboxGroup panel1Group = new CheckboxGroup (  );
    	private CheckboxGroup panel2Group = new CheckboxGroup (  );

    	private	Checkbox panel1OptionA = new Checkbox 
		( "major", panel1Group, false );
    	private Checkbox panel1OptionB = new Checkbox 
		( "minor", panel1Group, false );
	private Checkbox panel1OptionC = new Checkbox 
		(  "submajor", panel1Group, false );

    	private	Checkbox panel2OptionA = new Checkbox 
		(  "Bankstown", panel2Group, false );
    	private Checkbox panel2OptionB = new Checkbox 
		( "Campbelltown", panel2Group, false );

    	private	Checkbox panel3CheckA = 
		new Checkbox ( "fullltime");
    	private Checkbox panel3CheckB = 
		new Checkbox ( "part time");
	private Checkbox panel3CheckC = 
		new Checkbox ( "flexible delivery" );

	private TextField output1 = new TextField(40) ;
	private TextField output2 = new TextField(40) ;	
	
}

WhatRain Java Examples WhatRain Java 2 Examples


JAVA is a tradmark of Sun Microsystems




Visit
What Rain Home port

This site designed and maintained by
WhatRain WWW Services

Contact Us