Tach erstmal ...
bin gerade dabei einen Kalender zu programmieren und möchte die Ausgabe der Tage eines Monats in 7x6 Buttons ausgeben (7 Wochentage und 6 Wochen). Leider findet man nur Kalenderberechnungen über Tabellen, jedoch will ich dies nicht.
Mit Calender und deren Methoden habe ich auch schon dafür gesorgt das der erste Tag eines Monats in der Zeile, Woche 1 , am jeweiligen Wochentag ausgegeben wird.
Mein Problem ist jetzt die restliche Ausgabe von Monatstag 2 bis max. 31 auf die restlichen Buttons mithilfe einer doppelten For-Schleife.
Ich programmiere erst seit nen knappen Jahr und habe halt noch einige Lücken xD Deshlab bitte ich um etwas Verständnis.
Ich poste mal die Klasse der Monatsberechnung.
Mit diesem Code werden mir jetzt leider nur Button mit dem String 31 ausgegebn. Wenn ich diese Ausgaben in der Console ausgeben lasse, sehe ich das die Anzahl der String * der Anzahl der Buttons gerechnet werden.
Die restlichen Klassen poste ich nicht, da es viel zuviel ist, fürs Verständnis aber auch nicht nötig. Der Rest ist GUI und etlichte Zusatzfunktion, was ein Kalender halt bieten soll.
Greez AlIastor
bin gerade dabei einen Kalender zu programmieren und möchte die Ausgabe der Tage eines Monats in 7x6 Buttons ausgeben (7 Wochentage und 6 Wochen). Leider findet man nur Kalenderberechnungen über Tabellen, jedoch will ich dies nicht.
Mit Calender und deren Methoden habe ich auch schon dafür gesorgt das der erste Tag eines Monats in der Zeile, Woche 1 , am jeweiligen Wochentag ausgegeben wird.
Mein Problem ist jetzt die restliche Ausgabe von Monatstag 2 bis max. 31 auf die restlichen Buttons mithilfe einer doppelten For-Schleife.
Ich programmiere erst seit nen knappen Jahr und habe halt noch einige Lücken xD Deshlab bitte ich um etwas Verständnis.
Ich poste mal die Klasse der Monatsberechnung.
Java:
import javax.swing.*;
import java.util.*;
/*****************
* ... *
*****************/
public class RechnungMonat {
// Instanzvariablen (Attribute, Member)
// <Datentyp> <Name> (<Zuweisung>)
public static String[] arrayString = {"","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"};
public static JButton[] arrayButton = new JButton[42];
public static JPanel jpCenterCenterMonatCenter = new JPanel ();
public static GregorianCalendar cal = new GregorianCalendar();
// Instanz-Methoden
public static void createRechnung() {
cal.get (Calendar.MONTH);
cal.set (Calendar.DAY_OF_MONTH, 1);
cal.set (Calendar.YEAR, 2012);
int currentDay = RechnungMonat.cal.get (GregorianCalendar.DATE);
int currentWeekDay = RechnungMonat.cal.get (Calendar.DAY_OF_WEEK) -1;
int currentMonth = RechnungMonat.cal.get (Calendar.MONTH) +1;
int currentYear = RechnungMonat.cal.get (Calendar.YEAR);
System.out.println ("Tag:" + currentDay);
System.out.println ("Wochentag:" + currentWeekDay);
System.out.println ("Monat:" + currentMonth);
System.out.println ("Jahr:" + currentYear);
if (currentWeekDay == 1) {
arrayButton[0] = new JButton (arrayString[1]);
for (int iIndex = 0; iIndex < 1; iIndex++) {
jpCenterCenterMonatCenter.add (arrayButton[iIndex]);
}
for (int iIndex = 1; iIndex < arrayButton.length; iIndex++ ) {
arrayButton[iIndex] = new JButton();
jpCenterCenterMonatCenter.add (arrayButton[iIndex]);
}
}
else if (currentWeekDay == 2) {
arrayButton[0] = new JButton (arrayString[0]);
arrayButton[1] = new JButton (arrayString[1]);
for (int iIndex = 0; iIndex < 2; iIndex++) {
jpCenterCenterMonatCenter.add (arrayButton[iIndex]);
}
for (int iIndex = 2; iIndex < arrayButton.length; iIndex++ ) {
arrayButton[iIndex] = new JButton();
jpCenterCenterMonatCenter.add (arrayButton[iIndex]);
}
}
else if (currentWeekDay == 3) {
arrayButton[0] = new JButton (arrayString[0]);
arrayButton[1] = new JButton (arrayString[0]);
arrayButton[2] = new JButton (arrayString[1]);
for (int iIndex = 0; iIndex < 3; iIndex++) {
jpCenterCenterMonatCenter.add (arrayButton[iIndex]);
}
for (int iIndex = 3; iIndex < arrayButton.length; iIndex++ ) {
arrayButton[iIndex] = new JButton();
jpCenterCenterMonatCenter.add (arrayButton[iIndex]);
}
}
else if (currentWeekDay == 4) {
arrayButton[0] = new JButton (arrayString[0]);
arrayButton[1] = new JButton (arrayString[0]);
arrayButton[2] = new JButton (arrayString[0]);
arrayButton[3] = new JButton (arrayString[1]);
for (int iIndex = 4; iIndex < 7; iIndex++) {
jpCenterCenterMonatCenter.add (arrayButton[iIndex]);
}
for (int iIndex = 4; iIndex < arrayButton.length; iIndex++ ) {
arrayButton[iIndex] = new JButton();
jpCenterCenterMonatCenter.add (arrayButton[iIndex]);
}
}
else if (currentWeekDay == 5) {
arrayButton[0] = new JButton (arrayString[0]);
arrayButton[1] = new JButton (arrayString[0]);
arrayButton[2] = new JButton (arrayString[0]);
arrayButton[3] = new JButton (arrayString[0]);
arrayButton[4] = new JButton (arrayString[1]);
for (int iIndex = 0; iIndex < 5; iIndex++) {
jpCenterCenterMonatCenter.add (arrayButton[iIndex]);
}
for (int iIndex = 5; iIndex < arrayButton.length; iIndex++ ) {
arrayButton[iIndex] = new JButton();
jpCenterCenterMonatCenter.add (arrayButton[iIndex]);
}
}
else if (currentWeekDay == 6) {
arrayButton[0] = new JButton (arrayString[0]);
arrayButton[1] = new JButton (arrayString[0]);
arrayButton[2] = new JButton (arrayString[0]);
arrayButton[3] = new JButton (arrayString[0]);
arrayButton[4] = new JButton (arrayString[0]);
arrayButton[5] = new JButton (arrayString[1]);
for (int iIndex = 0; iIndex < 6; iIndex++) {
jpCenterCenterMonatCenter.add (arrayButton[iIndex]);
}
for (int iIndex = 6; iIndex < arrayButton.length; iIndex++ ) {
arrayButton[iIndex] = new JButton();
jpCenterCenterMonatCenter.add (arrayButton[iIndex]);
}
}
else if (currentWeekDay == 0) {
arrayButton[0] = new JButton (arrayString[0]);
arrayButton[1] = new JButton (arrayString[0]);
arrayButton[2] = new JButton (arrayString[0]);
arrayButton[3] = new JButton (arrayString[0]);
arrayButton[4] = new JButton (arrayString[0]);
arrayButton[5] = new JButton (arrayString[0]);
arrayButton[6] = new JButton (arrayString[1]);
for (int iIndex = 0; iIndex < 7; iIndex++) {
jpCenterCenterMonatCenter.add (arrayButton[iIndex]);
}
for (int iIndex = 7; iIndex < arrayButton.length; iIndex++ ) {
arrayButton[iIndex] = new JButton();
jpCenterCenterMonatCenter.add (arrayButton[iIndex]);
}
for (int iIndexString = 2; iIndexString < arrayString.length; iIndexString++ ) {
for (int iIndexButton = 7; iIndexButton < arrayButton.length; iIndexButton++) {
arrayButton[iIndexButton].setText (arrayString[iIndexString]);
jpCenterCenterMonatCenter.add (arrayButton[iIndexButton]);
}
}
}
}
}
Mit diesem Code werden mir jetzt leider nur Button mit dem String 31 ausgegebn. Wenn ich diese Ausgaben in der Console ausgeben lasse, sehe ich das die Anzahl der String * der Anzahl der Buttons gerechnet werden.
Die restlichen Klassen poste ich nicht, da es viel zuviel ist, fürs Verständnis aber auch nicht nötig. Der Rest ist GUI und etlichte Zusatzfunktion, was ein Kalender halt bieten soll.
Greez AlIastor