Sempre que executo o programa ele não me da os valores dentro da lista, ela fica como se não existisse e nenhum valor é fornecido. O que eu queria saber era como fazer os valores aparecerem na lista que foi criada no JFrame. Obrigado!
package classes;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractListModel;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.ListSelectionModel;
import javax.swing.DropMode;
public class TelaContador extends JFrame {
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
TelaContador frame = new TelaContador();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public TelaContador() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 654, 406);
JPanel contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JSlider sliInicio = new JSlider();
sliInicio.setValue(0);
sliInicio.setMaximum(5);
sliInicio.setBounds(78, 38, 200, 26);
contentPane.add(sliInicio);
JSlider sliFim = new JSlider();
sliFim.setValue(6);
sliFim.setMinimum(6);
sliFim.setMaximum(20);
sliFim.setBounds(78, 80, 200, 26);
contentPane.add(sliFim);
JSlider sliPasso = new JSlider();
sliPasso.setValue(1);
sliPasso.setMinimum(1);
sliPasso.setMaximum(4);
sliPasso.setBounds(78, 128, 200, 26);
contentPane.add(sliPasso);
JLabel lblNewLabel = new JLabel("In\u00EDcio");
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblNewLabel.setBounds(22, 41, 46, 14);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Fim");
lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblNewLabel_1.setBounds(22, 87, 46, 14);
contentPane.add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("Passo");
lblNewLabel_2.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblNewLabel_2.setBounds(22, 129, 46, 14);
contentPane.add(lblNewLabel_2);
JLabel lblInicio = new JLabel("0");
lblInicio.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblInicio.setBounds(288, 41, 46, 14);
contentPane.add(lblInicio);
JLabel lblFim = new JLabel("6");
lblFim.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblFim.setBounds(288, 87, 46, 14);
contentPane.add(lblFim);
JLabel lblPasso = new JLabel("1");
lblPasso.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblPasso.setBounds(288, 129, 46, 14);
contentPane.add(lblPasso);
JButton btnCont = new JButton("Contar");
btnCont.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnCont.setBounds(99, 176, 89, 23);
contentPane.add(btnCont);
JList lstContar = new JList();
lstContar.setBounds(517, 325, -158, -279);
contentPane.add(lstContar);
sliInicio.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int i = sliInicio.getValue();
lblInicio.setText(Integer.toString(i));
}
});
sliFim.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int f = sliFim.getValue();
lblFim.setText(Integer.toString(f));
}
});
sliPasso.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int p = sliPasso.getValue();
lblPasso.setText(Integer.toString(p));
}
});
btnCont.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int i = sliInicio.getValue();
int f = sliFim.getValue();
int p = sliPasso.getValue();
DefaultListModel lista = new DefaultListModel();
for (int c = i; c <= f; c += p) {
lista.addElement(c);
}
lstContar.setModel(lista);
}
});
}
}