"Maximo (termometro)"
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
@SuppressWarnings("serial")
public class max extends JFrame implements ChangeListener, ActionListener {
private JSlider deslizante;
private JTextField campotexto;
private JButton boton;
private int max=0;
public static void main(String[] args) {
max demo=new max();
demo.setSize(200,300);
demo.setTitle("Maximo");
demo.crearGUI();
demo.setVisible(true); }
private void crearGUI() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
Container ventana=getContentPane();
ventana.setLayout(new FlowLayout());
deslizante=new JSlider(JSlider.VERTICAL, 0, 100, 0);
deslizante.setMajorTickSpacing(10);
deslizante.setPaintTicks(true);
deslizante.addChangeListener(this);
ventana.add(deslizante);
campotexto=new JTextField(12);
ventana.add(campotexto);
boton=new JButton("restablecer");
boton.addActionListener(this);
ventana.add(boton); }
@Override
public void actionPerformed(ActionEvent arg0) {
campotexto.setText("");
max=0; }
@Override
public void stateChanged(ChangeEvent arg0) {
int temp;
temp=deslizante.getValue();
if (temp>max) {max=temp; }
mostrar();
}
private void mostrar() {
campotexto.setText("el valor maximo es " + max);
}
}
//