Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.mycompany.kalkulator;
- import java.awt.Color;
- import javax.swing.*;
- import org.apache.commons.lang3.math.NumberUtils;
- /**
- *
- * @author Marcin
- */
- public class SprawdzLiczbe extends InputVerifier {
- @Override
- public boolean verify(JComponent input) {
- String text = ((JTextField) input).getText();
- if (NumberUtils.isNumber(text) || text.equals("")) { // czy podana wartosc to liczba lub puste pole
- double liczba = NumberUtils.toDouble(text);
- if (liczba >= 0 && liczba <= 2000) { // czy liczba miesci sie w zakresie
- input.setBackground(Color.WHITE); // kolor domyslny
- return true;
- }
- input.setBackground(Color.red); // kolor czerwony
- return false;
- }
- input.setBackground(Color.red);
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement