Question

editing formated time, hours and minutes

Asked by: Drop_of_Rain

How could I be able to edit the hours and minutes with JButtons one for hours, one for minutes which will activate those formating areas and up and down buttons to advance and decrease the numbers.
public void run()
   {

      String s;
      while (true)
      {
                  Calendar c = Calendar.getInstance();
                  StringBuilder builder = new StringBuilder();
                  Formatter formatter = new Formatter(builder);
                  formatter.format("%02d:%02d:%02d", c.get(Calendar.HOUR), c.get(Calendar.MINUTE), c.get(Calendar.SECOND));
                  formatter.flush();
                  s = builder.toString();
         try
         {
            t.sleep(1000);
         }
         catch (Exception e)
         {
         }
         time.setText(" " + s);
         listenerTF.setText(time.getText());
      }
   }

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-07-07 at 19:35:36ID22681491
Tags

minutes

,

hour

Topics

Java Standard Edition

,

New to Java Programming

Participating Experts
2
Points
500
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Date,Hour,Minute
    I have this date problem. As I have a functiom which allows the customer to choose the next appointment. There is a calendar to let customer to choose date, a drop down list box to choose hour (24 hour format, from 00 to 23), a drop down list box to choose minute (five minute...
  2. JButton
    How do I set a flag/status to a JButton and how do I read the status after a mouse click... for example JButton[][] mybutton = new JButton[][]; mybutton[x][y] = new JButton(); mybutton[x][y] = ? add(mybutton[x][y]); Thanks
  3. stringbuilder efficiency
    This question has two parts. I have a number of "controls" that build html strings from data for display in a browser. I use as stringBuilder for efficency. The default Capacity for a stringbuilder is only 16 and when you go over this the memory is re-allocated and ...
  4. Convert seconds to hours:minute:second
    Hi, Would like to convert seconds to hours:minutes:seconds as such that 1 second = 00:00:01. Thanks, Yama

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: StillUnAwarePosted on 2007-07-08 at 03:15:07ID: 19439611

Here is a little sample, which will do what You want:

import javax.swing.*;

public class DateSpinner {
  public static void main(String args[]) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JSpinner spinner = new JSpinner(new SpinnerDateModel());
    spinner.setEditor(new JSpinner.DateEditor(spinner, "yyyy.MM.dd"));
    f.add(spinner);
    f.pack();
    f.setVisible(true);
  }
}

Of course there are a lot more options.

 

by: Drop_of_RainPosted on 2007-07-08 at 04:04:57ID: 19439677

Thanks but that won't work. I already have the gui coded here is an older version of it: I need to be able to use the existing buttons.

http://www.experts-exchange.com/Programming/Languages/Java/J2SE/Q_22678365.html

 

by: Drop_of_RainPosted on 2007-07-10 at 22:14:12ID: 19460016

I have thought of using a a window like a popup to just set the time, but I would like to have it be done through the GUI.

 

by: Drop_of_RainPosted on 2007-07-10 at 22:27:13ID: 19460057

I found this class out there, but I don't know how to just edit the hour, minutes in the same JTextField that you will see in the code I supplied in the referred question above for the GUI  


private class TimeResetter extends JPanel
   {
      private Listener listener = new Listener();
      private JTextField hour, minute, second;

      public TimeResetter(long initialTime)
      { // constructor
         setLayout(new GridLayout(1, 5, 0, 0)); // 1 row, 5 "columns"

         String initH = String.format("%2d", initialTime / 3600);
         hour = new JTextField(initH, 2);
         add(hour);

         add(new JLabel(":", JLabel.CENTER));
         String initM = String.format("%02d", (initialTime % 3600) / 60);
         minute = new JTextField(initM, 2);
         add(minute);

         String initS = String.format("%02d", initialTime % 60);
         add(new JLabel(":", JLabel.CENTER));
         second = new JTextField(initS, 2);
         add(second);

         hour.addActionListener(listener);
         minute.addActionListener(listener);
         second.addActionListener(listener);
      }
     
      private class Listener implements ActionListener
      {
         public void actionPerformed(ActionEvent e)
         {
            int h, m, s;
            try
            {
               h = Integer.parseInt(hour.getText().trim());
            }
            catch (NumberFormatException nfe)
            {
               blink(hour);
               return;
            }
            if (h < 0 || h > 23)
            {
               blink(hour);
               return;
            }

            try
            {
               m = Integer.parseInt(minute.getText().trim());
            }
            catch (NumberFormatException nfe)
            {
               blink(minute);
               return;
            }
            if (m < 0 || m > 59)
            {
               blink(minute);
               return;
            }

            try
            {
               s = Integer.parseInt(second.getText().trim());
            }
            catch (NumberFormatException nfe)
            {
               blink(second);
               return;
            }
            if (s < 0 || s > 59)
            {
               blink(second);
               return;
            }

            counter.set(h * 3600 + m * 60 + s);
         }
         
         private void blink(JTextField f)
         {
            Graphics g = getGraphics();
            for (int i = 0; i < 3; i++)
            {
               f.setVisible(false);
               update(g);
               try
               {
                  Thread.sleep(300);
               }
               catch (InterruptedException e)
               {
               }
               f.setVisible(true);
               update(g);
               try
               {
                  Thread.sleep(300);
               }
               catch (InterruptedException e)
               {
               }
            }
         }
      }

   }

 

