I've just started swing, and had a few promising results, until my code got a little more complex. I've run into a problem, and I don't know enough to really understand why it's there. Basically, I have some code (which I will paste here after my explanation) that is supposed to create a window and add in a text area and text field. The problem is, the JPanel and JScrollPane variables aren't recognized as existent by the compiler. I can seem to figure out why.
Here's the entire code I'm working with:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class TerraGUI {
private static void createAndShowGUI() {
JFrame frame = new JFrame("Main Window");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel mainPane = new JPanel();
mainPane.setPreferredSize(new Dimension(800, 600));
frame.getContentPane().add(mainPain);
JScrollPane chatPain = new JScrollPane();
chatPain.setVerticalAlignment(JLabel.BOTTOM);
JTextField textField = new JTextField(20);
JTextArea textArea = new JTextArea();
textArea.setColumns(50);
textArea.setRows(10);
textArea.setEditable(false);
chatPane.add(textArea);
chatPane.add(textField);
frame.getContentPane().add(chatPain);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
And here's the compiler errors:
C:\Program Files\Java\jdk1.6.0_16\bin\javac "TerraGUI.java" (in directory: C:\Users\Cyle Dawson\Documents\Java\Terra)
TerraGUI.java:12: cannot find symbol
symbol : variable mainPain
location: class TerraGUI
frame.getContentPane().add(mainPain);
^
TerraGUI.java:15: cannot find symbol
symbol : method setVerticalAlignment(int)
location: class javax.swing.JScrollPane
chatPain.setVerticalAlignment(JLabel.BOTTOM);
^
TerraGUI.java:21: cannot find symbol
symbol : variable chatPane
location: class TerraGUI
chatPane.add(textArea);
^
TerraGUI.java:22: cannot find symbol
symbol : variable chatPane
location: class TerraGUI
chatPane.add(textField);
^
4 errors
Compilation failed.
Can anyone explain to me why the variables aren't recognized? I'm supposed to have a small, semi-functioning GUI by Sunday and this is confounding me.