0 Replies - 886 Views - Last Post: 23 February 2009 - 07:44 AM Rate Topic: -----

#1 Public Designs  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 145
  • Joined: 08-November 08

Add control statement to a frame

Post icon  Posted 23 February 2009 - 07:44 AM

This is what I have. It makes a frame with 2 options. I need to make a control statement so something happens when either is selected. Where would I put the control statements in this code and how should I structure it.

When Bar chart is selected I am going to need it to call another class file. When Pie chart is selected a different class file.

// a class to run the program. request user inputs and work from methods

// imports whats needed
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;
import javax.swing.JLabel;



  public class ChartFrame{
	  
	  
  public static void main(String[] args) {
	  
	  
	  
	  
	  
	//create a new frame with a title  
	JFrame cframe=new JFrame("Do it Yourself Charts!");
	
	
	//add a label to the frame asking what chart to use
	JLabel chart=new JLabel("Would you like to make a pie or bar chart?:");
	
	cframe.setLayout(new GridLayout(0, 1));
	CheckboxGroup cg1=new CheckboxGroup();
	
	// adds the label to the frame
	cframe.add(chart);
	
	//adds two options to the frame. pie or bar chart
	cframe.add(new Checkbox("Pie", cg1, false));
	cframe.add(new Checkbox("Bar", cg1, false));
	
   
	
	// sets the frame size
	cframe.setSize(500,500);
	
	//makes the frame visible
	cframe.setVisible(true);
	
	// makes it so the frame can be closed and exit program
	
	 cframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
	
  }
} 


Is This A Good Question/Topic? 0
  • +

Page 1 of 1