by: keyurkarnikPosted on 2007-07-11 at 03:46:41ID: 19461206

I have added pseudo code where you need to actually parse the string and update the hour and minut fields.
Check the rest. Changes have been done to both the classes :


import java.awt.event.ActionEvent;

import javax.swing.JLabel;


public class GuiPanel extends javax.swing.JFrame
{
   enum Mode {
      Alarm, Timer, Clock, Date, Audio
   };

   private java.util.List<Mode> modes;
   private int modeIndex;
   private Mode currentMode;
   boolean alarmStarted = false;
   public String alarmTime;
   //   private/** Creates new form GuiPanel */
   public GuiPanel()
   {
      initComponents();
      initModes();
   }


   private void initModes()
   {
      modes = new java.util.ArrayList<Mode>();
      for (Mode m : Mode.values())
      {
         modes.add(m);
      }
      modeButton.setAction(new AdvanceModeAction("Mode"));
   }

   private class AdvanceModeAction extends javax.swing.AbstractAction
   {
      public AdvanceModeAction(String name)
      {
         super(name);
      }

      public void actionPerformed(java.awt.event.ActionEvent e)
      {
         advanceMode();
         modeDisplay.setText(currentMode.toString());

         enableAllButtons();

         if (currentMode == Mode.Alarm)
         {
            recordButton.setEnabled(false);
            playButton.setEnabled(false);
            stopButton.setEnabled(false);
            fastButton.setEnabled(false);

            alarmTempDisplay = new JLabel(timeDisplay.getText());
            alarmStarted = false;
            dispProv.setDispListener(alarmTempDisplay);
         }
         else if (currentMode == Mode.Audio)
         {
            hourButton.setEnabled(false);
            minutesButton.setEnabled(false);

         }
         else if (currentMode == Mode.Clock)
         {
            recordButton.setEnabled(false);
            playButton.setEnabled(false);
            stopButton.setEnabled(false);
         }
         else if (currentMode == Mode.Date)
         {
            recordButton.setEnabled(false);
            playButton.setEnabled(false);
            stopButton.setEnabled(false);
         }
         else if (currentMode == Mode.Timer)
         {
            recordButton.setEnabled(false);
            playButton.setEnabled(false);
            stopButton.setEnabled(false);
            dispProv.setDispListener(timeDisplay);
         }


      }
   }

   private class AlarmButtonSelectAction extends javax.swing.AbstractAction
   {
      public final int HR = 0;
      public final int MIN = 1;

      int selected = -1;

      public void actionPerformed(ActionEvent e)
      {
         String cmd = e.getActionCommand();
         if (currentMode == Mode.Alarm)
         {
            if (cmd.equals(hourButton.getText()))
            {
               selected = HR;
            }
            else if (cmd.equals(minutesButton.getText()))
            {
               selected = MIN;
            }
            else if (cmd.equals(upButton.getText()))
            {
               if (selected == HR)
               {
                  String time = timeDisplay.getText();
                  //start incrementing for the hour field in alarmDisplay
                  //by manually parsing and modifying
                  timeDisplay.setText(time); //modified time
               }
               else if (selected == MIN)
               {
                  String time = timeDisplay.getText();
                  //start incrementing the minute field
                  //by manually parsing and modifying
                  timeDisplay.setText(time); //modified time
               }
            }
            else if (cmd.equals(downButton.getText()))
            {
               if (selected == HR)
               {
                  String time = timeDisplay.getText();
                  //start incrementing for the hour field in alarmDisplay
                  //by manually parsing and modifying
                  timeDisplay.setText(time); //modified time
               }
               else if (selected == MIN)
               {
                  String time = timeDisplay.getText();
                  //start incrementing the minute field
                  //by manually parsing and modifying
                  timeDisplay.setText(time); //modified time
               }
            }
            else if (cmd.equals(okButton.getText()))
            {
               //time should be stored in alarmDisplay
               alarmStarted = true;
               alarmTime = timeDisplay.getText();
               selected = -1;
            }
         }
      }

   }


   private void enableAllButtons()
   {
      downButton.setEnabled(true);
      fastButton.setEnabled(true);
      hourButton.setEnabled(true);
      minutesButton.setEnabled(true);
      modeButton.setEnabled(true);
      okButton.setEnabled(true);
      playButton.setEnabled(true);
      recordButton.setEnabled(true);
      stopButton.setEnabled(true);
      upButton.setEnabled(true);
   }

   private void advanceMode()
   {
      currentMode = modes.get(modeIndex++ % modes.size());
   }


   /** 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()
   {
      jPanel1 = new javax.swing.JPanel();
      jLabel1 = new javax.swing.JLabel();
      timeDisplay = new javax.swing.JLabel();
      jPanel2 = new javax.swing.JPanel();
      modeDisplay = new javax.swing.JTextField();
      jPanel3 = new javax.swing.JPanel();
      modeButton = new javax.swing.JButton();
      okButton = new javax.swing.JButton();
      hourButton = new javax.swing.JButton();
      minutesButton = new javax.swing.JButton();
      recordButton = new javax.swing.JButton();
      playButton = new javax.swing.JButton();
      fastButton = new javax.swing.JButton();
      stopButton = new javax.swing.JButton();
      upButton = new javax.swing.JButton();
      downButton = new javax.swing.JButton();
     
      AlarmButtonSelectAction alarmButtonSelectAction = new AlarmButtonSelectAction();

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
      setResizable(false);
      jPanel1.setBackground(new java.awt.Color(255, 255, 255));
      jLabel1.setFont(new java.awt.Font("Tahoma", 2, 18));
      jLabel1.setForeground(new java.awt.Color(51, 51, 255));
      jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      jLabel1.setText("Audio Reminder Panel");

      timeDisplay.setFont(new java.awt.Font("Tahoma", 0, 36));
      timeDisplay.setForeground(new java.awt.Color(204, 0, 0));
      timeDisplay.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      timeDisplay.setText("00:00:00");

      javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
      jPanel1.setLayout(jPanel1Layout);
      jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(timeDisplay, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE).addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE));
      jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(timeDisplay, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE).addContainerGap()));

      jPanel2.setBackground(new java.awt.Color(0, 0, 0));
      modeDisplay.setBackground(new java.awt.Color(255, 255, 255));
      modeDisplay.setEditable(false);
      modeDisplay.setFont(new java.awt.Font("Tahoma", 1, 12));
      modeDisplay.setHorizontalAlignment(javax.swing.JTextField.CENTER);

      javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
      jPanel2.setLayout(jPanel2Layout);
      jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel2Layout.createSequentialGroup().addGap(152, 152, 152).addComponent(modeDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap(158, Short.MAX_VALUE)));
      jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(modeDisplay, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE));

      jPanel3.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, 11));
      modeButton.setForeground(new java.awt.Color(255, 255, 255));
      modeButton.setText("Mode");
      modeButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });

      okButton.setBackground(new java.awt.Color(0, 0, 0));
      okButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      okButton.setForeground(new java.awt.Color(255, 255, 255));
      okButton.setText("OK");
      okButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });
      okButton.addActionListener(alarmButtonSelectAction);

      hourButton.setBackground(new java.awt.Color(0, 0, 0));
      hourButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      hourButton.setForeground(new java.awt.Color(255, 255, 255));
      hourButton.setText("Hour");
      hourButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });
      hourButton.addActionListener(alarmButtonSelectAction);

      minutesButton.setBackground(new java.awt.Color(0, 0, 0));
      minutesButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      minutesButton.setForeground(new java.awt.Color(255, 255, 255));
      minutesButton.setText("Minutes");
      minutesButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });
      minutesButton.addActionListener(alarmButtonSelectAction);

      recordButton.setBackground(new java.awt.Color(0, 0, 0));
      recordButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      recordButton.setForeground(new java.awt.Color(255, 255, 255));
      recordButton.setText("Record");
      recordButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });

      playButton.setBackground(new java.awt.Color(0, 0, 0));
      playButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      playButton.setForeground(new java.awt.Color(255, 255, 255));
      playButton.setText("Play");
      playButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });

      fastButton.setBackground(new java.awt.Color(0, 0, 0));
      fastButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      fastButton.setForeground(new java.awt.Color(255, 255, 255));
      fastButton.setText("Fast");
      fastButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });

      stopButton.setBackground(new java.awt.Color(0, 0, 0));
      stopButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      stopButton.setForeground(new java.awt.Color(255, 255, 255));
      stopButton.setText("Stop");
      stopButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });

      upButton.setBackground(new java.awt.Color(0, 0, 0));
      upButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      upButton.setForeground(new java.awt.Color(255, 255, 255));
      upButton.setText("Up");
      upButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });
      upButton.addActionListener(alarmButtonSelectAction);

      downButton.setBackground(new java.awt.Color(0, 0, 0));
      downButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      downButton.setForeground(new java.awt.Color(255, 255, 255));
      downButton.setText("Down");
      downButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });
      downButton.addActionListener(alarmButtonSelectAction);

      javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
      jPanel3.setLayout(jPanel3Layout);
      jPanel3Layout.setHorizontalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel3Layout.createSequentialGroup().addComponent(modeButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(hourButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(recordButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(fastButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(upButton)).addGroup(jPanel3Layout.createSequentialGroup().addComponent(okButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(minutesButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(playButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(stopButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(downButton))).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

      jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[]{downButton, fastButton, hourButton, minutesButton, modeButton, okButton, playButton, recordButton, stopButton, upButton});

      jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(modeButton).addComponent(fastButton).addComponent(upButton).addComponent(recordButton).addComponent(hourButton, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE).addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(okButton).addComponent(minutesButton).addComponent(playButton).addComponent(stopButton).addComponent(downButton)).addGap(19, 19, 19)));

      jPanel3Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[]{downButton, fastButton, minutesButton, modeButton, okButton, playButton, recordButton, stopButton, upButton});

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addContainerGap()));
      layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(14, 14, 14).addComponent(jPanel3, 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 event(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.JButton downButton;
   private javax.swing.JButton fastButton;
   private javax.swing.JButton hourButton;
   private javax.swing.JLabel jLabel1;
   private javax.swing.JPanel jPanel1;
   private javax.swing.JPanel jPanel2;
   private javax.swing.JPanel jPanel3;
   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 stopButton;
   private javax.swing.JLabel timeDisplay;
   private javax.swing.JButton upButton;
   private JLabel alarmTempDisplay;
   // End of variables declaration                  
   public javax.swing.JLabel getTimeDisplay()
   {
      return timeDisplay;
   }

   public void setTimeDisplay(javax.swing.JLabel timeDisplay)
   {
      this.timeDisplay = timeDisplay;
   }


   /**
    * @param prn
    */
   public void setDispProvider(DispTime prn)
   {
      dispProv = prn;
   }

