8 Replies - 264 Views - Last Post: 08 February 2012 - 11:42 PM Rate Topic: -----

Topic Sponsor:

#1 Aurito  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-February 12

how can add array of weeks in to the GUI

Posted 08 February 2012 - 06:58 AM

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class JavaCalendar 
{
	private static final int i = 0;
	JLabel dateLabel, showEventPanel, lb4, lb5, lb6, lb7, lb8, lb9, lb10, optionlabel, weeklb, showEvent;
	JButton buttons, create, view, edit, csave, ccancel, vcreate, vedit, vcancel;
	JComboBox monthList, yearList;
	JFrame mainFrame;
	JPanel upperpanel, maincenterpanel, bottompanel, em1, em2, cm1, cm2, vm1, vm2;
	JTextField nameOfEvent, location, notes, startTime, endTime;
	int realYear, realMonth, realDay, currentYear, currentMonth;
	
	public JavaCalendar()
	{
		//Settings for main frame
		mainFrame = new JFrame();
		mainFrame.setTitle("Java Date Book");
		mainFrame.setSize(400, 250);
		mainFrame.setLayout(new BorderLayout());
		mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		//JPanels
		upperpanel = new JPanel();
		upperpanel.setLayout(new GridLayout(1,2));
		upperpanel.setBorder(BorderFactory.createTitledBorder("Date"));
		maincenterpanel = new JPanel();
		maincenterpanel.setLayout(new GridLayout(6, 8));
		bottompanel = new JPanel();
		bottompanel.setLayout(new BorderLayout());
		
		
		JButton buttons[] = new JButton[31];
		for(int i=0;i<buttons.length;i++)
		{
			buttons[i] = new JButton();
			buttons[i].setText(Integer.toString(i+1));
		}
		
		//labels
		dateLabel = new JLabel();
		dateLabel.setLayout(new BorderLayout());

		showEventPanel = new JLabel("None");
		showEventPanel.setLayout(new BorderLayout());
		
		Font f = new Font("Serif", Font.ITALIC, 20);
		lb4 = new JLabel("Sun");
		lb4.setLayout(new FlowLayout());
		lb4.setForeground(Color.red);
		lb5 = new JLabel("Mon");
		lb5.setLayout(new FlowLayout());
		lb6 = new JLabel("Tue");
		lb6.setLayout(new FlowLayout());
		lb7 = new JLabel("Wed");
		lb7.setLayout(new FlowLayout());
		lb8 = new JLabel("Thu");
		lb8.setLayout(new FlowLayout());
		lb9 = new JLabel("Fri");
		lb9.setLayout(new FlowLayout());
		lb10 = new JLabel("Sat");
		lb10.setLayout(new FlowLayout());
		
	[b]	//weeks label
		JLabel weeklb[] = new JLabel[5];
		for(int i=0;i<weeklb.length;i++)
		{
			weeklb[i] = new JLabel();
			weeklb[i].setText(Integer.toString(i+1));
		}[/b]
		
		//combo box
		String[] strvalue = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
		monthList = new JComboBox(strvalue);
		//combo box
		String[] stryear = {"2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020"};
		yearList = new JComboBox(stryear);
		
		//adding comboBox to panel 1
		upperpanel.add(monthList);
		upperpanel.add(yearList);
		
		//adding days label to panel 2
		maincenterpanel.add(lb4);
		maincenterpanel.add(lb5);
		maincenterpanel.add(lb6);
		maincenterpanel.add(lb7);
		maincenterpanel.add(lb8);
		maincenterpanel.add(lb9);
		maincenterpanel.add(lb10);
		

[b]		//adding array of button to panel 2
		int everySeven = 0;
		for(int i = 0; i < 31; i++)
		{
			
			
			if(everySeven++ %  7 == 0)
			{

		// the X is example, i am trying to put weeks so it goes 1, 2, 3, ...
				maincenterpanel.add(new JLabel("X"));
			}
			else {
				maincenterpanel.add(buttons[i]);
			}
	
		}[/b]
		
		
		//adding labels to panel 3
		bottompanel.add(dateLabel, BorderLayout.WEST);
		bottompanel.add(showEventPanel, BorderLayout.EAST);
		
		//Get real month/year
/*		GregorianCalendar cal = new GregorianCalendar(); //Create calendTimear
		realDay = cal.get(GregorianCalendar.DAY_OF_MONTH); //Get day
		realMonth = cal.get(GregorianCalendar.MONTH); //Get month
		realYear = cal.get(GregorianCalendar.YEAR); //Get year
		currentMonth = realMonth; //Match month and year
		currentYear = realYear;
*/		
		  Calendar currentDate = Calendar.getInstance();
		  SimpleDateFormat formatter= new SimpleDateFormat("MMMM-dd-yyyy HH:mm:ss");
		  String dateNow = formatter.format(currentDate.getTime());
		dateLabel.setText("Today: " +dateNow);
		
		
		mainFrame.add(upperpanel, BorderLayout.NORTH);
		mainFrame.add(maincenterpanel, BorderLayout.CENTER);
		mainFrame.add(bottompanel, BorderLayout.SOUTH);
		mainFrame.setVisible(true);
	}
public static void main (String[] args)
	{
		JavaCalendar jc = new JavaCalendar();
		JFrame.setDefaultLookAndFeelDecorated(true);
	}

}

