Reputation: 21
I am trying to compile my java class files however I am unable to do so due to the java on my school computer being old (java 6) whereas on my own laptop it works (java 7)
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
public class GUI extends JFrame {
private Rainfall rainfall;
/**
* Creates new form GUI
*/
public GUI(String fileName) {
rainfall = new Rainfall(fileName); //Initialise rainfall data
this.setTitle("Rainfall Analysis"); //Define the title
this.setSize(750, 650); //Define the size of the window
this.setResizable(false); //Disable resizability
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Definition of the menu
JMenuBar menuBar = new JMenuBar(); // Initialisation of the first menu bar
JMenu menuA = new JMenu("Rainfall Information"); // Build first menu
// A group of JMenuItems
JMenuItem menuItemA1 = new JMenuItem("Global Information"); // Create a menu item containing "Global Information" as text
JMenuItem menuItemA2 = new JMenuItem("Month Calendar Based Information");
JMenuItem menuItemA3 = new JMenuItem("Month Graphical Based Information");
menuA.add(menuItemA1);
menuA.addSeparator(); // We add a seperator to seperate the menu items
menuA.add(menuItemA2);
menuA.addSeparator();
menuA.add(menuItemA3);
JMenu menuB = new JMenu("Rainfall Analysis"); // Initialisation of the second menu bar
JMenuItem menuItemB1 = new JMenuItem("Yearly statistics"); // Create a menu item containing "Yearly Statistics" as text
JMenuItem menuItemB2 = new JMenuItem("Comparison between two months' rainfall"); // Create a menu item
menuB.add(menuItemB1); // Add menuItem to the menu(menuB)
menuB.addSeparator(); // We add a seperator to seperate the menu items
menuB.add(menuItemB2);
//Associate events to menu items
menuItemA1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
setContentPane(new RecordsView(rainfall)); //Make RecordsView as the content panel
getContentPane().revalidate();
getContentPane().repaint();
}
});
menuItemA2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
setContentPane(new MonthCalendarView(rainfall));//Make MonthCalendarView as the content panel
getContentPane().revalidate();
getContentPane().repaint();
}
});
menuItemA3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
setContentPane(new MonthGraphicalView(rainfall));//Make MonthGraphicalView as the content panel
getContentPane().revalidate();
getContentPane().repaint();
}
});
menuItemB1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
JPanel p = new JPanel();
p.setSize(750, 650);
setContentPane(p);
getContentPane().add(rainfall.getGlobalChartByYears()); //Make Chart that show statistics over years as the content panel
getContentPane().revalidate();
getContentPane().repaint();
}
});
menuItemB2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
setContentPane(new ComparisonView(rainfall)); // Set the comparisonView as the content of content pane so that it will be displayed in the GUI
getContentPane().revalidate();
getContentPane().repaint();
}
});
menuBar.add(menuA); // Add menuA to menuBar
menuBar.add(menuB); // Add menuB to menuBar
//End menu
this.setJMenuBar(menuBar); // Set the menu bar (menuBar) as the menu bar of the container
this.setContentPane(new RecordsView(rainfall));
}
/**
* @param args the command line arguments
*/
public static void main(final String args[]) {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GUI(args.length==0?"2RainfallDataLanc.txt":args[0]).setVisible(true);
}
});
}
}
Error received when compiling:
GUI.java:90: cannot find symbol
symbol : method revalidate()
location: class java.awt.Container
getContentPane().revalidate();
^
java version is: Version 6 Update 45
Whereas I have been working on Version 7 when coding the project.
It seems that version 6 of java does not recognize revalidate.
I have tried to use invalidate, since looking around invalidate is used for java 6.
My question (apologies for not adding it at the start); how would I compile it with java 6?
Thanks
Upvotes: 1
Views: 2651
Reputation: 159784
As a workaround you could do
invalidate();
validate();
This approximates to what is occurring in revalidate without RootPane
recursion.
Another option is to invoke pack if the window size has not changed.
Although upgrading to Java 7 would be simpler
Upvotes: 2