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
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();
}
}
Re: probelm in submit button in shutdown Timer
Quote:
Originally Posted by
zenkology
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.