Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Java - calendario.....come??
Forum - Java - calendario.....come??

Avatar
Il_maca (Normal User)
Rookie


Messaggi: 49
Iscritto: 19/12/2008

Segnala al moderatore
Postato alle 19:20
Domenica, 05/04/2009
ciao ragazzi!! a causa della mia poca memoria ho necessità di usare un'agenda elettronica!!
il problema è che ne ho provate tante, ma, come si sa, la migliore tra tante scelte e quella fatta da sè!! quindi mi so messo al lavoro! ma ecco i primi problemi! il CALENDARIO!! innanzi tutto per la sua visualizzazione mi consigliate una jTable??è lìunica cosa a cui ho pensato!
poi come faccio a crearlo???cioè come trovo un algoritmo adatto?? uno funzionante e semplice!! qualcosa tipo la finestra che si apre cliccando sull'ora in basso a destra di windows!!

aiutatemi!
io intanto continuo a spremere le meningi!

Ultima modifica effettuata da Il_maca il 05/04/2009 alle 20:00
PM Quote
Avatar
Il_maca (Ex-Member)
Pro


Messaggi: 163
Iscritto: 28/01/2009

Segnala al moderatore
Postato alle 20:09
Martedì, 07/04/2009
ALLORA: io fin'ora ho creato questo:
(provo a postare il codice, ma è molto lungo, se risulta illegibile posto il progetto!!)

