JSpinner with ChangeListener

A jspinner generates an event of type ChangeEvent when an item is selected that is sent to listeners of type ChangeListener. Both types are defined in the javax.swing.event package. To obtain the current value of the jspinner, call getValue( ). It returns the current setting. Program       Progarm Source import javax.swing.JFrame; import javax.swing.JSpinner; … Read more…

JSpinner with SpinnerListModel

SpinnerListModel is a model for a sequence defined by an array of objects of any type. You could use this to use a sequence of strings as the choices in the spinner. Program       Program Source import javax.swing.JFrame; import javax.swing.JSpinner; import javax.swing.SpinnerListModel; import java.awt.FlowLayout; import java.awt.Dimension; class JSpinnerTest extends JFrame { JSpinnerTest() { … Read more…

JSpinner with default value

The JSpinners are like to jcombo boxes and jlists in that they user can select input from a predetermined set of values. Program       Program Source import javax.swing.JFrame; import javax.swing.JSpinner; import java.awt.FlowLayout; import java.awt.Dimension; class JSpinnerTest extends JFrame { JSpinnerTest() { setTitle(“JSpinnerTest”); setLayout(new FlowLayout()); setJSpinner(); setSize(700,200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } void setJSpinner() { JSpinner js = new JSpinner(); … Read more…

JProgressBar (Another Example)

If you can control whether the contents of a text field may be modified by the user by calling setEditable( ). In setEditable( ), if value is true, the text may be changed. If it is false, the text cannot be altered. Program import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JProgressBar; … Read more…

JProgressBar

JProgressBar  It is visually displays the progress of some task. The setMinimum() and setMaximum() that creates the progress bar sets the progress bar’s minimum and maximum values. setStringPainted(boolean value ) : Sets the value of the stringPainted property, which determines whether the progress bar should render a progress string. setValue(): The setValue method is used … Read more…

Timer

Program       Program Source import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.Timer; import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; class Frame extends JFrame implements ActionListener{ private int time = 1; private JButton jb; private Timer timer; Frame(int t) { time += t; setTitle(“Timer test”); setLayout(new FlowLayout()); setTimer(); setSize(700,350); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void setTimer() { jb … Read more…