private void setBackgroundColor(String bColor) { frame.setBackground(stringToColor(bColor)); config.setBackgroundColor(bColor); }
private void setButtonColor(String bColor) { for (int i = 0; i < buttonList.size(); i++) { buttonList.get(i).setBackground(stringToColor(bColor)); } config.setButtonColor(bColor); }
/** Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 300, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu mnFile = new JMenu("File"); menuBar.add(mnFile); mntmExit = new JMenuItem("Exit"); mntmExit.addActionListener(this); mnFile.add(mntmExit); JMenu mnConfiguration = new JMenu("Configuration"); menuBar.add(mnConfiguration); JMenu mnButtonColor = new JMenu("Button Color"); mnConfiguration.add(mnButtonColor); mnBtBlack = new JMenuItem(CalcConfig.black); mnBtBlack.addActionListener(this); mnButtonColor.add(mnBtBlack); mnBtGray = new JMenuItem(CalcConfig.gray); mnBtGray.addActionListener(this); mnButtonColor.add(mnBtGray); mnBtWhite = new JMenuItem(CalcConfig.white); mnBtWhite.addActionListener(this); mnButtonColor.add(mnBtWhite); mnBtBlue = new JMenuItem(CalcConfig.blue); mnBtBlue.addActionListener(this); mnButtonColor.add(mnBtBlue); mnBtCyan = new JMenuItem(CalcConfig.cyan); mnBtCyan.addActionListener(this); mnButtonColor.add(mnBtCyan); mnBtDark_Gray = new JMenuItem(CalcConfig.dark_gray); mnBtDark_Gray.addActionListener(this); mnButtonColor.add(mnBtDark_Gray); mnBtGreen = new JMenuItem(CalcConfig.green); mnBtGreen.addActionListener(this); mnButtonColor.add(mnBtGreen); mnBtLight_Gray = new JMenuItem(CalcConfig.light_gray); mnBtLight_Gray.addActionListener(this); mnButtonColor.add(mnBtLight_Gray); mnBtMagenta = new JMenuItem(CalcConfig.magenta); mnBtMagenta.addActionListener(this); mnButtonColor.add(mnBtMagenta); mnBtPink = new JMenuItem(CalcConfig.pink); mnBtPink.addActionListener(this); mnButtonColor.add(mnBtPink); mnBtRed = new JMenuItem(CalcConfig.red); mnBtRed.addActionListener(this); mnButtonColor.add(mnBtRed); mnBtYellow = new JMenuItem(CalcConfig.yellow); mnBtYellow.addActionListener(this); mnButtonColor.add(mnBtYellow); // button text color JMenu mnTextColor = new JMenu("Text Color"); mnConfiguration.add(mnTextColor); mnTxBlack = new JMenuItem(CalcConfig.black); mnTxBlack.addActionListener(this); mnTextColor.add(mnTxBlack); mnTxGray = new JMenuItem(CalcConfig.gray); mnTxGray.addActionListener(this); mnTextColor.add(mnTxGray); mnTxWhite = new JMenuItem(CalcConfig.white); mnTxWhite.addActionListener(this); mnTextColor.add(mnTxWhite); mnTxBlue = new JMenuItem(CalcConfig.blue); mnTxBlue.addActionListener(this); mnTextColor.add(mnTxBlue); mnTxCyan = new JMenuItem(CalcConfig.cyan); mnTxCyan.addActionListener(this); mnTextColor.add(mnTxCyan); mnTxDark_Gray = new JMenuItem(CalcConfig.dark_gray); mnTxDark_Gray.addActionListener(this); mnTextColor.add(mnTxDark_Gray); mnTxGreen = new JMenuItem(CalcConfig.green); mnTxGreen.addActionListener(this); mnTextColor.add(mnTxGreen); mnTxLight_Gray = new JMenuItem(CalcConfig.light_gray); mnTxLight_Gray.addActionListener(this); mnTextColor.add(mnTxLight_Gray); mnTxMagenta = new JMenuItem(CalcConfig.magenta); mnTxMagenta.addActionListener(this); mnTextColor.add(mnTxMagenta); mnTxPink = new JMenuItem(CalcConfig.pink); mnTxPink.addActionListener(this); mnTextColor.add(mnTxPink); mnTxRed = new JMenuItem(CalcConfig.red); mnTxRed.addActionListener(this); mnTextColor.add(mnTxRed); mnTxYellow = new JMenuItem(CalcConfig.yellow); mnTxYellow.addActionListener(this); mnTextColor.add(mnTxYellow); // background color JMenu mnBackgroundColor = new JMenu("Background Color"); mnConfiguration.add(mnBackgroundColor); mnBkBlack = new JMenuItem(CalcConfig.black); mnBkBlack.addActionListener(this); mnBackgroundColor.add(mnBkBlack); mnBkGray = new JMenuItem(CalcConfig.gray); mnBkGray.addActionListener(this); mnBackgroundColor.add(mnBkGray); mnBkWhite = new JMenuItem(CalcConfig.white); mnBkWhite.addActionListener(this); mnBackgroundColor.add(mnBkWhite); mnBkBlue = new JMenuItem(CalcConfig.blue); mnBkBlue.addActionListener(this); mnBackgroundColor.add(mnBkBlue); mnBkCyan = new JMenuItem(CalcConfig.cyan); mnBkCyan.addActionListener(this); mnBackgroundColor.add(mnBkCyan); mnBkDark_Gray = new JMenuItem(CalcConfig.dark_gray); mnBkDark_Gray.addActionListener(this); mnBackgroundColor.add(mnBkDark_Gray); mnBkGreen = new JMenuItem(CalcConfig.green); mnBkGreen.addActionListener(this); mnBackgroundColor.add(mnBkGreen); mnBkLight_Gray = new JMenuItem(CalcConfig.light_gray); mnBkLight_Gray.addActionListener(this); mnBackgroundColor.add(mnBkLight_Gray); mnBkMagenta = new JMenuItem(CalcConfig.magenta); mnBkMagenta.addActionListener(this); mnBackgroundColor.add(mnBkMagenta); mnBkPink = new JMenuItem(CalcConfig.pink); mnBkPink.addActionListener(this); mnBackgroundColor.add(mnBkPink); mnBkRed = new JMenuItem(CalcConfig.red); mnBkRed.addActionListener(this); mnBackgroundColor.add(mnBkRed); mnBkYellow = new JMenuItem(CalcConfig.yellow); mnBkYellow.addActionListener(this); mnBackgroundColor.add(mnBkYellow); // calculator buttons buttonList = new ArrayList<JButton>(); button1 = new JButton("1"); button1.setBounds(25, 50, 45, 45); button1.setOpaque(true); button1.addActionListener(this); frame.getContentPane().add(button1); buttonList.add(button1); button2 = new JButton("2"); button2.setBounds(75, 50, 45, 45); button2.setOpaque(true); button2.addActionListener(this); frame.getContentPane().add(button2); buttonList.add(button2); button3 = new JButton("3"); button3.setBounds(125, 50, 45, 45); button3.setOpaque(true); button3.addActionListener(this); frame.getContentPane().add(button3); buttonList.add(button3); button4 = new JButton("4"); button4.setBounds(25, 100, 45, 45); button4.setOpaque(true); button4.addActionListener(this); frame.getContentPane().add(button4); buttonList.add(button4); button5 = new JButton("5"); button5.setBounds(75, 100, 45, 45); button5.setOpaque(true); button5.addActionListener(this); frame.getContentPane().add(button5); buttonList.add(button5); button6 = new JButton("6"); button6.setBounds(125, 100, 45, 45); button6.setOpaque(true); button6.addActionListener(this); frame.getContentPane().add(button6); buttonList.add(button6); button7 = new JButton("7"); button7.setBounds(25, 150, 45, 45); button7.setOpaque(true); button7.addActionListener(this); frame.getContentPane().add(button7); buttonList.add(button7); button8 = new JButton("8"); button8.setBounds(75, 150, 45, 45); button8.setOpaque(true); button8.addActionListener(this); frame.getContentPane().add(button8); buttonList.add(button8); button9 = new JButton("9"); button9.setBounds(125, 150, 45, 45); button9.setOpaque(true); button9.addActionListener(this); frame.getContentPane().add(button9); buttonList.add(button9); button0 = new JButton("0"); button0.setBounds(75, 200, 45, 45); button0.setOpaque(true); button0.addActionListener(this); frame.getContentPane().add(button0); buttonList.add(button0); buttonDec = new JButton("."); buttonDec.setBounds(125, 200, 45, 45); buttonDec.setOpaque(true); buttonDec.addActionListener(this); frame.getContentPane().add(buttonDec); buttonList.add(buttonDec); buttonPlus = new JButton("+"); buttonPlus.setBounds(175, 50, 45, 45); buttonPlus.setOpaque(true); buttonPlus.addActionListener(this); frame.getContentPane().add(buttonPlus); buttonList.add(buttonPlus); buttonMinus = new JButton("-"); buttonMinus.setBounds(175, 100, 45, 45); buttonMinus.setOpaque(true); buttonMinus.addActionListener(this); frame.getContentPane().add(buttonMinus); buttonList.add(buttonMinus); buttonMult = new JButton("*"); buttonMult.setBounds(175, 150, 45, 45); buttonMult.setOpaque(true); buttonMult.addActionListener(this); frame.getContentPane().add(buttonMult); buttonList.add(buttonMult); buttonDiv = new JButton("/"); buttonDiv.setBounds(175, 200, 45, 45); buttonDiv.setOpaque(true); buttonDiv.addActionListener(this); frame.getContentPane().add(buttonDiv); buttonList.add(buttonDiv); buttonEq = new JButton("="); buttonEq.setBounds(225, 100, 45, 145); buttonEq.setOpaque(true); buttonEq.addActionListener(this); frame.getContentPane().add(buttonEq); buttonList.add(buttonEq); buttonClr = new JButton("C"); buttonClr.setBounds(225, 50, 45, 45); buttonClr.setOpaque(true); buttonClr.addActionListener(this); frame.getContentPane().add(buttonClr); buttonList.add(buttonClr); textField = new JTextField(); textField.setHorizontalAlignment(SwingConstants.TRAILING); textField.setBounds(25, 6, 245, 39); frame.getContentPane().add(textField); textField.setColumns(15); textField.setText(Double.toString(runningTotal)); setBackgroundColor(config.getBackgroundColor()); setButtonTextColor(config.getTextColor()); setButtonColor(config.getButtonColor()); }