This post has been edited by smohd: 09 February 2012 - 01:03 AM
Reason for edit:: Code tags added. Please use [code] tags when posting codes


Is This A Good Question/Topic? 0
  • +

Replies To: how can add array of weeks in to the GUI

#2 SwiftStriker00  Icon User is offline

  • Microsoft Insider
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,337
  • Joined: 25-December 08

Re: how can add array of weeks in to the GUI

Posted 08 February 2012 - 08:32 AM

Please :code:

Also what do you mean by an array of weeks?
String[] weeks = new String[]{ "Monday", "Tues", "etc.."};

Was This Post Helpful? 1
  • +
  • -

#3 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1413
  • View blog
  • Posts: 6,037
  • Joined: 20-September 08

Re: how can add array of weeks in to the GUI

Posted 08 February 2012 - 08:35 AM

Make life easy on yourself and use a proper calendar component. Google on 'toedter calendar'
Was This Post Helpful? 2
  • +
  • -

#4 Aurito  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-February 12

Re: how can add array of weeks in to the GUI

Posted 08 February 2012 - 10:10 PM

View PostSwiftStriker00, on 08 February 2012 - 08:32 AM, said:

Please :code:

Also what do you mean by an array of weeks?
String[] weeks = new String[]{ "Monday", "Tues", "etc.."};


I mean the weeks, that will show 1, 2, 3.

View Postg00se, on 08 February 2012 - 08:35 AM, said:

Make life easy on yourself and use a proper calendar component. Google on 'toedter calendar'


Thanks

I will try to work with the toedter

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#5 Sheph  Icon User is online

  • D.I.C Addict
  • member icon

Reputation: 295
  • View blog
  • Posts: 779
  • Joined: 12-October 11

Re: how can add array of weeks in to the GUI

Posted 08 February 2012 - 10:20 PM

The image clarifies your intentions, but perhaps you could tell us what part of the code you are having trouble with? Do you not know how to put a JLabel on the side? Or is it that you can't calculate the week numbers?
Was This Post Helpful? 1
  • +
  • -

#6 Aurito  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-February 12

Re: how can add array of weeks in to the GUI

Posted 08 February 2012 - 10:38 PM

if(everySeven++ % 7 == 0)
{

// the X is example, i am trying to put weeks so it goes 1, 2, 3, ...
maincenterpanel.add(new JLabel("X"));
}
else {
maincenterpanel.add(buttons[i]);
}

}


//weeks label
JLabel weeklb[] = new JLabel[5];
for(int i=0;i<weeklb.length;i++)
{
weeklb[i] = new JLabel();
weeklb[i].setText(Integer.toString(i+1));
}



This part is the problem and the new JLabel("X") is only trying i want to try putting the weeklb in the panel so it like adding the first week 1 than 7 button next week 2 than 7 buttons...
Was This Post Helpful? 0
  • +
  • -

#7 Sheph  Icon User is online

  • D.I.C Addict
  • member icon

Reputation: 295
  • View blog
  • Posts: 779
  • Joined: 12-October 11

Re: how can add array of weeks in to the GUI

Posted 08 February 2012 - 10:41 PM

entrySeven%7 can give you the day, entrySeven/7 can give you the week. You may have to add or subtract 1... I don't feel like thinking about it very much...
Was This Post Helpful? 0
  • +
  • -

#8 Aurito  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-February 12

Re: how can add array of weeks in to the GUI

Posted 08 February 2012 - 10:43 PM

Thanks I'll try it. :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#9 Aurito  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-February 12

Re: how can add array of weeks in to the GUI

Posted 08 February 2012 - 11:42 PM

Attached Image
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1