   private DispTime dispProv;

}



















import java.util.Calendar;
import java.util.Formatter;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

      public class DispTime extends JFrame implements Runnable
{
   Calendar calendar;
   int i;
   JTextField time;
   Thread t;
 
   DispTime()
   {
      time = new JTextField();
      time.setEditable(false);
      t = new Thread(this);
      t.start();
   }


   public void run()
   {
      String s;
      while (true)
      {
                  Calendar c = Calendar.getInstance();
                  StringBuilder builder = new StringBuilder();
                  Formatter formatter = new Formatter(builder);
                  formatter.format("%02d:%02d:%02d", c.get(Calendar.HOUR), c.get(Calendar.MINUTE), c.get(Calendar.SECOND));
                  formatter.flush();
                  s = builder.toString();
         try
         {
            t.sleep(1000);
         }
         catch (Exception e)
         {
         }
         time.setText(" " + s);
         listenerTF.setText(time.getText());
      }
   }


   public static void main(String[] args)
   {
     
      final DispTime PRN = new DispTime();
      final GuiPanel gp = new GuiPanel();
      PRN.setDispListener(gp.getTimeDisplay());
      gp.setDispProvider(PRN);

      java.awt.EventQueue.invokeLater(new Runnable()
      {
         public void run()
         {
            gp.setVisible(true);
         }
      });

   }


   /**
    * @param timeDisplay
    */
   public void setDispListener(JLabel timeDisplay)
   {
      this.listenerTF = timeDisplay;
   }
   
   private JLabel listenerTF;
}

 

by: keyurkarnikPosted on 2007-07-11 at 03:50:56ID: 19461225

Now, when you click on alarm, the clock will stop, and you should be able to edit the hour and minute.
[Make sure you write hte code where I have added the comments in the GuiPanel.AlarmButtonSelectAction.]

when finally ok is clicked, the alarm time will get stored in a string called as alarmTime. Yo can use that where reqd.

When the mode is set to Timer again, normal process starts.

You can change the code around and add some more behaviour for the other modes

 

by: Drop_of_RainPosted on 2007-07-11 at 07:08:06ID: 19462752

Thanks I though I had to access the text in the formatter and that stopped my thinking process. I see the way you coded it, very  nice! You keep it nice and simple, you are a good teacher. Sorry for having to ask so much from you, you get learn in the process of helping us though. This requires a new open way of thinking which takes time to learn. Thanks again for your help.

 

by: keyurkarnikPosted on 2007-07-11 at 23:55:18ID: 19469358

Glad to be of help!

 

by: Drop_of_RainPosted on 2007-07-12 at 07:31:08ID: 19472076

Could you help me with this question. Most of the code is there.

http://www.experts-exchange.com/Programming/Languages/Java/J2SE/Q_22689088.html

 

by: keyurkarnikPosted on 2007-07-12 at 07:51:49ID: 19472347

paste in your main method there - i will give u a solution soon.

put in everything - the whole code and the code you use to test.

 

by: Drop_of_RainPosted on 2007-07-12 at 13:18:37ID: 19475806

I though I did this right but it don't work, what did i do wrong?

private class AlarmButtonSelectAction extends javax.swing.AbstractAction
   {
      public final int HR = 0;
      public final int MIN = 1;

      int selected = -1;

      public void actionPerformed(ActionEvent e)
      {
         String cmd = e.getActionCommand();
         if (currentMode == Mode.Alarm)
         {
            if (cmd.equals(hourButton.getText()))
            {
               selected = HR;
            }
            else if (cmd.equals(minutesButton.getText()))
            {
               selected = MIN;
            }
            else if (cmd.equals(upButton.getText()))
            {
               if (selected == HR)
               {
                  String time = timeDisplay.getText();
                  int HR=Integer.parseInt(time);
                  HR = HR + 1;
                  timeDisplay.setText(time); //modified time
               }
               else if (selected == MIN)
               {
                  String time = timeDisplay.getText();
                  int MIN=Integer.parseInt(time);
                  MIN = MIN + 1;
                  timeDisplay.setText(time); //modified time
               }
            }
            else if (cmd.equals(downButton.getText()))
            {
               if (selected == HR)
               {
                  String time = timeDisplay.getText();
                  int HR=Integer.parseInt(time);
                  HR = HR - 1;
                  timeDisplay.setText(time); //modified time
               }
               else if (selected == MIN)
               {
                  String time = timeDisplay.getText();
                  int MIN=Integer.parseInt(time);
                  MIN = MIN - 1;
                  timeDisplay.setText(time); //modified time
               }
            }
            else if (cmd.equals(okButton.getText()))
            {
               //time should be stored in alarmDisplay
               alarmStarted = true;
               alarmTime = timeDisplay.getText();
               selected = -1;
            }
         }
      }

   }

 

by: keyurkarnikPosted on 2007-07-12 at 23:25:23ID: 19478581

that is totally WRONG!!!

the HR and MIN are indicators for what button has been selected (if Hour is selected, then selected = HR) I have made HR and MIN final - how are you changing it??


secondly, the 'time' String is in HH:MM:SS format. So Integer.parseInt(time) will throw a number format exception.

You need to split the time String into 3 parts : HH, MM and SS
then in the HR case, you increase the HH part and reconstruct the String to HH:MM:SS


it would be somthing like :

private class AlarmButtonSelectAction extends javax.swing.AbstractAction
   {
      public final int HR = 0;
      public final int MIN = 1;

      int selected = -1;

      public void actionPerformed(ActionEvent e)
      {
         String cmd = e.getActionCommand();
         if (currentMode == Mode.Alarm)
         {
            if (cmd.equals(hourButton.getText()))
            {
               selected = HR;
            }
            else if (cmd.equals(minutesButton.getText()))
            {
               selected = MIN;
            }
            else if (cmd.equals(upButton.getText()))
            {
               if (selected == HR)
               {
                  String time = timeDisplay.getText();
                  String[] splitTime = time.split(":");

                  int hr = Integer.parseInt(splitTime[0].trim());
                  time = Integer.toString(hr + 1) + ":" + splitTime[1] + ":" + splitTime[2];

                  timeDisplay.setText(time); //modified time
               }
               else if (selected == MIN)
               {
                  String time = timeDisplay.getText();
                  String[] splitTime = time.split(":");

                  int min = Integer.parseInt(splitTime[1].trim());
                  time = splitTime[0] + ":" + Integer.toString(min + 1) + ":" + splitTime[2];

                  timeDisplay.setText(time); //modified time
               }
            }
            else if (cmd.equals(downButton.getText()))
            {
               if (selected == HR)
               {
                  String time = timeDisplay.getText();
                  String[] splitTime = time.split(":");

                  int hr = Integer.parseInt(splitTime[0].trim());
                  time = Integer.toString(hr - 1) + ":" + splitTime[1] + ":" + splitTime[2];

                  timeDisplay.setText(time); //modified time
               }
               else if (selected == MIN)
               {
                  String time = timeDisplay.getText();
                  String[] splitTime = time.split(":");

                  int min = Integer.parseInt(splitTime[1].trim());
                  time = splitTime[0] + ":" + Integer.toString(min - 1) + ":" + splitTime[2];

                  timeDisplay.setText(time); //modified time
               }
            }
            else if (cmd.equals(okButton.getText()))
            {
               //time should be stored in alarmDisplay
               alarmStarted = true;
               alarmTime = timeDisplay.getText();
               selected = -1;
            }
         }
      }

   }



Replace and run

After that, you need to add checks to see that hr +1 and hr -1 rollover at 24 and 0 (24 hrs clock)
same for min - need to make sure it rolls over at 60 and hr gets incremented and so on...

 String[] splitTime = time.split(":");


splitTime contains the hour, minute and second at position 0, 1 and 2 resp.

 

by: Drop_of_RainPosted on 2007-07-12 at 23:34:33ID: 19478605

It don't work but compiles

 

by: keyurkarnikPosted on 2007-07-13 at 00:09:46ID: 19478703

it works just fine :

Here is the complete code :

import java.awt.event.ActionEvent;

import javax.swing.JLabel;


public class GuiPanel extends javax.swing.JFrame
{
   enum Mode {
      Alarm, Timer, Clock, Date, Audio
   };

   private java.util.List<Mode> modes;
   private int modeIndex;
   private Mode currentMode;
   boolean alarmStarted = false;
   public String alarmTime;
   //   private/** Creates new form GuiPanel */
   public GuiPanel()
   {
      initComponents();
      initModes();
   }


   private void initModes()
   {
      modes = new java.util.ArrayList<Mode>();
      for (Mode m : Mode.values())
      {
         modes.add(m);
      }
      modeButton.setAction(new AdvanceModeAction("Mode"));
   }

   private class AdvanceModeAction extends javax.swing.AbstractAction
   {
      public AdvanceModeAction(String name)
      {
         super(name);
      }

      public void actionPerformed(java.awt.event.ActionEvent e)
      {
         advanceMode();
         modeDisplay.setText(currentMode.toString());

         enableAllButtons();

         if (currentMode == Mode.Alarm)
         {
            recordButton.setEnabled(false);
            playButton.setEnabled(false);
            stopButton.setEnabled(false);
            fastButton.setEnabled(false);

            alarmTempDisplay = new JLabel(timeDisplay.getText());
            alarmStarted = false;
            dispProv.setDispListener(alarmTempDisplay);
         }
         else if (currentMode == Mode.Audio)
         {
            hourButton.setEnabled(false);
            minutesButton.setEnabled(false);

         }
         else if (currentMode == Mode.Clock)
         {
            recordButton.setEnabled(false);
            playButton.setEnabled(false);
            stopButton.setEnabled(false);
         }
         else if (currentMode == Mode.Date)
         {
            recordButton.setEnabled(false);
            playButton.setEnabled(false);
            stopButton.setEnabled(false);
         }
         else if (currentMode == Mode.Timer)
         {
            recordButton.setEnabled(false);
            playButton.setEnabled(false);
            stopButton.setEnabled(false);
            dispProv.setDispListener(timeDisplay);
         }


      }
   }

   private class AlarmButtonSelectAction extends javax.swing.AbstractAction
   {
      public final int HR = 0;
      public final int MIN = 1;

      int selected = -1;

      public void actionPerformed(ActionEvent e)
      {
         String cmd = e.getActionCommand();
         if (currentMode == Mode.Alarm)
         {
            if (cmd.equals(hourButton.getText()))
            {
               selected = HR;
            }
            else if (cmd.equals(minutesButton.getText()))
            {
               selected = MIN;
            }
            else if (cmd.equals(upButton.getText()))
            {
               if (selected == HR)
               {
                  String time = timeDisplay.getText();
                  String[] splitTime = time.split(":");

                  int hr = Integer.parseInt(splitTime[0].trim());
                  time = Integer.toString(hr + 1) + ":" + splitTime[1] + ":" + splitTime[2];

                  timeDisplay.setText(time); //modified time
               }
               else if (selected == MIN)
               {
                  String time = timeDisplay.getText();
                  String[] splitTime = time.split(":");

                  int min = Integer.parseInt(splitTime[1].trim());
                  time = splitTime[0] + ":" + Integer.toString(min + 1) + ":" + splitTime[2];

                  timeDisplay.setText(time); //modified time
               }
            }
            else if (cmd.equals(downButton.getText()))
            {
               if (selected == HR)
               {
                  String time = timeDisplay.getText();
                  String[] splitTime = time.split(":");

                  int hr = Integer.parseInt(splitTime[0].trim());
                  time = Integer.toString(hr - 1) + ":" + splitTime[1] + ":" + splitTime[2];

                  timeDisplay.setText(time); //modified time
               }
               else if (selected == MIN)
               {
                  String time = timeDisplay.getText();
                  String[] splitTime = time.split(":");

                  int min = Integer.parseInt(splitTime[1].trim());
                  time = splitTime[0] + ":" + Integer.toString(min - 1) + ":" + splitTime[2];

                  timeDisplay.setText(time); //modified time
               }
            }
            else if (cmd.equals(okButton.getText()))
            {
               //time should be stored in alarmDisplay
               alarmStarted = true;
               alarmTime = timeDisplay.getText();
               selected = -1;
            }
         }
      }

   }


