Hi can I ask for some help regarding my homework.
I need to make simple calendar with the ability to add some simple events/reminders/notes to it.
I got written calendar:
Now what I would like to achieve is to click particular button with date and then open new window with simple texbox to add some note and save it.
How should I write code for clicking and opening new window?
Also should I use serialization to save those newly added notes?
I don't need any savings to file or database just simple let say array to hold let say 10 new events.
Can I ask you for some help?
I need to make simple calendar with the ability to add some simple events/reminders/notes to it.
I got written calendar:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Jakub extends Frame {
Choice miesiąc;
Choice rok;
Button dni[] = new Button[49];
Button start = new Button("Start");
Label lmiesiąc;
Label lrok;
int dzisiaj;
private static final int[] leapYearDays = { 31, 29, 31, 30, 31, 30, 31, 31,
30, 31, 30, 31 };
private static final int[] regYearDays = { 31, 28, 31, 30, 31, 30, 31, 31,
30, 31, 30, 31 };
Panel p1, p2;
GregorianCalendar gc;
public void setCal(int selMonth, int selYr) {
int selYear = selYr - 1900;
Date d1 = new Date(selYear, selMonth, 1);
int day = d1.getDay();
miesiąc.select(selMonth);
rok.select(selYear);
setVal(d1, day, selMonth, selYear);
}
private void createMonthYear() {
Font f = new Font("ScanSerif", Font.BOLD, 11);
gc = new GregorianCalendar();
miesiąc = new Choice();
rok = new Choice();
lmiesiąc = new Label("Miesiąc");
lrok = new Label("Rok");
lmiesiąc.setFont(f);
lrok.setFont(f);
miesiąc.add("Styczeń");
miesiąc.add("Luty");
miesiąc.add("Marzec");
miesiąc.add("Kwiecień");
miesiąc.add("Maj");
miesiąc.add("Czerwiec");
miesiąc.add("Lipiec");
miesiąc.add("Sierpień");
miesiąc.add("Wrzesień");
miesiąc.add("Październik");
miesiąc.add("Listopad");
miesiąc.add("Grudzień");
for (int i = 1900; i < 3000; i++) {
rok.add(String.valueOf(i));
}
rok.addItemListener(new myLis1(this));
miesiąc.addItemListener(new myLis1(this));
}
public Jakub() {
Frame f = new Frame();
setTitle("Kalendarz");
setSize(500, 500);
setResizable(false);
setLocation(50, 50);
p1 = new Panel(new FlowLayout(FlowLayout.LEFT));
p2 = new Panel(new GridLayout(7, 7, 10, 10));
p1.setBackground(Color.blue);
p2.setBackground(Color.red);
add(p1, BorderLayout.NORTH);
add(p2);
createMonthYear();
p1.add(lmiesiąc);
p1.add(miesiąc);
p1.add(new Panel());
p1.add(lrok);
p1.add(rok);
p1.add(new Panel());
p1.add(start);
start.addActionListener(new myLis(this));
for (int i = 0; i < 49; i++) {
dni[i] = new Button("");
}
for (int c = 0; c < 49; c++) {
p2.add(dni[c]);
}
setVisible(true);
Calendar rightNow = Calendar.getInstance();
int selMonth = rightNow.get(Calendar.MONTH);
int selYear1 = rightNow.get(Calendar.YEAR);
setCal(selMonth, selYear1);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
void setButtons(int myday, int mytotdays) {
int count = 7;
Font f = new Font("Helvetica", Font.BOLD, 30);
dni[0].setLabel("Pn");
dni[1].setLabel("Wt");
dni[2].setLabel("Śr");
dni[3].setLabel("Cz");
dni[4].setLabel("Pt");
dni[5].setLabel("So");
dni[6].setLabel("N");
for (int i = 0; i < 7; i++) {
dni[i].setFont(f);
}
dni[0].setForeground(Color.RED);
if (myday > 0) {
int blank = myday;
for (; blank > 0; blank--, count++) {
dni[count].setLabel("");
}
}
for (int i = 1; i <= mytotdays; i++, count++) {
dni[count].setLabel("" + i);
dni[count].setFont(f);
if (count == 7 || count == 14 || count == 21 || count == 28
|| count == 35 || count == 49)
dni[count].setForeground(Color.RED);
else
dni[count].setForeground(Color.BLACK);
}
for (int j = 1; count < 49; j++, count++) {
dni[count].setLabel("");
}
}
void setVal(Date date, int iday, int iselMonth, int iselYear) {
gc.setTime(date);
if (gc.isLeapYear(iselYear))
dzisiaj = leapYearDays[iselMonth];
else
dzisiaj = regYearDays[iselMonth];
setButtons(iday, dzisiaj);
}
static public void main(String args[]) {
Jakub c = new Jakub();
}
}
class myLis implements ActionListener {
Jakub calLis;
public myLis(Jakub c) {
calLis = c;
}
public void actionPerformed(ActionEvent i) {
int selMonth = calLis.miesiąc.getSelectedIndex();
int selYear1 = Integer.parseInt(calLis.rok.getSelectedItem());
int selYear = selYear1 - 1900;
Date d1 = new Date(selYear, selMonth, 1);
int day = d1.getDay();
calLis.setVal(d1, day, selMonth, selYear);
}
}
class myLis1 implements ItemListener {
Jakub calLis;
public myLis1(Jakub c) {
calLis = c;
}
public void itemStateChanged(ItemEvent i) {
for (int k = 7; k < 49; k++) {
calLis.dni[k].setLabel("");
}
}
}
Now what I would like to achieve is to click particular button with date and then open new window with simple texbox to add some note and save it.
How should I write code for clicking and opening new window?
Also should I use serialization to save those newly added notes?
I don't need any savings to file or database just simple let say array to hold let say 10 new events.
Can I ask you for some help?