Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class InnException extends Exception {
- public String ExceptionMessage() {
- System.err.println("Введен некорректный инн!");
- return "Введен некорректный инн!";
- }
- }
- /////////////////////////////////////////////////////
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.*;
- import java.util.List;
- public class LabClassUI extends JFrame {
- List<Long> arr = new ArrayList<>();
- private JLabel info = new JLabel("Список: " + arr);
- private JButton sortBut = new JButton("Сортировать");
- private JTextField number = new JTextField(3);
- private JButton searchBut = new JButton("Найти ИНН");
- public List<Long> getArr() {
- return arr;
- }
- public LabClassUI() {
- super("T9");
- this.setBounds(200,200,640,640);
- this.setDefaultCloseOperation(EXIT_ON_CLOSE);
- info.setHorizontalAlignment(info.CENTER);
- number.setHorizontalAlignment(number.CENTER);
- sortBut.setHorizontalAlignment(sortBut.CENTER);
- searchBut.setHorizontalAlignment(searchBut.CENTER);
- sortBut.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- long x = Long.parseLong(number.getText());
- try {
- if (checkInn(x)) arr.add(x);
- }
- catch (InnException e1) {
- // e1.ExceptionMessage();
- JOptionPane.showMessageDialog(LabClassUI.this, e1.ExceptionMessage());
- }
- //arr.add(x);
- Collections.sort(arr, new Comparator<Long>() {
- @Override
- public int compare(Long o1, Long o2) {
- return (int) (o2 - o1);
- }
- });
- info.setText("Список:" + arr);
- }
- });
- searchBut.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- if (checkUser(Long.parseLong(number.getText()))) JOptionPane.showMessageDialog(LabClassUI.this, "ИНН найден!");
- } catch (Exception e2) {
- JOptionPane.showMessageDialog(LabClassUI.this, "ИНН не найден!");
- }
- }
- });
- JPanel panel = new JPanel();
- GridLayout lay = new GridLayout(2,2,5,5);
- panel.setLayout(lay);
- panel.add(info);
- panel.add(number);
- panel.add(sortBut);
- panel.add(searchBut);
- getContentPane().add(panel);
- setVisible(true);
- }
- private boolean checkInn(long inn) throws InnException {
- if(inn/100000000000L < 1 | inn/100000000000L > 9 | inn<0) {
- throw new InnException(); }
- else return true;
- }
- public boolean checkUser(long inn) throws InnNotFoundException{
- if (!this.arr.contains(inn)) throw new InnNotFoundException();
- else return true;
- }
- public static void main(String[] args) {
- LabClassUI gui = new LabClassUI();
- }
- }
- //////////////////////////////////////
- public class InnNotFoundException extends Exception {
- public String ExceptionMessage() {
- System.err.println("Введен некорректный инн!");
- return "Введен некорректный инн!";
- }
- }
Add Comment
Please, Sign In to add comment