Ich hab da nen kleinen Kalender in Java und wollte den als Applet in eine Seite einbinden
Nur da ich absolut keinen Schimmer von Applets habe, noch irgendwelche Selbstversuche durch Internetinformationen geglückt sind versuch mal mein Glück bei euch
Wäre nett wenn mir da einer helfen könnte.
Anbei mal mein Kalendercode
Alles anzeigen
Würd mich freuen wenn einer von euch damit was anfangen kann.. Hab schon fast kein Bock mehr *lach*


Anbei mal mein Kalendercode

Quellcode
- import java.util.Calendar;
- import java.util.GregorianCalendar;
- import javax.swing.BorderFactory;
- import javax.swing.JApplet;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.FlowLayout;
- import java.awt.Graphics;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class TEST extends JPanel {
- private static final long serialVersionUID = 1L;
- protected int yy;
- protected int mm, dd;
- protected JButton labs[][];
- protected int abstand = 0;
- Calendar kalender = new GregorianCalendar();
- protected final int thisYear = kalender.get(Calendar.YEAR);
- protected final int thisMonth = kalender.get(Calendar.MONTH);
- private JButton b0;
- private JComboBox monat;
- private JComboBox jahr;
- TEST()
- {
- super();
- setYYMMDD(kalender.get(Calendar.YEAR), kalender.get(Calendar.MONTH),
- kalender.get(Calendar.DAY_OF_MONTH));
- buildGUI();
- berechnen();
- }
- TEST(int year, int month, int today)
- {
- super();
- setYYMMDD(year, month, today);
- buildGUI();
- berechnen();
- }
- private void setYYMMDD(int year, int month, int today) {
- yy = year;
- mm = month;
- dd = today;
- }
- String[] months = { "Januar", "Februar", "Maerz", "April", "Mai", "Juni",
- "Juli", "August", "September", "Oktober", "November", "Dezember" };
- /** Dumme GUI zusammenbasteln... */
- private void buildGUI()
- {
- setBorder(BorderFactory.createEtchedBorder());
- setLayout(new BorderLayout());
- JPanel tp = new JPanel();
- tp.add(monat = new JComboBox());
- for (int i = 0; i < months.length; i++)
- {
- monat.addItem(months[i]);
- }
- monat.setSelectedItem(months[mm]);
- monat.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae)
- {
- int i = monat.getSelectedIndex();
- if (i >= 0) {
- mm = i;
- // System.out.println("Month=" + mm);
- berechnen();
- }
- }
- });
- monat.getAccessibleContext().setAccessibleName("Monat");
- monat.getAccessibleContext().setAccessibleDescription(
- "Wähle Monat aus aktuellem Jahr...");
- tp.add(jahr = new JComboBox());
- jahr.setEditable(true);
- //Hier kannste die Jahresauswahl verändern... ^^
- for (int i = yy; i < yy + 20; i++)
- {
- jahr.addItem(Integer.toString(i));
- }
- jahr.setSelectedItem(Integer.toString(yy));
- jahr.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent ae)
- {
- int i = jahr.getSelectedIndex();
- if (i >= 0) {
- yy = Integer.parseInt(jahr.getSelectedItem()
- .toString());
- // System.out.println("Year=" + yy);
- berechnen();
- }
- }
- });
- add(BorderLayout.CENTER, tp);
- JPanel bp = new JPanel();
- bp.setLayout(new GridLayout(7, 7));
- labs = new JButton[6][7]; // Erste Zeile sind die Tageesnamen...
- bp.add(b0 = new JButton("So"));
- bp.add(new JButton("Mo"));
- bp.add(new JButton("Di"));
- bp.add(new JButton("Mi"));
- bp.add(new JButton("Do"));
- bp.add(new JButton("Fr"));
- bp.add(new JButton("Sa"));
- //Die AL Methode fürs Highlighten ^^
- ActionListener dateSetter = new ActionListener() {
- public void actionPerformed(ActionEvent e)
- {
- String num = e.getActionCommand();
- if (!num.equals("")) {
- setDayActive(Integer.parseInt(num));
- }
- }
- };
- // Knöpfe baun und adden....
- for (int i = 0; i < 6; i++)
- {
- for (int j = 0; j < 7; j++)
- {
- bp.add(labs[i][j] = new JButton(""));
- labs[i][j].addActionListener(dateSetter);
- }
- }
- add(BorderLayout.NORTH, bp);
- }
- //Unterschiedliche Tage...
- public final static int dom[] = { 31, 28, 31, 30, /* jan feb mar apr */
- 31, 30, 31, 31, /* mai jun jul aug */
- 30, 31, 30, 31 /* sep okt nov dec */
- };
- /** Berechnung der Felder im Kalender... */
- protected void berechnen()
- {
- if (mm < 0 || mm > 11)
- {
- throw new IllegalArgumentException("Monat " + mm + " gibts nicht.. " +
- "Darf nur von 0-11 liegen!");
- }
- clearDayActive();
- kalender = new GregorianCalendar(yy, mm, dd);
- abstand = new GregorianCalendar(yy, mm, 1).get(Calendar.DAY_OF_WEEK) - 1;
- int daysInMonth = dom[mm];
- if (isLeap(kalender.get(Calendar.YEAR)) && mm > 1)
- ++daysInMonth;
- // Bevor der erste Tag des Monats kommt.. leer lassen!!
- for (int i = 0; i < abstand; i++)
- {
- labs[0][i].setText("");
- }
- // Nummern der Tage in die entsprechenden Felder eintragen
- for (int i = 1; i <= daysInMonth; i++)
- {
- JButton b = labs[(abstand + i - 1) / 7][(abstand + i - 1) % 7];
- b.setText(Integer.toString(i));
- }
- // 7 Tage/Woche * 6 Zeilen... usw ^^
- for (int i = abstand + 1 + daysInMonth; i < 6 * 7; i++)
- {
- labs[(i) / 7][(i) % 7].setText("");
- }
- // Hier wird der aktuelle Tag, der angeklickt ist nochmals eingefärbt..
- // Siehe AL
- if (thisYear == yy && mm == thisMonth)
- setDayActive(dd); // <--- Aktueller Tag eingefärbt
- repaint();
- }
- public boolean isLeap(int year)
- {
- if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
- return true;
- return false;
- }
- // Setzt das Jahr, Monat, und Tag
- public void setDate(int yy, int mm, int dd)
- {
- this.yy = yy;
- this.mm = mm; // startet bei 0, wie das Datum ;)
- this.dd = dd;
- berechnen();
- }
- //wird halt ausgeführt wenn Knöppe nüsch angeklickt sind T_T
- private void clearDayActive()
- {
- JButton b;
- if (activeDay > 0)
- {
- b = labs[(abstand + activeDay - 1) / 7][(abstand + activeDay - 1) % 7];
- b.setBackground(b0.getBackground());
- b.repaint();
- activeDay = -1;
- }
- }
- private int activeDay = -1;
- public void setDayActive(int newDay)
- {
- clearDayActive();
- // Den neuen Setzen.. Tag natürlich
- if (newDay <= 0)
- {
- dd = new GregorianCalendar().get(Calendar.DAY_OF_MONTH);
- }
- else
- {
- dd = newDay;
- }
- // Korrektes "Quadrat" einfärben
- Component square = labs[(abstand + newDay - 1) / 7][(abstand + newDay - 1) % 7];
- square.setBackground(Color.blue);
- square.repaint();
- activeDay = newDay;
- }
- // Testen der ganzen scheiße...
- public static void main(String[] av)
- {
- JFrame f = new JFrame("Kalenderansicht");
- Container c = f.getContentPane();
- c.setLayout(new FlowLayout());
- c.add(new TEST());
- //c.add(new TEST(2005, 3, 11));
- f.pack();
- f.setVisible(true);
- }
- }
Würd mich freuen wenn einer von euch damit was anfangen kann.. Hab schon fast kein Bock mehr *lach*
