-
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.
-
1. implement the interface 'ActionListener'
2. write the actionPerformed(ActionEvent) method, which updates your bar graph
3. voteButton.addActionListener(this);
Similar Threads
-
Replies: 4
Last Post: 01-22-2008, 01:04 PM
-
Replies: 0
Last Post: 03-17-2005, 11:47 AM
-
By Prasant in forum VB Classic
Replies: 0
Last Post: 07-29-2001, 12:46 PM
-
By joni in forum VB Classic
Replies: 0
Last Post: 07-13-2000, 05: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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks