Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PVC;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- import javax.swing.JButton;
- import java.awt.BorderLayout;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class Test {
- private JFrame frame;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Test window = new Test();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public Test() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame();
- frame.setBounds(100, 100, 450, 300);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JButton btnNewButton_1 = new JButton("New button");
- btnNewButton_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- double f = 1, sr = 0;
- int c = 0;
- while(f!=0) {
- f = Double.parseDouble(JOptionPane.showInputDialog(""));
- if(f%2!=0) {
- sr += f;
- c++;
- }
- }
- if(sr==0) JOptionPane.showMessageDialog(null, "Няма такива");
- else JOptionPane.showMessageDialog(null, sr/c);
- }
- });
- frame.getContentPane().add(btnNewButton_1, BorderLayout.WEST);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement