Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package kkalendarz;
- /**
- *
- * @author Student
- */
- public class WyjatekMiesiac extends RuntimeException{
- WyjatekMiesiac(String s){
- super(s);
- }
- WyjatekMiesiac(){
- }
- }
- ////////////////
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package kkalendarz;
- /**
- *
- * @author Student
- */
- public class WyjatekDzien extends RuntimeException{
- public WyjatekDzien()
- {
- super();
- }
- public WyjatekDzien(String s){
- super(s);
- }
- }
- ////////////////
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package kkalendarz;
- public class Miesiace {
- private static Miesiac miesiace[] = {
- new Miesiac("01", 31, "Styczen"),
- new Miesiac("02", 28, "Luty"),
- new Miesiac("03", 31, "Marzec"),
- new Miesiac("04", 30, "Kwiecien"),
- new Miesiac("05", 31, "Maj"),
- new Miesiac("06", 30, "Czerwiec"),
- new Miesiac("07", 31, "Lipiec"),
- new Miesiac("08", 31, "Sierpien"),
- new Miesiac("09", 30, "Wrzesien"),
- new Miesiac("10", 31, "Pazdziernik"),
- new Miesiac("11", 30, "Listopad"),
- new Miesiac("12", 31, "Grudzien")
- //new Miesiac("02", 29, "Luty")
- };
- public static Miesiac getMiesiac( int nrMiesiaca) {
- try {
- return miesiace[nrMiesiaca - 1];
- } catch (Exception e){
- throw new WyjatekMiesiac("Wprowadzono nieprawidłowy numer miesiaca!");
- }
- }
- }
- //////////////////
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package kkalendarz;
- public class Miesiac {
- private String numerMiesiaca;
- private int liczbaDni;
- private String nazwa;
- public Miesiac(String numerMiesiaca, int liczbaDni, String nazwa) {
- this.numerMiesiaca = numerMiesiaca;
- this.liczbaDni = liczbaDni;
- this.nazwa = nazwa;
- }
- public String getNumerMiesiaca() {
- return numerMiesiaca;
- }
- public int getLiczbaDni() {
- return liczbaDni;
- }
- public String getNazwa() {
- return nazwa;
- }
- }
- //////////////////
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package kkalendarz;
- public class Kalendarzmain {
- public static void main(String[] args) throws Exception{
- try {
- Kalendarz k = new Kalendarz(2019,12,31);
- System.out.println(k.dzienTygodnia());
- System.out.println(k.toString(k.NUM));
- } catch (Exception e){
- System.out.println(e.getMessage());
- e.printStackTrace(System.out);
- }
- //System.out.println(k.getMaxday());
- }
- }
- /////////////////////
- package kkalendarz;
- public class Kalendarz {
- private int rok;
- private Miesiac miesiac;
- private int dzien;
- public static final int LONG = 753;
- public static final int MID = 951;
- public static final int NUM = 852;
- private static String[] day = {"Poniedzialek","Wtorek","Sroda","Czwartek","Piatek","Sobota","Niedziela"};
- public Kalendarz(int rok, int miesiac, int dzien) throws Exception {
- if (rok > 0){
- this.rok = rok;
- }else{
- throw new WyjatekDzien("Wprowadzono nieprawidłowy numer roku!");
- }
- if (miesiac==2 && czyPrzestepny(rok)){
- this.miesiac = new Miesiac("02", 29, "Luty");
- }else{
- this.miesiac = Miesiace.getMiesiac(miesiac);
- }
- if (dzien > 0 && dzien <= this.miesiac.getLiczbaDni()){
- this.dzien = dzien;
- }else{
- throw new WyjatekDzien("Wprowadzono nieprawidłowy dzień! - Maksymalna liczba dni dla miesiąca "+this.miesiac.getNazwa()+" to "+this.miesiac.getLiczbaDni()+".");
- }
- }
- public String toString(int format){
- switch (format){
- case 753:
- return dzien+"."+miesiac.getNazwa()+"."+rok;
- case 951:
- return dzien+"."+miesiac.getNazwa()+"/"+rok;
- case 852:
- return dzien+"/"+miesiac.getNumerMiesiaca()+"/"+rok;
- }
- return dzien+"/"+miesiac.getNumerMiesiaca()+"/"+rok;
- }
- private boolean czyPrzestepny(int rok)
- {
- return (rok % 4 == 0 && rok % 100 != 0 || rok % 400 == 0);
- }
- public String dzienTygodnia() throws Exception{
- Kalendarz pref = new Kalendarz(2018,01,01);
- int save = 0;
- //save = this.dzien - pref.dzien;
- //int roz = Integer.parseInt(this.miesiac.getNumerMiesiaca()) - Integer.parseInt(pref.miesiac.getNumerMiesiaca());
- //if compareTo
- //if (compareTo(pref) == 1){
- // int roz = this.rok - pref.rok;
- // return Integer.toString(roz);
- //}
- return Integer.toString(save);
- //return day[0];
- }
- public int compareTo(Kalendarz por){
- if (this.rok > por.rok){
- return 1;
- }
- if (this.rok < por.rok){
- return -1;
- }
- if (this.rok == por.rok){
- if (Integer.parseInt(this.miesiac.getNumerMiesiaca()) > Integer.parseInt(por.miesiac.getNumerMiesiaca())){
- return 1;
- }
- if (Integer.parseInt(this.miesiac.getNumerMiesiaca()) < Integer.parseInt(por.miesiac.getNumerMiesiaca())){
- return -1;
- }
- if (Integer.parseInt(this.miesiac.getNumerMiesiaca()) == Integer.parseInt(por.miesiac.getNumerMiesiaca())){
- if (this.dzien > por.dzien){
- return 1;
- }
- if (this.dzien > por.dzien){
- return -1;
- }
- }
- }
- return 0;
- }
- }
- ////////////////////////*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package gui;
- /**
- *
- * @author Student
- */
- public class NewJFrame extends javax.swing.JFrame {
- /**
- * Creates new form NewJFrame
- */
- public NewJFrame() {
- initComponents();
- }
- /**
- * 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() {
- jScrollBar1 = new javax.swing.JScrollBar();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- jTextArea1 = new javax.swing.JTextArea();
- jButton3 = new javax.swing.JButton();
- jButton4 = new javax.swing.JButton();
- jButton5 = new javax.swing.JButton();
- jTextField1 = new javax.swing.JTextField();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jButton1.setText("Przycisk 1");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setText("Przycisk 2");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jTextArea1.setColumns(20);
- jTextArea1.setRows(5);
- jScrollPane1.setViewportView(jTextArea1);
- jButton3.setText("W tył");
- jButton4.setText("W przód");
- jButton5.setText("OK");
- jTextField1.setText("Przesuń tydzień");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(28, 28, 28)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton3)
- .addGap(48, 48, 48)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(12, 12, 12))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addGap(32, 32, 32)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jButton4)
- .addComponent(jButton5)))
- .addGroup(layout.createSequentialGroup()
- .addGap(136, 136, 136)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap(64, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(54, 54, 54)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton5))
- .addGap(46, 46, 46)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton4)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton3))
- .addGap(15, 15, 15)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(54, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- System.out.println("Wcisnieto " + jButton1.getText());
- jButton1.setText("Przycisk 2");
- jTextArea1.setText("1");
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- System.out.println("Wcisnieto " + jButton2.getText());
- jTextArea1.setText("2");
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new NewJFrame().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JButton jButton3;
- private javax.swing.JButton jButton4;
- private javax.swing.JButton jButton5;
- private javax.swing.JScrollBar jScrollBar1;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTextArea jTextArea1;
- private javax.swing.JTextField jTextField1;
- // End of variables declaration
- }
- ////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement