George Kosmadakis wrote:I have in a JPanel on the top left a Combobox with 3 items and in the top right two JRadioButtons. The radiobuttons switch between two different charts, Pie chart and Bar Chart. The 3 items on combobox are for total expenses, September expenses and October expenses. What i want to achieve is switching between the two charts (which i already do) and at the same time while being in one of the two charts to be able to change the chart when the user selects every item from the combobox.
The problem is when i switch to the Bar Chart and select September the execution goes inside the createDatasetPie method and the monthCombo is Total Expenses falsely and it shows me the total expenses ofenter image description here Pie chart instead of the Bar Chart.
Fred Kleinschmidt wrote:In your action listener added to variable "month", the if-else construct beginning at line 58 is incomplete. if monthCombo is not "TotalExpenses" it then checks if pieChart.isSelected() and monthCombo is "September". So if barChart is selected, this is false and it goes to the next else, checking if monthCombo.equals("October") So if monthCombo is "September", this too fails and the if-block ends without doing anything.
Campbell Ritchie wrote:Please don't simply say, “It doesn't work”. Tell us what actually happens.
Fred Kleinschmidt wrote:You should really only have a single combo box and a single radio (containing "pie and "Bar" buttons) Then your top container contains the combobos, a title, and the radio buttons, and below that have a container where you can switch between the Pie and bar charts. The combobox action listener should then check the radio status to see which one is active and act on the appropriate one, and the radio button action listeners should check the combo box for the correct data to display in the pie or bar.
The combo box and buttons should not be created in buildPieChart() or buildBarChart(), but should be in the class that holds the charts. The BarChart should have no knowledge that the PieChart exists; that way it will be much easier to modify things if you were to add other views in the future.