Hi, can anyone help me with this code, I'm trying to apply a selected number from 0 to 10000 from the countdown prog to the ddd program and countdown from that number.
I can compile, but the program crashs after chosing a number.
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.math.*;
public class CountDown extends JPanel
{
JList list;
DefaultListModel model;
int counter = 10000;
String time;
final int SECONDS = 60;
int minutes = 0;
public static void main(String s[])
{
JFrame frame = new JFrame("List Model Example");
frame.setContentPane(new CountDown());
frame.setSize(70, 80);
frame.setVisible(true);
}
public CountDown()
{
setLayout(new BorderLayout());
model = new DefaultListModel();
list = new JList(model);
JScrollPane pane = new JScrollPane(list);
pane.setPreferredSize(new Dimension(50,22));
JButton btn = new JButton("Min");
for (int i = 1; i < 10000; i++)
model.addElement(" " + i);
list.setSelectedIndex(0);
add(pane, BorderLayout.NORTH);
add(btn, BorderLayout.WEST);
btn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
int bob = list.getSelectedIndex();
if(bob == JOptionPane.OK_OPTION);
{
String time = (String)list.getSelectedValue();
System.out.println("Chosen Minute" + time);
ddd("");
}
}
});
}
public void ddd(String time)
{
minutes = Integer.parseInt(time);
final java.util.Timer sid = new java.util.Timer();
sid.scheduleAtFixedRate(new TimerTask()
{
int bbb = minutes * SECONDS;
public void run()
{
System.out.println(""+bbb/SECONDS+" : "+bbb % SECONDS);
bbb--;
if(bbb < 0)
{
sid.cancel();
System.exit(0);
}
}
},0,1000);
}
}