   private void enableAllButtons()
   {
      downButton.setEnabled(true);
      fastButton.setEnabled(true);
      hourButton.setEnabled(true);
      minutesButton.setEnabled(true);
      modeButton.setEnabled(true);
      okButton.setEnabled(true);
      playButton.setEnabled(true);
      recordButton.setEnabled(true);
      stopButton.setEnabled(true);
      upButton.setEnabled(true);
   }

   private void advanceMode()
   {
      currentMode = modes.get(modeIndex++ % modes.size());
   }


   /** 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()
   {
      jPanel1 = new javax.swing.JPanel();
      jLabel1 = new javax.swing.JLabel();
      timeDisplay = new javax.swing.JLabel();
      jPanel2 = new javax.swing.JPanel();
      modeDisplay = new javax.swing.JTextField();
      jPanel3 = new javax.swing.JPanel();
      modeButton = new javax.swing.JButton();
      okButton = new javax.swing.JButton();
      hourButton = new javax.swing.JButton();
      minutesButton = new javax.swing.JButton();
      recordButton = new javax.swing.JButton();
      playButton = new javax.swing.JButton();
      fastButton = new javax.swing.JButton();
      stopButton = new javax.swing.JButton();
      upButton = new javax.swing.JButton();
      downButton = new javax.swing.JButton();

      AlarmButtonSelectAction alarmButtonSelectAction = new AlarmButtonSelectAction();

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
      setResizable(false);
      jPanel1.setBackground(new java.awt.Color(255, 255, 255));
      jLabel1.setFont(new java.awt.Font("Tahoma", 2, 18));
      jLabel1.setForeground(new java.awt.Color(51, 51, 255));
      jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      jLabel1.setText("Audio Reminder Panel");

      timeDisplay.setFont(new java.awt.Font("Tahoma", 0, 36));
      timeDisplay.setForeground(new java.awt.Color(204, 0, 0));
      timeDisplay.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      timeDisplay.setText("00:00:00");

      javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
      jPanel1.setLayout(jPanel1Layout);
      jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(timeDisplay, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE).addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE));
      jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(timeDisplay, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE).addContainerGap()));

      jPanel2.setBackground(new java.awt.Color(0, 0, 0));
      modeDisplay.setBackground(new java.awt.Color(255, 255, 255));
      modeDisplay.setEditable(false);
      modeDisplay.setFont(new java.awt.Font("Tahoma", 1, 12));
      modeDisplay.setHorizontalAlignment(javax.swing.JTextField.CENTER);

      javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
      jPanel2.setLayout(jPanel2Layout);
      jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel2Layout.createSequentialGroup().addGap(152, 152, 152).addComponent(modeDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap(158, Short.MAX_VALUE)));
      jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(modeDisplay, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE));

      jPanel3.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, 11));
      modeButton.setForeground(new java.awt.Color(255, 255, 255));
      modeButton.setText("Mode");
      modeButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });

      okButton.setBackground(new java.awt.Color(0, 0, 0));
      okButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      okButton.setForeground(new java.awt.Color(255, 255, 255));
      okButton.setText("OK");
      okButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });
      okButton.addActionListener(alarmButtonSelectAction);

      hourButton.setBackground(new java.awt.Color(0, 0, 0));
      hourButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      hourButton.setForeground(new java.awt.Color(255, 255, 255));
      hourButton.setText("Hour");
      hourButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });
      hourButton.addActionListener(alarmButtonSelectAction);

      minutesButton.setBackground(new java.awt.Color(0, 0, 0));
      minutesButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      minutesButton.setForeground(new java.awt.Color(255, 255, 255));
      minutesButton.setText("Minutes");
      minutesButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });
      minutesButton.addActionListener(alarmButtonSelectAction);

      recordButton.setBackground(new java.awt.Color(0, 0, 0));
      recordButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      recordButton.setForeground(new java.awt.Color(255, 255, 255));
      recordButton.setText("Record");
      recordButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });

      playButton.setBackground(new java.awt.Color(0, 0, 0));
      playButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      playButton.setForeground(new java.awt.Color(255, 255, 255));
      playButton.setText("Play");
      playButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });

      fastButton.setBackground(new java.awt.Color(0, 0, 0));
      fastButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      fastButton.setForeground(new java.awt.Color(255, 255, 255));
      fastButton.setText("Fast");
      fastButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });

      stopButton.setBackground(new java.awt.Color(0, 0, 0));
      stopButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      stopButton.setForeground(new java.awt.Color(255, 255, 255));
      stopButton.setText("Stop");
      stopButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });

      upButton.setBackground(new java.awt.Color(0, 0, 0));
      upButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      upButton.setForeground(new java.awt.Color(255, 255, 255));
      upButton.setText("Up");
      upButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });
      upButton.addActionListener(alarmButtonSelectAction);

      downButton.setBackground(new java.awt.Color(0, 0, 0));
      downButton.setFont(new java.awt.Font("Tahoma", 1, 11));
      downButton.setForeground(new java.awt.Color(255, 255, 255));
      downButton.setText("Down");
      downButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(java.awt.event.ActionEvent evt)
         {
            event(evt);
         }
      });
      downButton.addActionListener(alarmButtonSelectAction);

      javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
      jPanel3.setLayout(jPanel3Layout);
      jPanel3Layout.setHorizontalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel3Layout.createSequentialGroup().addComponent(modeButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(hourButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(recordButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(fastButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(upButton)).addGroup(jPanel3Layout.createSequentialGroup().addComponent(okButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(minutesButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(playButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(stopButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(downButton))).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

      jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[]{downButton, fastButton, hourButton, minutesButton, modeButton, okButton, playButton, recordButton, stopButton, upButton});

      jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(modeButton).addComponent(fastButton).addComponent(upButton).addComponent(recordButton).addComponent(hourButton, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE).addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(okButton).addComponent(minutesButton).addComponent(playButton).addComponent(stopButton).addComponent(downButton)).addGap(19, 19, 19)));

      jPanel3Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[]{downButton, fastButton, minutesButton, modeButton, okButton, playButton, recordButton, stopButton, upButton});

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addContainerGap()));
      layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(14, 14, 14).addComponent(jPanel3, 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 event(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.JButton downButton;
   private javax.swing.JButton fastButton;
   private javax.swing.JButton hourButton;
   private javax.swing.JLabel jLabel1;
   private javax.swing.JPanel jPanel1;
   private javax.swing.JPanel jPanel2;
   private javax.swing.JPanel jPanel3;
   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 stopButton;
   private javax.swing.JLabel timeDisplay;
   private javax.swing.JButton upButton;
   private JLabel alarmTempDisplay;
   // End of variables declaration                  
   public javax.swing.JLabel getTimeDisplay()
   {
      return timeDisplay;
   }

   public void setTimeDisplay(javax.swing.JLabel timeDisplay)
   {
      this.timeDisplay = timeDisplay;
   }


   /**
    * @param prn
    */
   public void setDispProvider(DispTime prn)
   {
      dispProv = prn;
   }

   private DispTime dispProv;

}














import java.util.Calendar;
import java.util.Formatter;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

      public class DispTime extends JFrame implements Runnable
{
   Calendar calendar;
   int i;
   JTextField time;
   Thread t;
 
   DispTime()
   {
      time = new JTextField();
      time.setEditable(false);
      t = new Thread(this);
      t.start();
   }


   public void run()
   {
      String s;
      while (true)
      {
                  Calendar c = Calendar.getInstance();
                  StringBuilder builder = new StringBuilder();
                  Formatter formatter = new Formatter(builder);
                  formatter.format("%02d:%02d:%02d", c.get(Calendar.HOUR), c.get(Calendar.MINUTE), c.get(Calendar.SECOND));
                  formatter.flush();
                  s = builder.toString();
         try
         {
            t.sleep(1000);
         }
         catch (Exception e)
         {
         }
         time.setText(" " + s);
         listenerTF.setText(time.getText());
      }
   }


   public static void main(String[] args)
   {
     
      final DispTime PRN = new DispTime();
      final GuiPanel gp = new GuiPanel();
      PRN.setDispListener(gp.getTimeDisplay());
      gp.setDispProvider(PRN);

      java.awt.EventQueue.invokeLater(new Runnable()
      {
         public void run()
         {
            gp.setVisible(true);
         }
      });

   }


   /**
    * @param timeDisplay
    */
   public void setDispListener(JLabel timeDisplay)
   {
      this.listenerTF = timeDisplay;
   }
   
   private JLabel listenerTF;
}





if you remember, to run it you need to run the main of DispTime, and hte above code was to be put in GuiPanel

 

by: Drop_of_RainPosted on 2007-07-13 at 00:37:33ID: 19478762

Yes it works great. I can see that after the ok button is pressed the mode display needs to be changed to something else.because the time doesn't start again, unless I change the mode I added a new mode namded Reminder. How do you change to a different mode?

 

by: keyurkarnikPosted on 2007-07-13 at 00:42:18ID: 19478772

By clicking on mode again :)

I purposefully kept it that way - so that if you are in alarm mode, the time wont start till you go into Timer mode (or clock mode if you want)

Specific actions need to be added for every mode, so that it will do specific stuff.

 

by: Drop_of_RainPosted on 2007-07-13 at 00:48:20ID: 19478785

Yes I know, The way i see it is after the new time is set that mode isn't needed anymore. What will happen next next after the OK button is pressed is a dialog will come up and ask if a audio outgoing message is to recorded now. Then the audio class will be called .

 

by: keyurkarnikPosted on 2007-07-13 at 00:51:40ID: 19478800

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...