07/04/09 18:09
Il_maca
ALLORA: io fin'ora ho creato questo:
(provo a postare il codice, ma è molto lungo, se risulta illegibile posto il progetto!!)
LA CLASSE INVECE é QUESTA:
(provo a postare il codice, ma è molto lungo, se risulta illegibile posto il progetto!!)
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * Calendario.java * * Created on 5-apr-2009, 21.59.12 */ package Pacchetto; /** * * @author Amministratore */ public class Calendario extends javax.swing.JFrame { /** Creates new form Calendario */ public Calendario() { initComponents(); this.anno.setText(an1=""+an); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { Calendario = new javax.swing.JPanel(); mese_anno = new javax.swing.JPanel(); MESE = new javax.swing.JPanel(); Msx = new javax.swing.JButton(); mese = new javax.swing.JLabel(); Mdx = new javax.swing.JButton(); ANNO = new javax.swing.JPanel(); Asx = new javax.swing.JButton(); anno = new javax.swing.JLabel(); Adx = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); Calendario.setBackground(new java.awt.Color(255, 255, 255)); mese_anno.setBackground(new java.awt.Color(228, 253, 228)); mese_anno.setLayout(new java.awt.GridLayout(1, 0)); MESE.setBackground(new java.awt.Color(255, 255, 255)); MESE.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); Msx.setText("<"); Msx.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { MsxActionPerformed(evt); } }); mese.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); mese.setText("GENNAIO"); Mdx.setText(">"); Mdx.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { MdxActionPerformed(evt); } }); javax.swing.GroupLayout MESELayout = new javax.swing.GroupLayout(MESE); MESE.setLayout(MESELayout); MESELayout.setHorizontalGroup( MESELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(MESELayout.createSequentialGroup() .addContainerGap() .addComponent(Msx) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(mese, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Mdx) .addContainerGap()) ); MESELayout.setVerticalGroup( MESELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, MESELayout.createSequentialGroup() .addContainerGap(12, Short.MAX_VALUE) .addGroup(MESELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Msx) .addComponent(Mdx) .addComponent(mese, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); mese_anno.add(MESE); ANNO.setBackground(new java.awt.Color(255, 255, 255)); ANNO.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); Asx.setText("<"); Asx.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { AsxActionPerformed(evt); } }); anno.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); anno.setText("2000"); Adx.setText(">"); Adx.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { AdxActionPerformed(evt); } }); javax.swing.GroupLayout ANNOLayout = new javax.swing.GroupLayout(ANNO); ANNO.setLayout(ANNOLayout); ANNOLayout.setHorizontalGroup( ANNOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(ANNOLayout.createSequentialGroup() .addContainerGap() .addComponent(Asx) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(anno, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Adx) .addContainerGap()) ); ANNOLayout.setVerticalGroup( ANNOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ANNOLayout.createSequentialGroup() .addContainerGap(12, Short.MAX_VALUE) .addGroup(ANNOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Asx) .addComponent(anno, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(Adx)) .addContainerGap()) ); mese_anno.add(ANNO); javax.swing.GroupLayout CalendarioLayout = new javax.swing.GroupLayout(Calendario); Calendario.setLayout(CalendarioLayout); CalendarioLayout.setHorizontalGroup( CalendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(CalendarioLayout.createSequentialGroup() .addContainerGap() .addComponent(mese_anno, javax.swing.GroupLayout.PREFERRED_SIZE, 725, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); CalendarioLayout.setVerticalGroup( CalendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(CalendarioLayout.createSequentialGroup() .addContainerGap() .addComponent(mese_anno, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(361, Short.MAX_VALUE)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(Calendario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(Calendario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pack(); }// </editor-fold> private void MsxActionPerformed(java.awt.event.ActionEvent evt) { if (m==0) m=11; else m--; this.mese.setText(mesi[m]); con.conteggio(mesi[m], an); System.out.println("M: " + con.M + "\nA: " + con.A + "\nC: " + con.C + "\ntot: " + con.tot); } private void MdxActionPerformed(java.awt.event.ActionEvent evt) { if (m==11) m=0; else m++; this.mese.setText(mesi[m]); con.conteggio(mesi[m], an); System.out.println("M: " + con.M + "\nA: " + con.A + "\nC: " + con.C + "\ntot: " + con.tot); } private void AsxActionPerformed(java.awt.event.ActionEvent evt) { an--; if (an==1899) an=2100; this.anno.setText(an1=""+an); con.conteggio(mesi[m], an); System.out.println("M: " + con.M + "\nA: " + con.A + "\nC: " + con.C + "\ntot: " + con.tot); } private void AdxActionPerformed(java.awt.event.ActionEvent evt) { an++; if (an==2101) an=1900; this.anno.setText(an1=""+an); con.conteggio(mesi[m], an); System.out.println("M: " + con.M + "\nA: " + con.A + "\nC: " + con.C + "\ntot: " + con.tot); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Calendario().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JPanel ANNO; private javax.swing.JButton Adx; private javax.swing.JButton Asx; private javax.swing.JPanel Calendario; private javax.swing.JPanel MESE; private javax.swing.JButton Mdx; private javax.swing.JButton Msx; private javax.swing.JLabel anno; private javax.swing.JLabel mese; private javax.swing.JPanel mese_anno; // End of variables declaration String giorni[] = {"Lunedì", "Martedì", "Mercoledì", "Giovedì","Venerdì", "Sabato", "Domenica"}; String mesi[] = {"GENNAIO", "FEBBRAIO", "MARZO", "APRILE","MAGGIO", "GIUGNO", "LUGLIO", "AGOSTO", "SETTEMBRE","OTTOBRE", "NOVEMBRE", "DICEMBRE"}; int DaysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int m=0,a=0; int an=2009;String an1; Conteggio con=new Conteggio(); }
LA CLASSE INVECE é QUESTA:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package Pacchetto; /** * * @author Mariano Campanella */ public class Conteggio { int M=0,A=0,C=0,tot=0; public int conteggio(String mese,int anno){ String mesi[] = {"GENNAIO", "FEBBRAIO", "MARZO", "APRILE","MAGGIO", "GIUGNO", "LUGLIO", "AGOSTO", "SETTEMBRE","OTTOBRE", "NOVEMBRE", "DICEMBRE"}; String an,sec; int anno2=0,secolo=0; //CALCOLO DI M 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; 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; 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; if (((anno % 4 == 0 && anno % 100 != 0) || anno % 400 == 0)) M++; //CALCOLO DI A an=""+anno; an=an.substring(2); anno2=Integer.parseInt(an); A=(anno2 % 28)+(((anno2%28)-1)/4); System.out.println(A); //CALCOLO DI C sec=""+anno; sec=sec.substring(0, 2); secolo=Integer.parseInt(sec); C=secolo%4; switch(C){ case 0: C=6; break; case 1: C=4; break; case 2: C=2; break; case 3: C=0; break; } //CALCOLO TOTALE tot=(1+M+A+C)%7; return tot; } }
aaa
07/04/09 18:11
Il_maca
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??
uso una jTable? o una serie di jlabel??
secondo voi cos'è meglio??
aaa