Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. package PVC;
  2.  
  3. import java.awt.EventQueue;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.JOptionPane;
  7. import javax.swing.JButton;
  8. import java.awt.BorderLayout;
  9. import java.awt.event.ActionListener;
  10. import java.awt.event.ActionEvent;
  11.  
  12. public class Test {
  13.  
  14. private JFrame frame;
  15.  
  16. /**
  17. * Launch the application.
  18. */
  19. public static void main(String[] args) {
  20. EventQueue.invokeLater(new Runnable() {
  21. public void run() {
  22. try {
  23. Test window = new Test();
  24. window.frame.setVisible(true);
  25. } catch (Exception e) {
  26. e.printStackTrace();
  27. }
  28. }
  29. });
  30. }
  31.  
  32. /**
  33. * Create the application.
  34. */
  35. public Test() {
  36. initialize();
  37. }
  38.  
  39. /**
  40. * Initialize the contents of the frame.
  41. */
  42. private void initialize() {
  43. frame = new JFrame();
  44. frame.setBounds(100, 100, 450, 300);
  45. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  46.  
  47. JButton btnNewButton_1 = new JButton("New button");
  48. btnNewButton_1.addActionListener(new ActionListener() {
  49. public void actionPerformed(ActionEvent e) {
  50. double f = 1, sr = 0;
  51. int c = 0;
  52. while(f!=0) {
  53. f = Double.parseDouble(JOptionPane.showInputDialog(""));
  54. if(f%2!=0) {
  55. sr += f;
  56. c++;
  57. }
  58. }
  59. if(sr==0) JOptionPane.showMessageDialog(null, "Няма такива");
  60. else JOptionPane.showMessageDialog(null, sr/c);
  61.  
  62. }
  63. });
  64. frame.getContentPane().add(btnNewButton_1, BorderLayout.WEST);
  65. }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement