Hey so I've been working on a lab for my intro to software developing class and have been trying to get my program to work for hours since yesterday morning. It's a real basic program, im sure someone will be able to figure out the issue im having. Hopefully once I learn what I'm doing I'll be able to return the favor, but until then thanks, heres the code.
I bolded the errors which happen when I try to reference the non static variable in my main method which i know doesnt work, but I cant seem to get it, there are always either errors, the program freezes, or just completely does nothing. Any help is appreciated, thanks!
package lab8; import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Scanner; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; @SuppressWarnings("serial") public class GUIMonthNames extends JFrame { private JLabel instructions; private JTextField data; public GUIMonthNames() { super("Month Names: GUI version"); setSize(400,400); setDefaultCloseOperation(EXIT_ON_CLOSE); Container myPane = getContentPane(); myPane.setLayout(new FlowLayout()); instructions = new JLabel("Enter a number (1-12) below"); data = new JTextField(20); add(data); add(instructions); setVisible(true); } public static void main(String[] args) { new GUIMonthNames(); [B]data[/B].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Scanner keyboard = new Scanner(System.in); int monthNumber = keyboard.nextInt(); monthNumber = new Integer([B]data[/B].getText()); final String MONTH_TABLE = "January February March April May June " + "July August SeptemberOctober November December "; int start = (monthNumber - 1) * 9; int stop = start + 9; String monthName = MONTH_TABLE.substring(start, stop); [B]data[/B].setText(monthNumber + " is '" + monthName.trim() + "'."); } }); }}