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 several days now. 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.

Right now there are no errors indicated by Eclipse, is it only a syntax error then, i feel like im missing something.

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 implements ActionListener {
	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);
		  data.addActionListener(this);
		  add(instructions);
		  setVisible(true);	
	}
	@Override
	public void actionPerformed(ActionEvent arg0) {
			int	monthNumber = new Integer(data.getText());
			Scanner keyboard = new Scanner(System.in);
			monthNumber = keyboard.nextInt();
			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);
							data.setText(monthNumber +	" is '" + monthName.trim() + "'.");	
					}
	public static void main(String[] args) {
				new GUIMonthNames();
	}
	
}

Recommended Answers

All 5 Replies

When you have a problem, please give us a complete description of it - full text of any error messages, or an exact description of what's wrong with the output.
Anyway... this is a GUI program, and on line 31 you get monthNumber from the field in your GUI - that's OK - but then you use a Scanner to replace that value with one from the console - that looks like a mistake.

i want to use the jtext field to input the number of the month AND then when you press enter it will display the month...I am supposed to do this using data.setText() as i did.

Please describe what you are seeing that is wrong with your program. It is hard to help if we don't know what you need help with.

Yes, OK, but what are lines 32 and 33 doing there - the input is in the text field, not in System.in. Just delete those 2 lines and see what happens.

jesus thats so painfully obvious. Thank you. It makes sense now but I figured it needed a scanner to recognize when the date was input. It works thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.