Bar chart


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Bar chart

  1. #1
    Join Date
    Jun 2006
    Posts
    1

    Bar chart

    I am new to Java and so far i have done the following code and now im stuck

    import javax.swing.*;
    public class OpinionPolls extends JFrame{
    JLabel questionLabel = new JLabel("Who will win the World Cup?:");

    JRadioButton option1 = new JRadioButton("Brazil");
    JRadioButton option2 = new JRadioButton("England");
    JRadioButton option3 = new JRadioButton("Germany");
    JRadioButton option4 = new JRadioButton("Italy");
    JButton voteButton = new JButton ("Vote");


    public OpinionPolls() {
    super ("Opinion Polls");
    setSize(500, 500); //size of window in pixels
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    ButtonGroup group = new ButtonGroup();
    group.add(option1);
    group.add(option2);
    group.add(option3);
    group.add(option4);

    JPanel commandPane = new JPanel();
    BoxLayout vertical = new BoxLayout (commandPane,
    BoxLayout.Y_AXIS);
    commandPane.setLayout(vertical);
    commandPane.add(questionLabel);
    commandPane.add(option1);
    commandPane.add(option2);
    commandPane.add(option3);
    commandPane.add(option4);
    commandPane.add(voteButton);

    add(commandPane);
    setVisible(true);

    }

    public static void main(String[] arguments){
    OpinionPolls be = new OpinionPolls();
    }

    }

    Can someone please urgently tell me what code i should add to this so that when a choice is highlighted and the vote button is pressed a bar chart appears. i know i need to import java.awt.event.*;and
    import java.awt.*; and i no i need to use action listener) All help is welcome. Thanks.

  2. #2
    Join Date
    Mar 2004
    Posts
    635
    1. implement the interface 'ActionListener'
    2. write the actionPerformed(ActionEvent) method, which updates your bar graph
    3. voteButton.addActionListener(this);

Similar Threads

  1. Replies: 4
    Last Post: 01-22-2008, 02:04 PM
  2. Replies: 0
    Last Post: 03-17-2005, 12:47 PM
  3. Replies: 0
    Last Post: 07-29-2001, 01:46 PM
  4. msChart don't display xY chart
    By joni in forum VB Classic
    Replies: 0
    Last Post: 07-13-2000, 06:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center