mercredi 12 octobre 2016

How to output to a file when conditions are correct with mouseclicked and itemlistener

What I am trying to do is output to a file when you press Save. They have 4 checkboxes and they need to choose one. when they choose one it will tell the program which one they choose and output the following accordingly. what I have currently does not work, any ideas?

JButton buttonSave = new JButton("Save");
        buttonSave.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {

                String name = whoSoldTo.getText();
                String test = sellPrice.getText();
                int soldToPrice = Integer.parseInt(test);

                checkboxMint.addItemListener(new ItemListener() {
                    @Override
                    public void itemStateChanged(ItemEvent ev) {
                    }
                });

                if(ev.getStateChange() == ItemEvent.SELECTED) {
                    write.soldToFile(name, "mint", soldToPrice);
                    System.out.println("Mint works");
                }

                checkboxTobacco.addItemListener(new ItemListener() {
                    @Override
                    public void itemStateChanged(ItemEvent e) {
                        if(e.getStateChange() == ItemEvent.SELECTED) {
                            write.soldToFile(name, "tobacco", soldToPrice);
                        }
                    }
                });

                checkboxFruit.addItemListener(new ItemListener() {
                    @Override
                    public void itemStateChanged(ItemEvent e) {
                        if(e.getStateChange() == ItemEvent.SELECTED) {
                            write.soldToFile(name, "fruit", soldToPrice);
                        }
                    }
                });

                checkboxCreme.addItemListener(new ItemListener() {
                    @Override
                    public void itemStateChanged(ItemEvent e) {
                        if(e.getStateChange() == ItemEvent.SELECTED) {
                            write.soldToFile(name, "creme", soldToPrice);
                        }
                    }
                });

            }
        });

        buttonSave.setBounds(227, 143, 117, 29);
        contentPane.add(buttonSave);

    }
}

Aucun commentaire:

Enregistrer un commentaire