-
Calender
hello, I am following this tutorial on how to make a calander on a single month in java.
I can't get anything to appear in the grey box when I run it.
Can you tell me where I am going wrong?
thanks
here is my code:
Code:
import java.awt.*;
import javax.swing.*;
class cal extends JFrame {
JPanel months_1;
JPanel title;
Container everything;
public String[] days;
public cal() {
title = new JPanel();
days = new String[] { "monday", "tuesday", "wednesday", "thursday",
"friday", "saturday", "sunday" };
title.add(new JLabel("month of hahaha"));
everything = getContentPane();
everything.setLayout(new FlowLayout());
months_1 = new JPanel();
months_1.setLayout(new GridLayout(7, 111));
for (int i = 0; i < 7; i++) {
months_1.add(new JLabel(days[i]));
}
for (int i = 0; i < 30; i++) {
months_1.add(new JLabel(Integer.toString(i)));
}
everything.add(title);
everything.add(months_1);
setContentPane(everything);
}
}
-
You'll probably want to provide an SSCCE and use standard naming conventions (for example, classes start with an upper-case letter, variables and methods with a lower-case letter).
-
Unless you have another file, you are missing your "main" code :
public static void main(String[] args) { ...... }
otherwise, set your cal() object that you create in your main to visible.
Checkout the JComponent document:
JComponent (Java Platform SE 6))
Your code worked for me... there are just a couple of layout issues when I ran it. :)
-
He said he's getting a gray box, so I doubt it's something as simple as a missing setVisible(). He might be setting the wrong JFrame to visible, but an SSCCE would clear it all up.
-
I got it working.
It was because I didn't the main method.
Stupid mistake.
thanks all