Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JButton;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JTextField;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class zad1 {
- private JFrame frame;
- private JTextField textField;
- private JLabel lblO;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- zad1 window = new zad1();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public zad1() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame();
- frame.setTitle("\u041C\u0438\u043D. \u043E\u0442 \u043D\u0435\u0447\u0435\u0442\u043D\u0438\u0442\u0435");
- frame.setBounds(100, 100, 343, 169);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- JLabel lblM = new JLabel("m:");
- lblM.setBounds(158, 11, 46, 14);
- frame.getContentPane().add(lblM);
- textField = new JTextField();
- textField.setBounds(118, 36, 91, 20);
- frame.getContentPane().add(textField);
- textField.setColumns(10);
- lblO = new JLabel("O\u0442\u0433\u043E\u0432\u043E\u0440:");
- lblO.setBounds(118, 111, 197, 20);
- frame.getContentPane().add(lblO);
- JButton button = new JButton("\u0412\u044A\u0432\u0435\u0434\u0438");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- int m = Integer.parseInt(textField.getText());
- if (m<=0){
- lblO.setText("Невалидни данни.");
- }else{
- int[] arr = new int[m];
- for (int i = 0;i<m;i++){
- arr[i]=Integer.parseInt(JOptionPane.showInputDialog("Число "+(i+1)));
- }
- int min=Integer.MAX_VALUE;
- int count = 0;
- for (int i = 0;i<m;i++){
- if (arr[i]<min && arr[i]%2!=0){
- min = arr[i];
- count++;
- }
- }
- if (count!=0){
- lblO.setText(Integer.toString(min));
- }
- else{
- lblO.setText("Няма нечетни числа.");
- }
- }
- }
- });
- button.setBounds(118, 79, 91, 23);
- frame.getContentPane().add(button);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement