Link to home
Start Free TrialLog in
Avatar of Drop_of_Rain
Drop_of_Rain

asked on

2 classes with panels into A GUI code included

Hello everyone and thanks for all the help and support. I am lost here. I need to get the 2 first classes which are panels into the 3rd class the GUI. I know it will be simple for someone else, but i am lost and plaese help me. It is done in Java 1.6


import java.lang.String;
import javax.swing.*;
import java.util.Formatter;
import java.util.*;
import java.util.GregorianCalendar;



public class ClockPanel extends JPanel implements Runnable
{
      Thread t;
      int i;

   
    public ClockPanel() {
       initComponents();
      t = new Thread(this);
      t.start();
     JPanel dateTimeDisplayPanel;
    }


    private void initComponents() {


        timeDisplayPanel = new javax.swing.JPanel();
        timeLabel = new javax.swing.JLabel();
        hoursDisplay = new javax.swing.JLabel();
        minutesDisplay = new javax.swing.JLabel();
        secondsDisplay = new javax.swing.JLabel();
        amPmDisplay = new javax.swing.JLabel();
       
        timeDisplayPanel.setBackground(new java.awt.Color(0, 153, 153));
        timeLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        timeLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        timeLabel.setText("Time");

        hoursDisplay.setFont(new java.awt.Font("Tahoma", 0, 24));
        hoursDisplay.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        hoursDisplay.setText("00");

        minutesDisplay.setFont(new java.awt.Font("Tahoma", 0, 24));
        minutesDisplay.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        minutesDisplay.setText("00");

        secondsDisplay.setFont(new java.awt.Font("Tahoma", 0, 24));
        secondsDisplay.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        secondsDisplay.setText("00");

        amPmDisplay.setFont(new java.awt.Font("Tahoma", 0, 18));
        amPmDisplay.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        amPmDisplay.setText("AM");

        javax.swing.GroupLayout timeDisplayPanelLayout = new javax.swing.GroupLayout(timeDisplayPanel);
        timeDisplayPanel.setLayout(timeDisplayPanelLayout);
        timeDisplayPanelLayout.setHorizontalGroup(
            timeDisplayPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(timeDisplayPanelLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(timeLabel)
                .addGap(15, 15, 15)
                .addComponent(hoursDisplay)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(minutesDisplay)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(secondsDisplay)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(amPmDisplay)
                .addContainerGap(32, Short.MAX_VALUE))
        );
        timeDisplayPanelLayout.setVerticalGroup(
            timeDisplayPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, timeDisplayPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(timeDisplayPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(timeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addComponent(hoursDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(minutesDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(secondsDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(amPmDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
                        );
        dateTimeDisplayPanel.add(timeDisplayPanel);


    }

   public void run() {
        while(true) {
            //currentTimeZone = TimeZone.getDefault() ;
            clockCalendar = new GregorianCalendar();
            if(hourFormat == 24)
               currentHour = clockCalendar.get(Calendar.HOUR_OF_DAY);
            else
            currentHour = clockCalendar.get(Calendar.HOUR);
            currentMinute = clockCalendar.get(Calendar.MINUTE);
            currentSecond = clockCalendar.get(Calendar.SECOND);
          currentAmPm = clockCalendar.get(Calendar.AM_PM);
             
              hoursDisplay.setText("" + currentHour);
            minutesDisplay.setText(""  + currentMinute );
            secondsDisplay.setText(""  + currentSecond);
              
              if(Calendar.AM_PM == Calendar.AM) {
                 amPmDisplay.setText("AM");
            }
            else{
               amPmDisplay.setText("PM");
            }

            try {
                t.sleep(1000);
            } catch(InterruptedException interruptedexception) { }
        }
   
    }
    public String getHours() {
        return hoursDisplay.getText();
    }
   
    public String getMinutes() {
        return minutesDisplay.getText();
    }
   
    public String getSeconds() {
        return secondsDisplay.getText();
    }
   
   
    public String getAmPm() {
        return amPmDisplay.getText();
    }
   
   
    public void setHours(String hours) {
        hoursDisplay.setText(hours);
    }
   
    public void setMinutes(String minutes) {
        minutesDisplay.setText(minutes);
    }
   
    public void setSeconds(String seconds) {
        secondsDisplay.setText(seconds);
    }
   
   
    public void setAmPm(String amPm) {
        amPmDisplay.setText(amPm);
    }
   
       
   
    public void setTimeDisplay(String hours, String minutes, String seconds, String amPm) {
        setHours(hours);
        setMinutes(minutes);
        setSeconds(seconds);
        setAmPm(amPm);
    }
       
   
    public String getTimeDisplay() {
        return getHours() +":" + getMinutes() + ":" + getSeconds() + ":" + getAmPm();
    };
   
private JLabel listenerTF;
private int currentHour;
private int currentMinute;
private int currentSecond;
private int currentAmPm;
private Thread runner;
private GregorianCalendar clockCalendar;
private int hourFormat;
private javax.swing.JPanel timeDisplayPanel;
private javax.swing.JLabel amPmDisplay;
private javax.swing.JLabel hoursDisplay;
private javax.swing.JButton jButton1;
private javax.swing.JLabel minutesDisplay;
private javax.swing.JLabel secondsDisplay;
private javax.swing.JButton setButton;
private javax.swing.JPanel dateTimeDisplayPanel;
private javax.swing.JLabel timeLabel;  
   
}

import javax.swing.*;
import java.awt.EventQueue;
import java.text.DecimalFormat;
import java.util.*;


public class DatePanel extends JPanel implements Runnable
{
      Thread t;
      int i;
      private DecimalFormat formatter = new DecimalFormat( "00" ) ;
   
    public DatePanel() {
       initComponents();
      t = new Thread(this);
      t.start();
      JPanel dateTimeDisplayPanel;
    }


  private void initComponents() {

        dateDisplayPanel = new javax.swing.JPanel();
        dateLabel = new javax.swing.JLabel();
        monthDisplay = new javax.swing.JLabel();
        dayDisplay = new javax.swing.JLabel();
        yearDisplay = new javax.swing.JLabel();
       
        dateTimeDisplayPanel.setLayout(new java.awt.GridLayout(1, 2, 5, 5));
        dateTimeDisplayPanel.setBackground(new java.awt.Color(0, 0, 0));
        dateDisplayPanel.setBackground(new java.awt.Color(0, 153, 153));
        dateLabel.setBackground(new java.awt.Color(0, 153, 153));
        dateLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        dateLabel.setText("Date");

        monthDisplay.setFont(new java.awt.Font("Tahoma", 0, 24));
        monthDisplay.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        monthDisplay.setText("00");

        dayDisplay.setFont(new java.awt.Font("Tahoma", 0, 24));
        dayDisplay.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        dayDisplay.setText("00");

        yearDisplay.setFont(new java.awt.Font("Tahoma", 0, 24));
        yearDisplay.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        yearDisplay.setText("0000");

        javax.swing.GroupLayout dateDisplayPanelLayout = new javax.swing.GroupLayout(dateDisplayPanel);
        dateDisplayPanel.setLayout(dateDisplayPanelLayout);
        dateDisplayPanelLayout.setHorizontalGroup(
            dateDisplayPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dateDisplayPanelLayout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(dateLabel)
                .addGap(14, 14, 14)
                .addComponent(monthDisplay)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dayDisplay)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(yearDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );
        dateDisplayPanelLayout.setVerticalGroup(
            dateDisplayPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dateDisplayPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(dateDisplayPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(monthDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dayDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(yearDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dateLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        dateTimeDisplayPanel.add(dateDisplayPanel);
  }


   public void run() {
        while(true) {
            clockCalendar = new GregorianCalendar();
            currentMonth = clockCalendar.get(Calendar.MONTH);
            currentDay = clockCalendar.get(Calendar.DATE);
            currentYear = clockCalendar.get(Calendar.YEAR);
           
            monthDisplay.setText(""  + formatter.format( currentMonth ) );
            dayDisplay.setText("" + formatter.format( currentDay ) );
            yearDisplay.setText(""  + formatter.format( currentYear ) );
             
            try {
                Thread.sleep(1000);
            } catch(InterruptedException interruptedexception) { }
        }
    }
    public String getDay() {
        return dayDisplay.getText();
    }
   
    public String getMonth() {
        return monthDisplay.getText();
    }
   
    public String getYear() {
        return yearDisplay.getText();
    }
   
   
   
   
    public void setDay(String day) {
        dayDisplay.setText(day);
    }
   
    public void setMonth(String month) {
        monthDisplay.setText(month);
    }
   
    public void setYear(String year) {
        yearDisplay.setText(year);
    }
   
   
   
    public void setDateDisplay(String day, String month, String year) {
        setDay( day);
        setMonth( month);
        setYear( year);
    }
   
   
    public String getDateDisplay() {
        return getDay() +":" + getMonth() + ":" + getYear();
    }

private int currentDay;
private int currentMonth;
private int currentYear;
private Thread runner;
private GregorianCalendar clockCalendar;
private javax.swing.JLabel dateLabel;
private javax.swing.JPanel dateDisplayPanel;
private javax.swing.JPanel dateTimeDisplayPanel;        
private javax.swing.JLabel dayDisplay;
private javax.swing.JLabel monthDisplay;
private javax.swing.JLabel yearDisplay;  
   
}



import javax.swing.*;
import java.util.ArrayList;
import javax.swing.AbstractAction;
import java.awt.event.ActionEvent;
import java.awt.event.ActionEvent;
import java.lang.*;
import javax.swing.JLabel;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;


/**
 *
 * @author  HP_Owner
 */
public class GuiPanel extends javax.swing.JFrame {
enum Mode {
CLOCK, ALARM, TIMER, DATE, AUDIO, REMINDERS, CUSTOM, SETUP
};

   private java.util.List<Mode> modes;
   private int modeIndex;
   private Mode currentMode;
   boolean alarmStarted = false;
   public String alarmTime;
   private javax.swing.JLabel timeDisplay;
   public ClockPanel clockPanel = new ClockPanel();
   public DatePanel datePanel = new DatePanel();
   
   /** Creates new form GuiPanel */
public GuiPanel() {
initComponents();

//initModes();
}
   
    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
    private void initComponents() {
        PanelNamePanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        dateTimeDisplayPanel = new javax.swing.JPanel();
        modeDisplay = new javax.swing.JTextField();
        buttonPanel = new javax.swing.JPanel();
        modeButton = new javax.swing.JButton();
        okButton = new javax.swing.JButton();
        setButton = new javax.swing.JButton();
        stopButton = new javax.swing.JButton();
        recordButton = new javax.swing.JButton();
        playButton = new javax.swing.JButton();
        upButton = new javax.swing.JButton();
        downButton = new javax.swing.JButton();
        hourButton = new javax.swing.JButton();
        minutesButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        PanelNamePanel.setBackground(new java.awt.Color(0, 0, 0));
        jLabel1.setBackground(new java.awt.Color(0, 0, 0));
        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabel1.setForeground(new java.awt.Color(0, 153, 153));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Audio Remeinder Panel");

        javax.swing.GroupLayout PanelNamePanelLayout = new javax.swing.GroupLayout(PanelNamePanel);
        PanelNamePanel.setLayout(PanelNamePanelLayout);
        PanelNamePanelLayout.setHorizontalGroup(
            PanelNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelNamePanelLayout.createSequentialGroup()
                .addGap(63, 63, 63)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(42, Short.MAX_VALUE))
        );
        PanelNamePanelLayout.setVerticalGroup(
            PanelNamePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelNamePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 37, Short.MAX_VALUE)
                .addContainerGap())
        );

        dateTimeDisplayPanel.setLayout(new java.awt.GridLayout(1, 2, 5, 5));

        dateTimeDisplayPanel.setBackground(new java.awt.Color(0, 0, 0));

        modeDisplay.setBackground(new java.awt.Color(0, 0, 0));
        modeDisplay.setEditable(false);
        modeDisplay.setFont(new java.awt.Font("Tahoma", 1, 16));
        modeDisplay.setForeground(new java.awt.Color(0, 153, 153));
        modeDisplay.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        modeDisplay.setText("CLOCK");

        buttonPanel.setBackground(new java.awt.Color(255, 255, 255));
        modeButton.setBackground(new java.awt.Color(0, 0, 0));
        modeButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        modeButton.setForeground(new java.awt.Color(0, 153, 153));
        modeButton.setText("Mode");
        modeButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        modeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modeButtonevent(evt);
            }
        });

        okButton.setBackground(new java.awt.Color(0, 0, 0));
        okButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        okButton.setForeground(new java.awt.Color(0, 153, 153));
        okButton.setText("OK");
        okButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonevent(evt);
            }
        });

        setButton.setBackground(new java.awt.Color(0, 0, 0));
        setButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        setButton.setForeground(new java.awt.Color(0, 153, 153));
        setButton.setText("Set");
        setButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        stopButton.setBackground(new java.awt.Color(0, 0, 0));
        stopButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        stopButton.setForeground(new java.awt.Color(0, 153, 153));
        stopButton.setText("Stop");
        stopButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        stopButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopButtonevent(evt);
            }
        });

        recordButton.setBackground(new java.awt.Color(0, 0, 0));
        recordButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        recordButton.setForeground(new java.awt.Color(0, 153, 153));
        recordButton.setText("Record");
        recordButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        recordButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                recordButtonevent(evt);
            }
        });

        playButton.setBackground(new java.awt.Color(0, 0, 0));
        playButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        playButton.setForeground(new java.awt.Color(0, 153, 153));
        playButton.setText("Play");
        playButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        playButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                playButtonevent(evt);
            }
        });

        upButton.setBackground(new java.awt.Color(0, 0, 0));
        upButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        upButton.setForeground(new java.awt.Color(0, 153, 153));
        upButton.setText("Up");
        upButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        upButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                upButtonevent(evt);
            }
        });

        downButton.setBackground(new java.awt.Color(0, 0, 0));
        downButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        downButton.setForeground(new java.awt.Color(0, 153, 153));
        downButton.setText("Down");
        downButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        downButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                downButtonevent(evt);
            }
        });

        hourButton.setBackground(new java.awt.Color(0, 0, 0));
        hourButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        hourButton.setForeground(new java.awt.Color(0, 153, 153));
        hourButton.setText("Hour");
        hourButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        hourButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hourButtonevent(evt);
            }
        });

        minutesButton.setBackground(new java.awt.Color(0, 0, 0));
        minutesButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        minutesButton.setForeground(new java.awt.Color(0, 153, 153));
        minutesButton.setText("Minutes");
        minutesButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        minutesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                minutesButtonevent(evt);
            }
        });

        javax.swing.GroupLayout buttonPanelLayout = new javax.swing.GroupLayout(buttonPanel);
        buttonPanel.setLayout(buttonPanelLayout);
        buttonPanelLayout.setHorizontalGroup(
            buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(buttonPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(buttonPanelLayout.createSequentialGroup()
                        .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(stopButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(minutesButton))
                    .addGroup(buttonPanelLayout.createSequentialGroup()
                        .addComponent(modeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(setButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(hourButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(buttonPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(playButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(buttonPanelLayout.createSequentialGroup()
                        .addComponent(recordButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        buttonPanelLayout.setVerticalGroup(
            buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(buttonPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(setButton, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(hourButton, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(recordButton, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(modeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17)
                .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(playButton, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(minutesButton, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(stopButton, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(dateTimeDisplayPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 459, Short.MAX_VALUE)
                    .addComponent(PanelNamePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(modeDisplay, javax.swing.GroupLayout.DEFAULT_SIZE, 459, Short.MAX_VALUE)
                    .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(PanelNamePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dateTimeDisplayPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(modeDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>                        

    private void downButtonevent(java.awt.event.ActionEvent evt) {                                
// TODO add your handling code here:
    }                                

    private void upButtonevent(java.awt.event.ActionEvent evt) {                              
// TODO add your handling code here:
    }                              

    private void playButtonevent(java.awt.event.ActionEvent evt) {                                
// TODO add your handling code here:
    }                                

    private void recordButtonevent(java.awt.event.ActionEvent evt) {                                  
// TODO add your handling code here:
    }                                  

    private void stopButtonevent(java.awt.event.ActionEvent evt) {                                
// TODO add your handling code here:
    }                                

    private void hourButtonevent(java.awt.event.ActionEvent evt) {                                
// TODO add your handling code here:
    }                                

    private void minutesButtonevent(java.awt.event.ActionEvent evt) {                                    
// TODO add your handling code here:
    }                                  

    private void okButtonevent(java.awt.event.ActionEvent evt) {                              
// TODO add your handling code here:
    }                              

    private void modeButtonevent(java.awt.event.ActionEvent evt) {                                
// TODO add your handling code here:
    }                                
   
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GuiPanel().setVisible(true);
            }
        });
    }
   
    // Variables declaration - do not modify                    
    private javax.swing.JPanel PanelNamePanel;
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JPanel dateTimeDisplayPanel;
    private javax.swing.JButton downButton;
    private javax.swing.JButton hourButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton minutesButton;
    private javax.swing.JButton modeButton;
    private javax.swing.JTextField modeDisplay;
    private javax.swing.JButton okButton;
    private javax.swing.JButton playButton;
    private javax.swing.JButton recordButton;
    private javax.swing.JButton setButton;
    private javax.swing.JButton stopButton;
    private javax.swing.JButton upButton;
    // End of variables declaration                  
   
}
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Drop_of_Rain
Drop_of_Rain

ASKER

But won't that cause 2 panels to be created?
yes. But looking at your code thats what u need. You set the layout in each class and add lots of components.
If you want them to a share the same panel then you'll need to pass each class a reference to the shared panel, either in the constructor or via a setter.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
dateTimeDisplayPanel  has a gridLayout with 2 colums and 1 row with 5 as the amount for spacing. So they do sahre 1 panel. The code from the layout sould have that info in it since that was the way I laid it out. So is what is need is something like this:

    public ClockPanel(GuiPanel guiPanel, DatePanel datePanel)
    {
 
        this.guiPanel = guiPanel;
        private final GuiPanel guiPanel;
        private final DateiPanel datePanel;
        private DatePanel datePanel = new DatePanel();
    }

     guiPanel.addComponent(dateTimeDisplayPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 459, Short.MAX_VALUE)

This wat onlt 1 panel is created and the second class can just be placed in the layout. What do you think?
I added the above code to both the clock and date classes and then added the code below, but still get the same error message.

 this.dateTimeDisplayPanel.add(dateDisplayPanel);
I'm trying to get it to work, here is my last try. I think i took care of the last error, but you can't tell sometimes. Both of these classes compile, the errors come when i thry to run the GuiPanel class.

C:\Documents and Settings\HP_Owner\Reminder\src\my\reminder\GuiPanel.java:35: cannot find symbol
symbol  : constructor ClockPanel()

location: class my.reminder.ClockPanel
   ClockPanel clockPanel = new ClockPanel();

C:\Documents and Settings\HP_Owner\Reminder\src\my\reminder\GuiPanel.java:36: cannot find symbol
symbol  : constructor DatePanel()

location: class my.reminder.DatePanel
   DatePanel datePanel = new DatePanel();




public class DatePanel extends JPanel implements Runnable
{
      Thread t;
      int i;
      private DecimalFormat formatter = new DecimalFormat( "00" ) ;
   
    public DatePanel(ClockPanel clockPanel) {
       this.dateTimeDisplayPanel = dateTimeDisplayPanel;
        initComponents();
      t = new Thread(this);
      t.start();
     
    }


  private void initComponents() {

        dateDisplayPanel = new javax.swing.JPanel();

public class ClockPanel extends JPanel implements Runnable
{
        public final GuiPanel guiPanel;
        public final DatePanel datePanel;

        Thread t;
        int i;

   public ClockPanel(GuiPanel guiPanel, DatePanel datePanel) {
       
     
      this.datePanel = datePanel;
      this.guiPanel = guiPanel;
      this.dateTimeDisplayPanel = dateTimeDisplayPanel;
      initComponents();
      t = new Thread(this);
      t.start();
     
    }
   
    private void initComponents() {


        this.dateTimeDisplayPanel = dateTimeDisplayPanel;
you'll also need to change where u create the ClockPanel and pass it the necessary paramertrs.

...
   public ClockPanel clockPanel = null;
   public DatePanel datePanel = null;
   
   /** Creates new form GuiPanel */
public GuiPanel() {
initComponents();

//initModes();
}
   
    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
    private void initComponents() {
        PanelNamePanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        dateTimeDisplayPanel = new javax.swing.JPanel();  
        clockPanel = new ClockPanel(dateTimeDisplayPanel);
        datePanel = new DatePanel(dateTimeDisplayPanel);

        ...
Not clear where that code goes.
thats copied from your existing code incuding the necesary changes
iw. it replaces what u curreently have
Ok this time the gui came up just no clock or date panels. What if we imported the Container.ContentPane from the GuiPanel then we would know it is in the class  

Container contentPane = getContentPane();  //  what is wrong with this code? by the way
I can see this isn't a easy problem.
I can't see anywhere that u add either the clock or date panel to your gui.
A component will not display unless it is added to the gui hierarchy.
What if we got the contentPane into the class then we could use it to add the panels.

Container contentPane = frame.getContentPane();

contentPane().addComponent(datePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

contentPane().addComponent(timePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE))
you're doing things a little bit back to front. A component subclass is easier to manage if it just adds any child components to itself, does not add itself or anyother components to elsewhere in the hierarchy.
This way the component stays more self contained and easy to manage.
I think it would be easier to just move the clock and date code to the GuiPanel class in a inner class and then use outer classes to do everything else.
You don't need an inner class for that.  you might as well just get rid of those classes altogether then and put the code directly in the GuiPanel class.

Why wouldn't it be easier to just add the TimePanel panel in the GuiPanel class?
I would know how to add to runs in inner classes but not otherwise. I'm already going this way
Here are the 2 inner classes i came up with. I transfered all the variables and imports ti the GuiPanle already.  

private class Date implements Runnable
  {

      Thread t;
      int i;
      private DecimalFormat formatter = new DecimalFormat( "00" ) ;
   
    public Date() {

      t = new Thread(this);
      t.start();
     
    }

     public void run() {
        while(true) {
            clockCalendar = new GregorianCalendar();
            currentMonth = clockCalendar.get(Calendar.MONTH);
            currentDay = clockCalendar.get(Calendar.DATE);
            currentYear = clockCalendar.get(Calendar.YEAR);
           
            monthDisplay.setText(""  + formatter.format( currentMonth ) );
            dayDisplay.setText("" + formatter.format( currentDay ) );
            yearDisplay.setText(""  + formatter.format( currentYear ) );
             
            try {
                Thread.sleep(1000);
            } catch(InterruptedException interruptedexception) { }
        }
 
      }



  }






  private Class CLock Implements Runnable
  {
        Thread t;
        int i;

   
     public Clock() {
       
      private DecimalFormat formatter = new DecimalFormat( "00" ) ;
      t = new Thread(this);
      t.start();
     }

   

     public void run() {
         while(true) {
            //currentTimeZone = TimeZone.getDefault() ;
            clockCalendar = new GregorianCalendar();
            if(hourFormat == 24)
               currentHour = clockCalendar.get(Calendar.HOUR_OF_DAY);
            else
            currentHour = clockCalendar.get(Calendar.HOUR);
            currentMinute = clockCalendar.get(Calendar.MINUTE);
            currentSecond = clockCalendar.get(Calendar.SECOND);
          currentAmPm = clockCalendar.get(Calendar.AM_PM);
             
              hoursDisplay.setText("" + formatter.format( currentHour) );
            minutesDisplay.setText(""   + formatter.format( currentMinute) );
            secondsDisplay.setText(""   + formatter.format( currentSecond) );
              
              if(Calendar.AM_PM == Calendar.AM) {
                 amPmDisplay.setText("AM");
            }
            else{
               amPmDisplay.setText("PM");
            }

            try {
                t.sleep(1000);
            } catch(InterruptedException interruptedexception) { }
          }
   
      }
   
  }