import java.awt.event.ActionListener

annuncio pubblicitario
import
import
import
import
javax.swing.*;
java.awt.*;
java.awt.event.ActionEvent;
java.awt.event.ActionListener;
public class ProgressBar extends JFrame implements ActionListener {
private
private
private
private
private
private
private
private
private
private
private
JLabel l1;
JButton b1;
JButton b2;
JTextField t1;
JTextField t2;
JProgressBar pb;
double x;
double y;
String sottrai;
int a;
int value;
public ProgressBar() {
setLayout(null);
setSize(450, 450);
setLocation(420, 160);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
l1 = new JLabel("SERBATOIO");
l1.setBounds(152, 10, 190, 30);
l1.setFont(new Font("verdana", Font.BOLD, 20));
t1 = new JTextField("");
t1.setBounds(90, 100, 110, 45);
t1.setFont(new Font("verdana", Font.BOLD, 20));
t2 = new JTextField("");
t2.setBounds(90, 180, 110, 45);
t2.setFont(new Font("verdana", Font.BOLD, 20));
b1 = new JButton("Aggiungi");
b1.setBounds(240, 100, 110, 45);
b1.setFont(new Font("verdana", Font.BOLD, 14));
b1.addActionListener(this);
b1.setForeground(Color.BLUE);
b1.setBackground(Color.ORANGE);
b2 = new JButton("Rimuovi");
b2.setBounds(240, 180, 110, 45);
b2.setFont(new Font("verdana", Font.BOLD, 14));
b2.addActionListener(this);
b2.setForeground(Color.red);
b2.setBackground(Color.ORANGE);
pb = new JProgressBar(JProgressBar.HORIZONTAL);
pb.setBounds(178, 260, 80, 120);
pb.setFont(new Font("verdana", Font.BOLD, 14));
add(l1);
add(b1);
add(b2);
add(t1);
add(t2);
add(pb);
}
public void actionPerformed(ActionEvent e) {
try{
if (e.getSource() == b1) {
value = pb.getValue() + Integer.parseInt(t1.getText());
pb.setValue(value);
pb.setStringPainted(true);
}
if (e.getSource() == b2) {
int a = Integer.parseInt(t2.getText());
value = value - a;
pb.setValue(value);
pb.setStringPainted(true);
}
} catch(Exception eccezzione) {
if(eccezzione.toString().contains("FormatException")){
JOptionPane.showMessageDialog(null, "Inserisci un
numero per continuare!");
}
}
}
}
Scarica