Jcombobox选项在带有tickboxes Java的面板之间切换

时间:2018-04-05 09:11:01

标签: java intellij-idea calculator jcombobox

我是Java的新手,我想做以下事情:

用户从JComboBox中选择一个选项,该选项将触发以下内容:

新面板显示在同一帧中,包含5个复选框。每个复选框都有一个值。 用户选择2个复选框,点击"计算" 使用值的总和触发新TextBox。

用户从ComboBox更改选择,删除前一帧并显示新帧。

上面的想法是一个计算器,但比传统计算器复杂一点。

非常感谢您的时间和帮助。我在IntelliJ中使用gui表单。这是我到目前为止所得到的:

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.ImageIcon;

public class CastCalculator {
    private JPanel MainPanel;
    private JLabel CastImage;
    private JComboBox buidlingChoice;
    private JComboBox procurementChoice;
    private JCheckBox pMFoundationsCheckBox;
    private JCheckBox pMFrameElementsCheckBox;

    private JPanel House;
    private JPanel fiveStorey;
    private JPanel traditional;


    private JPanel finalCalculation;

    private JRadioButton radioButton1;
    private JButton calculateButton;
    double pmFoundationsValue;
    private JPanel resultPanel;

    String toString(double d) {
        return null;
    }
    private CastCalculator(){
        calculator();
    }

    private void calculator(){

        House.addComponentListener(new ComponentAdapter() {
            @Override
            public void componentResized(ComponentEvent e) {
                JOptionPane.showMessageDialog(null, "Hi Michelle");
            }
        });
        pMFoundationsCheckBox.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (pMFoundationsCheckBox.isSelected())
                    pmFoundationsValue = 1.5;
                }
        });
        String pmFV = Double.toString( pmFoundationsValue );
        calculateButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

            }
        });
    }

    private void houseComboBox {
        String[] buildingStrings = {"House", "5-Storey Building", "10-Storey Building"};
        String[] procurementStrings = {"Traditional", "2-D", "3-D"};

        JComboBox<String> buildingList = new JComboBox<>( buildingStrings );
        buildingList.setSelectedIndex( 3 );
        buildingList.addActionListener( (ActionListener) this );
        @Override
        public void actionPerformed(ActionEvent Object e;
        e) {

        }
    }
    private void createUIComponents() {
        CastImage = new JLabel( (new ImageIcon( "cast.png" )) );
    }


    public static void main(String[] args) {
        JFrame mainFrame = new JFrame( "Cast PMV Calculator" );
        mainFrame.setContentPane( new CastCalculator().calculator);
        mainFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        mainFrame.pack();
        //mainFrame.setSize(500,600);
        mainFrame.setVisible( true );
    }

}

0 个答案:

没有答案