Codice sorgente - presumibilmente Java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. /*
  7.  * Calendario.java
  8.  *
  9.  * Created on 5-apr-2009, 21.59.12
  10.  */
  11.  
  12. package Pacchetto;
  13.  
  14. /**
  15.  *
  16.  * @author Amministratore
  17.  */
  18. public class Calendario extends javax.swing.JFrame {
  19.  
  20.     /** Creates new form Calendario */
  21.     public Calendario() {
  22.         initComponents();
  23.         this.anno.setText(an1=""+an);
  24.     }
  25.  
  26.     /** This method is called from within the constructor to
  27.      * initialize the form.
  28.      * WARNING: Do NOT modify this code. The content of this method is
  29.      * always regenerated by the Form Editor.
  30.      */
  31.     @SuppressWarnings("unchecked")
  32.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  33.     private void initComponents() {
  34.  
  35.         Calendario = new javax.swing.JPanel();
  36.         mese_anno = new javax.swing.JPanel();
  37.         MESE = new javax.swing.JPanel();
  38.         Msx = new javax.swing.JButton();
  39.         mese = new javax.swing.JLabel();
  40.         Mdx = new javax.swing.JButton();
  41.         ANNO = new javax.swing.JPanel();
  42.         Asx = new javax.swing.JButton();
  43.         anno = new javax.swing.JLabel();
  44.         Adx = new javax.swing.JButton();
  45.  
  46.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  47.  
  48.         Calendario.setBackground(new java.awt.Color(255, 255, 255));
  49.  
  50.         mese_anno.setBackground(new java.awt.Color(228, 253, 228));
  51.         mese_anno.setLayout(new java.awt.GridLayout(1, 0));
  52.  
  53.         MESE.setBackground(new java.awt.Color(255, 255, 255));
  54.         MESE.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
  55.  
  56.         Msx.setText("<");
  57.         Msx.addActionListener(new java.awt.event.ActionListener() {
  58.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  59.                 MsxActionPerformed(evt);
  60.             }
  61.         });
  62.  
  63.         mese.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  64.         mese.setText("GENNAIO");
  65.  
  66.         Mdx.setText(">");
  67.         Mdx.addActionListener(new java.awt.event.ActionListener() {
  68.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  69.                 MdxActionPerformed(evt);
  70.             }
  71.         });
  72.  
  73.         javax.swing.GroupLayout MESELayout = new javax.swing.GroupLayout(MESE);
  74.         MESE.setLayout(MESELayout);
  75.         MESELayout.setHorizontalGroup(
  76.             MESELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  77.             .addGroup(MESELayout.createSequentialGroup()
  78.                 .addContainerGap()
  79.                 .addComponent(Msx)
  80.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  81.                 .addComponent(mese, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
  82.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  83.                 .addComponent(Mdx)
  84.                 .addContainerGap())
  85.         );
  86.         MESELayout.setVerticalGroup(
  87.             MESELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  88.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, MESELayout.createSequentialGroup()
  89.                 .addContainerGap(12, Short.MAX_VALUE)
  90.                 .addGroup(MESELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  91.                     .addComponent(Msx)
  92.                     .addComponent(Mdx)
  93.                     .addComponent(mese, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
  94.                 .addContainerGap())
  95.         );
  96.  
  97.         mese_anno.add(MESE);
  98.  
  99.         ANNO.setBackground(new java.awt.Color(255, 255, 255));
  100.         ANNO.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
  101.  
  102.         Asx.setText("<");
  103.         Asx.addActionListener(new java.awt.event.ActionListener() {
  104.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  105.                 AsxActionPerformed(evt);
  106.             }
  107.         });
  108.  
  109.         anno.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  110.         anno.setText("2000");
  111.  
  112.         Adx.setText(">");
  113.         Adx.addActionListener(new java.awt.event.ActionListener() {
  114.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  115.                 AdxActionPerformed(evt);
  116.             }
  117.         });
  118.  
  119.         javax.swing.GroupLayout ANNOLayout = new javax.swing.GroupLayout(ANNO);
  120.         ANNO.setLayout(ANNOLayout);
  121.         ANNOLayout.setHorizontalGroup(
  122.             ANNOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  123.             .addGroup(ANNOLayout.createSequentialGroup()
  124.                 .addContainerGap()
  125.                 .addComponent(Asx)
  126.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  127.                 .addComponent(anno, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
  128.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  129.                 .addComponent(Adx)
  130.                 .addContainerGap())
  131.         );
  132.         ANNOLayout.setVerticalGroup(
  133.             ANNOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  134.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ANNOLayout.createSequentialGroup()
  135.                 .addContainerGap(12, Short.MAX_VALUE)
  136.                 .addGroup(ANNOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  137.                     .addComponent(Asx)
  138.                     .addComponent(anno, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
  139.                     .addComponent(Adx))
  140.                 .addContainerGap())
  141.         );
  142.  
  143.         mese_anno.add(ANNO);
  144.  
  145.         javax.swing.GroupLayout CalendarioLayout = new javax.swing.GroupLayout(Calendario);
  146.         Calendario.setLayout(CalendarioLayout);
  147.         CalendarioLayout.setHorizontalGroup(
  148.             CalendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  149.             .addGroup(CalendarioLayout.createSequentialGroup()
  150.                 .addContainerGap()
  151.                 .addComponent(mese_anno, javax.swing.GroupLayout.PREFERRED_SIZE, 725, javax.swing.GroupLayout.PREFERRED_SIZE)
  152.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  153.         );
  154.         CalendarioLayout.setVerticalGroup(
  155.             CalendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  156.             .addGroup(CalendarioLayout.createSequentialGroup()
  157.                 .addContainerGap()
  158.                 .addComponent(mese_anno, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
  159.                 .addContainerGap(361, Short.MAX_VALUE))
  160.         );
  161.  
  162.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  163.         getContentPane().setLayout(layout);
  164.         layout.setHorizontalGroup(
  165.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  166.             .addComponent(Calendario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  167.         );
  168.         layout.setVerticalGroup(
  169.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  170.             .addComponent(Calendario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  171.         );
  172.  
  173.         pack();
  174.     }// </editor-fold>                        
  175.  
  176.     private void MsxActionPerformed(java.awt.event.ActionEvent evt) {                                    
  177.     if (m==0) m=11;
  178.     else m--;
  179.     this.mese.setText(mesi[m]);
  180.     con.conteggio(mesi[m], an);
  181.     System.out.println("M: " + con.M + "\nA: " + con.A + "\nC: " + con.C + "\ntot: " + con.tot);
  182.     }                                  
  183.  
  184.     private void MdxActionPerformed(java.awt.event.ActionEvent evt) {                                    
  185.     if (m==11) m=0;
  186.     else m++;
  187.     this.mese.setText(mesi[m]);
  188.     con.conteggio(mesi[m], an);
  189.     System.out.println("M: " + con.M + "\nA: " + con.A + "\nC: " + con.C + "\ntot: " + con.tot);
  190.     }                                  
  191.  
  192.     private void AsxActionPerformed(java.awt.event.ActionEvent evt) {                                    
  193.     an--;
  194.     if (an==1899) an=2100;
  195.     this.anno.setText(an1=""+an);
  196.     con.conteggio(mesi[m], an);
  197.     System.out.println("M: " + con.M + "\nA: " + con.A + "\nC: " + con.C + "\ntot: " + con.tot);
  198.     }                                  
  199.  
  200.     private void AdxActionPerformed(java.awt.event.ActionEvent evt) {                                    
  201.     an++;
  202.     if (an==2101) an=1900;
  203.     this.anno.setText(an1=""+an);
  204.     con.conteggio(mesi[m], an);
  205.     System.out.println("M: " + con.M + "\nA: " + con.A + "\nC: " + con.C + "\ntot: " + con.tot);
  206.     }                                  
  207.  
  208.     /**
  209.     * @param args the command line arguments
  210.     */
  211.     public static void main(String args[]) {
  212.         java.awt.EventQueue.invokeLater(new Runnable() {
  213.             public void run() {
  214.                 new Calendario().setVisible(true);
  215.             }
  216.         });
  217.     }
  218.  
  219.     // Variables declaration - do not modify                    
  220.     private javax.swing.JPanel ANNO;
  221.     private javax.swing.JButton Adx;
  222.     private javax.swing.JButton Asx;
  223.     private javax.swing.JPanel Calendario;
  224.     private javax.swing.JPanel MESE;
  225.     private javax.swing.JButton Mdx;
  226.     private javax.swing.JButton Msx;
  227.     private javax.swing.JLabel anno;
  228.     private javax.swing.JLabel mese;
  229.     private javax.swing.JPanel mese_anno;
  230.     // End of variables declaration                  
  231.     String giorni[] = {"Lunedì", "Martedì", "Mercoledì", "Giovedì","Venerdì", "Sabato", "Domenica"};
  232.     String mesi[] = {"GENNAIO", "FEBBRAIO", "MARZO", "APRILE","MAGGIO", "GIUGNO", "LUGLIO", "AGOSTO", "SETTEMBRE","OTTOBRE", "NOVEMBRE", "DICEMBRE"};
  233.     int DaysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  234.     int m=0,a=0;
  235.     int an=2009;String an1;
  236.     Conteggio con=new Conteggio();
  237. }




LA CLASSE INVECE é QUESTA:
Codice sorgente - presumibilmente Java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package Pacchetto;
  7.  
  8. /**
  9.  *
  10.  * @author Mariano Campanella
  11.  */
  12. public class Conteggio {
  13.      int M=0,A=0,C=0,tot=0;
  14.  
  15.  
  16.  
  17.      public int conteggio(String mese,int anno){
  18.       String mesi[] = {"GENNAIO", "FEBBRAIO", "MARZO", "APRILE","MAGGIO", "GIUGNO", "LUGLIO", "AGOSTO", "SETTEMBRE","OTTOBRE", "NOVEMBRE", "DICEMBRE"};
  19.       String an,sec;
  20.       int anno2=0,secolo=0;
  21.      
  22.       //CALCOLO DI M
  23.       if (mese.equalsIgnoreCase(mesi[0])) M=0; if (mese.equalsIgnoreCase(mesi[1])) M=3; if (mese.equalsIgnoreCase(mesi[2])) M=3; if (mese.equalsIgnoreCase(mesi[3])) M=6;
  24.       if (mese.equalsIgnoreCase(mesi[4])) M=1; if (mese.equalsIgnoreCase(mesi[5])) M=4; if (mese.equalsIgnoreCase(mesi[6])) M=6; if (mese.equalsIgnoreCase(mesi[7])) M=2;
  25.       if (mese.equalsIgnoreCase(mesi[8])) M=5; if (mese.equalsIgnoreCase(mesi[9])) M=0; if (mese.equalsIgnoreCase(mesi[10])) M=3; if (mese.equalsIgnoreCase(mesi[11])) M=5;
  26.       if (((anno % 4 == 0 && anno % 100 != 0) || anno % 400 == 0)) M++;
  27.  
  28.       //CALCOLO DI A
  29.       an=""+anno;      
  30.       an=an.substring(2);      
  31.       anno2=Integer.parseInt(an);      
  32.       A=(anno2 % 28)+(((anno2%28)-1)/4);
  33.       System.out.println(A);
  34.       //CALCOLO DI C
  35.       sec=""+anno;
  36.       sec=sec.substring(0, 2);
  37.       secolo=Integer.parseInt(sec);
  38.       C=secolo%4;
  39.       switch(C){
  40.           case 0: C=6; break;
  41.           case 1: C=4; break;
  42.           case 2: C=2; break;
  43.           case 3: C=0; break;
  44.       }
  45.  
  46.       //CALCOLO TOTALE
  47.       tot=(1+M+A+C)%7;
  48.       return tot;
  49.      }
  50.  
  51. }


PM Quote
Avatar
Il_maca (Ex-Member)
Pro


Messaggi: 163
Iscritto: 28/01/2009

Segnala al moderatore
Postato alle 20:11
Martedì, 07/04/2009
adesso mi servirebbe solamente impostare la parte grafica del calendario! ma non so cosa fare!
uso una jTable? o una serie di jlabel??
secondo voi cos'è meglio??

PM Quote
Avatar
Il_maca (Ex-Member)
Pro


Messaggi: 163
Iscritto: 28/01/2009

Segnala al moderatore
Postato alle 9:03
Mercoledì, 08/04/2009
ah cmq ho risolto tutto!! appena lo finisco lo metto nelle utility

PM Quote