public NavigatePanel(DatePicker parent) { this.parent = parent; setLayout(new BorderLayout()); Dimension d = new Dimension(20, 20); Box box = new Box(BoxLayout.X_AXIS); preyear = new JButton(); preyear.setToolTipText(parent.getString("pre.year", "Previous year.")); ImageIcon icon = new ImageIcon(getImage("preyear.gif"), "<<"); preyear.setIcon(icon); preyear.addActionListener(this); preyear.setPreferredSize(d); box.add(preyear); box.add(Box.createHorizontalStrut(3)); premon = new JButton(); premon.setToolTipText(parent.getString("pre.mon", "Previous Month")); icon = new ImageIcon(getImage("premon.gif"), "<"); premon.setIcon(icon); premon.addActionListener(this); premon.setPreferredSize(d); box.add(premon); add(box, BorderLayout.WEST); box = new Box(BoxLayout.X_AXIS); nextmon = new JButton(); nextmon.setToolTipText(parent.getString("next.mon", "Next month.")); icon = new ImageIcon(getImage("nextmon.gif"), ">"); nextmon.setIcon(icon); nextmon.setPreferredSize(d); nextmon.addActionListener(this); box.add(nextmon); box.add(Box.createHorizontalStrut(3)); nextyear = new JButton(); nextyear.setToolTipText(parent.getString("next.year", "Next year.")); icon = new ImageIcon(getImage("nextyear.gif"), ">>"); nextyear.setIcon(icon); nextyear.setPreferredSize(d); nextyear.addActionListener(this); box.add(nextyear); add(box, BorderLayout.EAST); setCurrentMonth(parent.calendar); // setLabel(parent.calendar); }
public void setLabel(Calendar c) { if (lbl != null) remove(lbl); lbl = new JLabel( parent.getString("month." + c.get(Calendar.MONTH), "") + ", " + c.get(Calendar.YEAR)); lbl.setHorizontalAlignment(SwingConstants.CENTER); add(lbl, BorderLayout.CENTER); }
public void actionPerformed(ActionEvent e) { Object src = e.getSource(); Calendar c = new GregorianCalendar(); c.setTime(parent.getCalendar().getTime()); if (src instanceof JButton) { if (e.getSource() == premon) c.add(Calendar.MONTH, -1); else if (e.getSource() == nextmon) c.add(Calendar.MONTH, 1); else if (e.getSource() == nextyear) c.add(Calendar.YEAR, 1); if (e.getSource() == preyear) c.add(Calendar.YEAR, -1); // System.out.println(c.getTime()); parent.updateScreen(c); } else if (src instanceof JComboBox) { JComboBox jcb = (JComboBox) src; if (src == monthBox) { c.set(Calendar.MONTH, jcb.getSelectedIndex()); } else if (e.getSource() == yearBox) { c.set(Calendar.YEAR, years[jcb.getSelectedIndex()].intValue()); setYearComboBox(c); } parent.setMonthPanel(c); parent.screen.pack(); } }
public MonthPanel(DatePicker parent, Calendar c) { this.parent = parent; GridLayout g = new GridLayout(); g.setColumns(7); g.setRows(0); this.setLayout(g); for (int i = 0; i < 7; i++) { JLabel wd = new JLabel(parent.getString("week." + i, "")); wd.setHorizontalAlignment(SwingConstants.CENTER); if (i == 0) wd.setForeground(Color.RED); else if (i == 6) wd.setForeground(Color.gray); this.add(wd); } setDaysOfMonth(c); this.setPreferredSize(new Dimension(200, 120)); }
private void setMonthComboBox(Calendar c) { if (months == null) { months = new String[12]; for (int i = 0; i < 12; i++) { String m = parent.getString("month." + i, ""); months[i] = m; } } if (monthBox == null) { monthBox = new JComboBox(); monthBox.addActionListener(this); monthBox.setFont(DatePicker.plain); monthBox.setSize(monthBox.getWidth(), height); monthBox.setPreferredSize(new Dimension(monthBox.getWidth(), height)); } monthBox.setModel(new DefaultComboBoxModel(months)); monthBox.setSelectedIndex(c.get(Calendar.MONTH)); }
public void mouseClicked(MouseEvent e) { // JOptionPane.showMessageDialog(this,getText()); parent.dayPicked(Integer.parseInt(getText())); }
public static void main(String[] argv) { DatePicker dp = new DatePicker(null); dp.start(null); }