Results 1 to 5 of 5

Thread: Calender

  1. #1
    dewitrydan is offline Member
    Join Date
    Aug 2010
    Posts
    67
    Rep Power
    0

    Default 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:
    Java 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);
    
    	}
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,864
    Rep Power
    8

    Default

    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).

  3. #3
    tashimoto is offline Member
    Join Date
    Sep 2010
    Location
    Oregon, usa
    Posts
    69
    Rep Power
    0

    Default

    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. :)

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,864
    Rep Power
    8

    Default

    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.

  5. #5
    dewitrydan is offline Member
    Join Date
    Aug 2010
    Posts
    67
    Rep Power
    0

    Default

    I got it working.
    It was because I didn't the main method.
    Stupid mistake.
    thanks all

Similar Threads

  1. Can't Get Gregorian Calender to Work
    By bengregg in forum Java Applets
    Replies: 1
    Last Post: 10-20-2010, 08:57 AM
  2. Small calender program
    By Moustafa taha in forum New To Java
    Replies: 1
    Last Post: 10-19-2010, 07:52 PM
  3. Calender Program Help Needed!!
    By DavidEvans in forum New To Java
    Replies: 1
    Last Post: 03-17-2010, 06:37 PM
  4. Calender
    By tiger100plus in forum New To Java
    Replies: 1
    Last Post: 12-26-2008, 07:20 PM
  5. date and calender not getting the right results
    By valoyivd in forum New To Java
    Replies: 4
    Last Post: 04-14-2008, 11:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •