Results 1 to 2 of 2
  1. #1
    zenkology is offline Member
    Join Date
    Nov 2011
    Posts
    1
    Rep Power
    0

    Default probelm in submit button in shutdown Timer

    hey guys, um working on shutdown timer and when I press on submit button illogical errors to me appear suddenly that's all the code


    Java Code:
    package shutdown.timer;
    
    import java.io.IOException;
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.*;
    
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    
    public class model extends JFrame {
    
        private boolean con = true;
        private JComboBox h;
        private JComboBox m;
        private JComboBox ap;
        private JLabel apaa;
        private JLabel hours;
        private JLabel minutes;
        private JRadioButton shutDownradio;
        private JRadioButton restartradio;
        private JLabel shutDownLabel;
        private JLabel resetLabel;
        private JButton submit;
        private JButton reset;
        private JPanel pan1;
        private JPanel pan2;
        private JPanel pan3;
        private Date d1;
        private Date d;
        private String[] hh = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
            "11", "12"};
        private String[] mm = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
            "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21",
            "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32",
            "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43",
            "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54",
            "55", "56", "57", "58", "59"};
        private String[] apa = {"am", "pm"};
        private ButtonGroup bg;
    
        public model() {
            setupGUI();
            getTime();
            addListeners();
    
        }
    
        private void getTime() {
            try {
                d = new Date();
                DateFormat df = new SimpleDateFormat("h:m a");
                df.format(d);
                String x = (String) h.getSelectedItem() + (String) m.getSelectedItem() + (String) ap.getSelectedItem();
                d1 = df.parse(x);
                System.out.println(d1);
            } catch (ParseException ex) {
    ex.getMessage();
            }
    
        }
    
        private void addListeners() {
    
            submit.addActionListener(new ActionListener() {
    
                @Override
                public void actionPerformed(ActionEvent e) {
                    con = true;
                    while (con) {
                        if (shutDownradio.isSelected()) {
                            if (d1.equals(d)) {
                                try {
                                    Runtime runtime = Runtime.getRuntime();
                                    Process proc = runtime.exec("shutdown.exe -s -t 0");
                                    System.exit(0);
                                } catch (IOException ex) {
                                    ex.getMessage();
                                }
                            }
                            
                        } else if (restartradio.isSelected()) {
                            if (d1.equals(d)) {
                                try {
                                    Runtime runtime2 = Runtime.getRuntime();
                                    Process proc = runtime2.exec("restart.exe -s -t 0");
                                    System.exit(0);
                                } catch (IOException ex) {
                                    ex.getMessage();
                                }
    
                            }
                        }
                    }
                }
            });
            reset.addActionListener(new ActionListener() {
    
                @Override
                public void actionPerformed(ActionEvent e) {
                 Thread t=new Thread(){
                 public void run(){
                 con=false;
                 
                 }
                 
                 
                 };
                 t.start();
                }
            });
    
    
    
    
        }
    
        private void setupGUI() {
    
            // Panels
            pan1 = new JPanel();
            pan2 = new JPanel();
            pan3 = new JPanel();
    
            // Labels
    
            resetLabel = new JLabel("Reset");
            shutDownLabel = new JLabel("ShutDown ");
            hours = new JLabel("Hours");
            minutes = new JLabel("Minutes");
            apaa = new JLabel("am/pm");
    
            // CheckBoxes
            shutDownradio = new JRadioButton();
            restartradio = new JRadioButton();
            bg = new ButtonGroup();
            bg.add(shutDownradio);
            bg.add(restartradio);
            // Buttons
    
            submit = new JButton("Submit");
            reset = new JButton("Reset");
    
            // ComboBoxes
            h = new JComboBox(hh);
            m = new JComboBox(mm);
            ap = new JComboBox(apa);
            ap.setSize(20, 10);
            h.setSize(20, 10);
            m.setSize(20, 10);
    
            // panels configuration
            pan1.setLayout(new FlowLayout());
            pan1.add(shutDownradio);
            pan1.add(shutDownLabel);
            pan1.add(restartradio);
            pan1.add(resetLabel);
    
            // ---------------------------------------------------------
    
            pan2.setLayout(new FlowLayout());
            pan2.add(hours);
            pan2.add(h);
            pan2.add(minutes);
            pan2.add(m);
            pan2.add(apaa);
            pan2.add(ap);
            // ---------------------------------------------------------
    
            pan3.setLayout(new FlowLayout());
            pan3.add(submit);
            pan3.add(reset);
    
            // Frame Layout
    
            setSize(350, 150);
            setVisible(true);
            add(pan2, BorderLayout.BEFORE_FIRST_LINE);
            add(pan1, BorderLayout.CENTER);
            add(pan3, BorderLayout.SOUTH);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
    
        }
    
        public static void main(String[] args) {
            new model();
        }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: probelm in submit button in shutdown Timer

    Quote Originally Posted by zenkology View Post
    hey guys, um working on shutdown timer and when I press on submit button illogical errors to me appear suddenly that's all the code
    Can you tell us about the "illogical errors"? Post any you see in their entirety.

Similar Threads

  1. Please help : JSP ,Submit button and servlet
    By kalyana in forum JavaServer Pages (JSP) and JSTL
    Replies: 12
    Last Post: 03-30-2011, 07:32 AM
  2. Submit, button, focus
    By Aschee in forum New To Java
    Replies: 0
    Last Post: 03-28-2011, 05:31 PM
  3. How to handling submit button from servlet
    By kalyana in forum New To Java
    Replies: 1
    Last Post: 03-27-2011, 04:10 PM
  4. Submit Button Help
    By Jay-1.1 in forum New To Java
    Replies: 2
    Last Post: 05-06-2008, 05:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •