import java.awt.*; import java.awt.FlowLayout; import java.awt.event.*; import java.awt.Color.*; import java.awt.image.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; public class Calculator extends JFrame implements ActionListener{ final int MAX_INPUT_LENGTH = 31; final int INPUT_MODE = 0; final int RESULT_MODE = 1; final int ERROR_MODE = 2; int displayMode; // variables for memory buttons functionality static double m1, m2; int k = 1; JButton butM1, butM2, butM3, butM4; double lastNumber; boolean clearOnNextDigit, percent; String lastOperator; JButton but0, but1, but2, but3, but4, but5, but6, but7, but8, but9, but10, but11, but12, but13, but14, but15, but16, but17, but18, but19, but20, but21, but22; JMenu jmenuEdit, jmenuView, jmenuHelp; JMenuItem jmenuitemCopy, jmenuitemPaste, jmenuitemStandard, jmenuitemScientific, jmenuitemDigit, jmenuitemHelp, jmenuitemAbout; Border raisedbevel, loweredbevel, border; JLabel MemoryTextfield, LabelOutPut; public Calculator() { setBackground(new Color(236,233,216)); setIconImage(new ImageIcon("6039.png").getImage()); border = LineBorder.createGrayLineBorder(); raisedbevel = BorderFactory.createRaisedBevelBorder(); loweredbevel = BorderFactory.createLoweredBevelBorder(); Font f12 = new Font("MS Shell Dlg", 0, 11); Font f121 = new Font("MS Shell Dlg", 0, 12); /*Edit menu*/ jmenuEdit = new JMenu("Edit"); jmenuEdit.setFont(f12); jmenuEdit.setMnemonic(KeyEvent.VK_F); jmenuitemCopy = new JMenuItem(" Copy"); jmenuitemCopy.setFont(f121); jmenuitemCopy.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_C, ActionEvent.CTRL_MASK)); jmenuitemPaste = new JMenuItem(" Paste"); jmenuitemPaste.setFont(f121); jmenuitemPaste.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_V, ActionEvent.CTRL_MASK)); jmenuEdit.add(jmenuitemCopy); jmenuEdit.add(jmenuitemPaste); /*View menu*/ jmenuView = new JMenu("View"); jmenuView.setFont(f12); jmenuView.setMnemonic(KeyEvent.VK_H); jmenuitemStandard = new JMenuItem(" Standard"); jmenuitemStandard.setFont(f121); jmenuitemScientific = new JMenuItem(" Scientific"); jmenuitemScientific.setFont(f121); jmenuitemDigit = new JMenuItem(" Digital grouping"); jmenuitemDigit.setFont(f121); jmenuView.add(jmenuitemStandard); jmenuView.add(jmenuitemScientific); jmenuView.add(jmenuitemDigit); /*Help menu*/ jmenuHelp = new JMenu("Help"); jmenuHelp.setFont(f12); jmenuHelp.setMnemonic(KeyEvent.VK_H); jmenuitemHelp = new JMenuItem(" Help Topics"); jmenuitemHelp.setFont(f121); jmenuitemHelp.addActionListener(this); jmenuitemAbout = new JMenuItem(" About calculator"); jmenuitemAbout.setFont(f121); jmenuitemAbout.addActionListener(this); jmenuHelp.add(jmenuitemHelp); jmenuHelp.add(jmenuitemAbout); JMenuBar mb = new JMenuBar(); mb.add(jmenuEdit); mb.add(jmenuView); mb.add(jmenuHelp); //setJMenuBar(mb); // Add components to frame add(mb,BorderLayout.NORTH); JPanel jplBackSpace, jplControl, jplButtons; jplButtons = new JPanel(); // Set jplButton panel layout manager for a 4 by 5 grid jplButtons.setLayout(new GridLayout(4, 5, 6, 6)); jplButtons.setBorder(new EmptyBorder(4, 12, 0, 0)); // Create numeric Jbuttons but1 = new JButton("1"); but1.setMargin(new Insets(0, 0, 0, 0)); but1.setFont(f12); but1.setForeground(Color.blue); but1.setBackground(new Color(242,243,238)); but1.setBorder(new RoundedBorder(10)); but1.addActionListener(this); but2 = new JButton("2"); but2.setMargin(new Insets(0, 0, 0, 0)); but2.setFont(f12); but2.setForeground(Color.blue); but2.setBackground(new Color(242,243,238)); but2.addActionListener(this); but3 = new JButton("3"); but3.setMargin(new Insets(0, 0, 0, 0)); but3.setFont(f12); but3.setForeground(Color.blue); but3.setBackground(new Color(242,243,238)); but3.addActionListener(this); but4 = new JButton("4"); but4.setMargin(new Insets(0, 0, 0, 0)); but4.setFont(f12); but4.setForeground(Color.blue); but4.setBackground(new Color(242,243,238)); but4.addActionListener(this); but5 = new JButton("5"); but5.setMargin(new Insets(0, 0, 0, 0)); but5.setFont(f12); but5.setForeground(Color.blue); but5.setBackground(new Color(242,243,238)); but5.addActionListener(this); but6 = new JButton("6"); but6.setMargin(new Insets(0, 0, 0, 0)); but6.setFont(f12); but6.setForeground(Color.blue); but6.setBackground(new Color(242,243,238)); but6.addActionListener(this); but7 = new JButton("7"); but7.setMargin(new Insets(0, 0, 0, 0)); but7.setFont(f12); but7.setForeground(Color.blue); but7.setBackground(new Color(242,243,238)); but7.addActionListener(this); but8 = new JButton("8"); but8.setMargin(new Insets(0, 0, 0, 0)); but8.setFont(f12); but8.setForeground(Color.blue); but8.setBackground(new Color(242,243,238)); but8.addActionListener(this); but9 = new JButton("9"); but9.setMargin(new Insets(0, 0, 0, 0)); but9.setFont(f12); but9.setForeground(Color.blue); but9.setBackground(new Color(242,243,238)); but9.addActionListener(this); but0 = new JButton("0"); but0.setMargin(new Insets(0, 0, 0, 0)); but0.setFont(f12); but0.setForeground(Color.blue); but0.setBackground(new Color(242,243,238)); but0.addActionListener(this); // Create operator Jbuttons but10 = new JButton("+/-"); but10.setMargin(new Insets(0, 0, 0, 0)); but10.setFont(f12); but10.setForeground(Color.blue); but10.setBackground(new Color(242,243,238)); but10.addActionListener(this); but11 = new JButton("."); but11.setMargin(new Insets(0, 0, 0, 0)); but11.setFont(f12); but11.setForeground(Color.blue); but11.setBackground(new Color(242,243,238)); but11.addActionListener(this); but12 = new JButton("="); but12.setMargin(new Insets(0, 0, 0, 0)); but12.setFont(f12); but12.setForeground(Color.red); but12.setBackground(new Color(242,243,238)); but12.addActionListener(this); but13 = new JButton("/"); but13.setMargin(new Insets(0, 0, 0, 0)); but13.setFont(f12); but13.setForeground(Color.red); but13.setBackground(new Color(242,243,238)); but13.addActionListener(this); but14 = new JButton("*"); but14.setMargin(new Insets(0, 0, 0, 0)); but14.setFont(f12); but14.setForeground(Color.red); but14.setBackground(new Color(242,243,238)); but14.addActionListener(this); but15 = new JButton("-"); but15.setFont(f12); but15.setForeground(Color.red); but15.setMargin(new Insets(0, 0, 0, 0)); but15.setBackground(new Color(242,243,238)); but15.addActionListener(this); but16 = new JButton("+"); but16.setFont(f12); but16.setForeground(Color.red); but16.setMargin(new Insets(0, 0, 0, 0)); but16.setBackground(new Color(242,243,238)); but16.addActionListener(this); but17 = new JButton("sqrt"); but17.setFont(f12); but17.setForeground(Color.blue); but17.setMargin(new Insets(0, 0, 0, 0)); but17.setBackground(new Color(242,243,238)); but17.addActionListener(this); but18 = new JButton("1/x"); but18.setFont(f12); but18.setForeground(Color.blue); but18.setMargin(new Insets(0, 0, 0, 0)); but18.setBackground(new Color(242,243,238)); but18.addActionListener(this); but19 = new JButton("%"); but19.setFont(f12); but19.setForeground(Color.blue); but19.setMargin(new Insets(0, 0, 0, 0)); but19.setBackground(new Color(242,243,238)); but19.addActionListener(this); //panel is the main Jpanel, so it contains jplControl, jplControl2, JButtons JPanel panel = new JPanel(new BorderLayout(0, 0)); getContentPane().add(panel, BorderLayout.CENTER); panel.setBorder(new EmptyBorder(3, 9, 10, 9)); // panel.setBackground(Color.yellow); //output numbers, result of calculations LabelOutPut = new JLabel("0"); LabelOutPut.setHorizontalAlignment(JLabel.RIGHT); LabelOutPut.setBackground(Color.WHITE); LabelOutPut.setFont(f121); LabelOutPut.setOpaque(true); LabelOutPut.setPreferredSize(new Dimension(200,23)); LabelOutPut.setBorder(loweredbevel); panel.add(LabelOutPut, BorderLayout.NORTH); /* JFormattedTextField formattedTextField = new JFormattedTextField(); panel.add(formattedTextField, BorderLayout.NORTH); formattedTextField.setHorizontalAlignment(JFormattedTextField.RIGHT); formattedTextField.setPreferredSize(new Dimension(105,22)); panel.add(formattedTextField,BorderLayout.NORTH); */ //text field for MC, MR, MS, M+ /* JFormattedTextField MemoryTextfield = new JFormattedTextField(); MemoryTextfield.setBackground(new Color(237,237,237)); MemoryTextfield.setPreferredSize(new Dimension(27,26)); */ MemoryTextfield = new JLabel(""); MemoryTextfield.setHorizontalAlignment(JLabel.CENTER); MemoryTextfield.setBackground(new Color(237,237,237)); MemoryTextfield.setFont(f121); MemoryTextfield.setOpaque(true); MemoryTextfield.setPreferredSize(new Dimension(27,27)); MemoryTextfield.setBorder(loweredbevel); panel.add(LabelOutPut, BorderLayout.NORTH); JPanel panel_1 = new JPanel(); panel_1.setBorder(new EmptyBorder(0, 0, 0, 0)); panel.add(panel_1, BorderLayout.CENTER); panel_1.setLayout(new BorderLayout(0, 0)); //Add buttons to keypad panel // First row jplButtons.add(but7); jplButtons.add(but8); jplButtons.add(but9); // add button / and sqrt jplButtons.add(but13); jplButtons.add(but17); // Second row jplButtons.add(but4); jplButtons.add(but5); jplButtons.add(but6); // add button * and x^2 jplButtons.add(but14); jplButtons.add(but19); // Third row jplButtons.add(but1); jplButtons.add(but2); jplButtons.add(but3); //adds button - and % jplButtons.add(but15); jplButtons.add(but18); //Fourth Row // add 0, +/-, ., +, and = jplButtons.add(but0); jplButtons.add(but10); jplButtons.add(but11); jplButtons.add(but16); jplButtons.add(but12); //Add jPanel jplButtons to jPanel panel_1 panel_1.add(jplButtons, BorderLayout.CENTER); //jplControl is responsible for Backspace, CE, C jplControl = new JPanel(); FlowLayout flowLayout = (FlowLayout) jplControl.getLayout(); flowLayout.setAlignment(FlowLayout.RIGHT); jplControl.setBorder(new EmptyBorder(6, 0, 0, 0)); //jplControl.setBackground(Color.red); panel_1.add(jplControl, BorderLayout.NORTH); //buttons inside the jplControl but20 = new JButton("Backspace"); but20.setMargin(new Insets(3, 1, 3, 1)); but20.setFont(f12); but20.setForeground(Color.red); but20.setBackground(new Color(242,243,238)); but20.addActionListener(this); but21 = new JButton("CE"); but21.setMargin(new Insets(3, 18, 3, 18)); but21.setFont(f121); but21.setForeground(Color.red); but21.setBackground(new Color(242,243,238)); but21.addActionListener(this); but22 = new JButton("C"); but22.setMargin(new Insets(3, 21, 3, 21)); but22.setFont(f121); but22.setForeground(Color.red); but22.setBackground(new Color(242,243,238)); but22.addActionListener(this); JLabel emptySpace = new JLabel(" "); jplControl.add(MemoryTextfield); // jplControl.add(emptySpace); jplControl.add(emptySpace); jplControl.add(but20); jplControl.add(but21); jplControl.add(but22); //jplControl2 is responsible for MC, MR, MS, M+ JPanel memoryPanel = new JPanel(); memoryPanel.setBorder(new EmptyBorder(2, 0, 0, 0)); JPanel jplControl2 = new JPanel(new GridLayout(4, 1, 7, 7)); panel_1.add(jplControl2, BorderLayout.WEST); jplControl2.setBorder(new EmptyBorder(3, 0, 0, 0)); butM1 = new JButton("MC"); butM1.setMargin(new Insets(9, 4, 8, 4)); butM1.setFont(f121); butM1.setForeground(Color.red); butM1.setBackground(new Color(242,243,238)); butM1.addActionListener(this); butM2 = new JButton("MR"); butM2.setMargin(new Insets(9, 4, 8, 4)); butM2.setFont(f121); butM2.setForeground(Color.red); butM2.setBackground(new Color(242,243,238)); butM2.addActionListener(this); butM3 = new JButton("MS"); butM3.setMargin(new Insets(9, 4, 8, 4)); butM3.setFont(f121); butM3.setForeground(Color.red); butM3.setBackground(new Color(242,243,238)); butM3.addActionListener(this); butM4 = new JButton("M+"); butM4.setMargin(new Insets(9, 4, 8, 4)); butM4.setFont(f121); butM4.setForeground(Color.red); butM4.setBackground(new Color(242,243,238)); butM4.addActionListener(this); jplControl2.add(butM1); jplControl2.add(butM2); jplControl2.add(butM3); jplControl2.add(butM4); } public void actionPerformed(ActionEvent e){ double result = 0; if(e.getSource() == jmenuitemAbout){ JDialog dlgAbout = new AboutDialog(this, "About Calculator", true); dlgAbout.setVisible(true); }else if(e.getSource() == jmenuitemHelp){ JDialog dlgHelp = new HelpDialog(this, "Calculator - Help", true); dlgHelp.setVisible(true); //System.exit(0); } if(e.getSource() == but1) { addDigitToDisplay(1); } else if(e.getSource() == but2) { addDigitToDisplay(2); } else if(e.getSource() == but3) { addDigitToDisplay(3); } else if(e.getSource() == but4) { addDigitToDisplay(4); } else if(e.getSource() == but5) { addDigitToDisplay(5); } else if(e.getSource() == but6) { addDigitToDisplay(6); } else if(e.getSource() == but7) { addDigitToDisplay(7); } else if(e.getSource() == but8) { addDigitToDisplay(8); } else if(e.getSource() == but9) { addDigitToDisplay(9); } else if(e.getSource() == but0) { addDigitToDisplay(0); } // +/- else if(e.getSource() == but10) { processSignChange(); } // decimal point else if(e.getSource() == but11) { addDecimalPoint(); } // = else if(e.getSource() == but12) { processEquals(); } // divide else if(e.getSource() == but13) { processOperator("/"); } // * else if(e.getSource() == but14) { processOperator("*"); } // - else if(e.getSource() == but15) { processOperator("-"); } // + else if(e.getSource() == but16) { processOperator("+"); } // sqrt else if(e.getSource() == but17) { if (displayMode != ERROR_MODE) { try { if (getDisplayString().indexOf("-") == 0) displayError("Invalid input for function!"); result = Math.sqrt(getNumberInDisplay()); displayResult(result); } catch(Exception ex) { displayError("Invalid input for function!"); displayMode = ERROR_MODE; } } } // 1/x else if(e.getSource() == but18) { if (displayMode != ERROR_MODE){ try { if (getNumberInDisplay() == 0) displayError("Cannot divide by zero!"); result = 1 / getNumberInDisplay(); displayResult(result); } catch(Exception ex) { displayError("Cannot divide by zero!"); displayMode = ERROR_MODE; } } } // % else if(e.getSource() == but19) { if (displayMode != ERROR_MODE){ try { result = getNumberInDisplay() / 100; displayResult(result); } catch(Exception ex) { displayError("Invalid input for function!"); displayMode = ERROR_MODE; } } } // backspace else if(e.getSource() == but20) { if (displayMode != ERROR_MODE){ setDisplayString(getDisplayString().substring(0, getDisplayString().length() - 1)); if (getDisplayString().length() < 1) setDisplayString("0"); } } // CE else if(e.getSource() == but21) { clearExisting(); } // C else if(e.getSource() == but22) { clearAll(); } // MC else if(e.getSource() == butM1) { m1 = 0; MemoryTextfield.setText(""); LabelOutPut.getText(); } // MR else if(e.getSource() == butM2) { LabelOutPut.setText(""); LabelOutPut.setText(LabelOutPut.getText() + m1); LabelOutPut.getText(); clearOnNextDigit = true; } // MS else if(e.getSource() == butM3) { m1 = Double.parseDouble(LabelOutPut.getText()); LabelOutPut.setText(""); LabelOutPut.setText(LabelOutPut.getText() + m1); MemoryTextfield.setText("M"); LabelOutPut.getText(); clearOnNextDigit = true; } // M+ else if(e.getSource() == butM4) { if (k == 1) { m1 = Double.parseDouble(LabelOutPut.getText()); k++; } else { m1 += Double.parseDouble(LabelOutPut.getText()); LabelOutPut.setText("" + m1); } } } void setDisplayString(String s){ LabelOutPut.setText(s); } String getDisplayString (){ return LabelOutPut.getText(); } void addDigitToDisplay(int digit){ if (clearOnNextDigit) setDisplayString(""); String inputString = getDisplayString(); if (inputString.indexOf("0") == 0){ inputString = inputString.substring(1); } if ((!inputString.equals("0") || digit > 0) && inputString.length() < MAX_INPUT_LENGTH){ setDisplayString(inputString + digit); } displayMode = INPUT_MODE; clearOnNextDigit = false; } void addDecimalPoint(){ displayMode = INPUT_MODE; if (clearOnNextDigit) setDisplayString(""); String inputString = getDisplayString(); // If the input string already contains a decimal point, don't // do anything to it. if (inputString.indexOf(".") < 0) setDisplayString(new String(inputString + ".")); } void processSignChange(){ if (displayMode == INPUT_MODE) { String input = getDisplayString(); if (input.length() > 0 && !input.equals("0")) { if (input.indexOf("-") == 0) setDisplayString(input.substring(1)); else setDisplayString("-" + input); } } else if (displayMode == RESULT_MODE) { double numberInDisplay = getNumberInDisplay(); if (numberInDisplay != 0) displayResult(-numberInDisplay); } } void clearAll() { setDisplayString("0"); lastOperator = "0"; lastNumber = 0; displayMode = INPUT_MODE; clearOnNextDigit = true; } void clearExisting(){ setDisplayString("0"); clearOnNextDigit = true; displayMode = INPUT_MODE; } double getNumberInDisplay() { String input = LabelOutPut.getText(); return Double.parseDouble(input); } void processOperator(String op) { if (displayMode != ERROR_MODE) { double numberInDisplay = getNumberInDisplay(); if (!lastOperator.equals("0")) { try { double result = processLastOperator(); displayResult(result); lastNumber = result; } catch (DivideByZeroException e) { } } else { lastNumber = numberInDisplay; } clearOnNextDigit = true; lastOperator = op; } } void displayResult(double result){ setDisplayString(Double.toString(result)); lastNumber = result; displayMode = RESULT_MODE; clearOnNextDigit = true; } void processEquals(){ double result = 0; if (displayMode != ERROR_MODE){ try { result = processLastOperator(); displayResult(result); } catch (DivideByZeroException e) { displayError("Cannot divide by zero!"); } lastOperator = "0"; } } double processLastOperator() throws DivideByZeroException { double result = 0; double numberInDisplay = getNumberInDisplay(); if (lastOperator.equals("/")) { if (numberInDisplay == 0) throw (new DivideByZeroException()); result = lastNumber / numberInDisplay; } if (lastOperator.equals("*")) result = lastNumber * numberInDisplay; if (lastOperator.equals("-")) result = lastNumber - numberInDisplay; if (lastOperator.equals("+")) result = lastNumber + numberInDisplay; return result; } void displayError(String errorMessage){ setDisplayString(errorMessage); lastNumber = 0; displayMode = ERROR_MODE; clearOnNextDigit = true; } public static void setNativeLookAndFeel() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { System.out.println("Error setting native LAF: " + e); } } public static void main(String Args[]){ Calculator calc = new Calculator(); calc.setTitle("Calculator"); calc.pack(); calc.setLocation(400, 250); calc.setVisible(true); calc.setSize(270,265); calc.setResizable(true); calc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); calc.clearAll(); calc.setNativeLookAndFeel(); //Add panel and Menu bar to frame } } class RoundedBorder implements Border { int radius; RoundedBorder(int radius) { this.radius = radius; } public Insets getBorderInsets(Component c) { return new Insets(this.radius+1, this.radius+1, this.radius+2, this.radius); } public boolean isBorderOpaque() { return true; } public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { g.setColor(Color.GRAY); g.drawRoundRect(x,y,width-1,height-1,radius,radius); } } class DivideByZeroException extends Exception{ public DivideByZeroException() { super(); } public DivideByZeroException(String s) { super(s); } } class AboutDialog extends JDialog implements ActionListener { JButton jbnOk; Font f121 = new Font("MS Shell Dlg", 0, 12); AboutDialog(JFrame parent, String title, boolean modal){ super(parent, title, modal); setBackground(new Color(242,243,238)); JPanel p1 = new JPanel(new BorderLayout(0, 0)); p1.setBorder(new EmptyBorder(0, 0, 0, 0)); StringBuffer text = new StringBuffer(); text.append("Java Swing Calculator\n\n"); text.append("This calculator has been developed for a college course \nassignment and is an open source software.\n\nIts source code is licensed for copy and/or modification.\nSo feel free to adapt it to your own needs.\n\n"); text.append("Version: 1.0\n"); text.append("Developer: Miguel\n"); text.append("Contact: miguel@procopio.co.uk\n"); text.append("______________________________________________\n"); text.append("Procopio Web Solutions - 0843 289 2986\n"); JLabel calcImg = new JLabel(new ImageIcon("6039.png")); calcImg.setBorder(new EmptyBorder(0, 15, 0, 0)); JLabel AboutImg = new JLabel(new ImageIcon("AboutIMG.png")); JTextArea jtAreaAbout = new JTextArea(2, 21); jtAreaAbout.setText(text.toString()); jtAreaAbout.setFont(f121); jtAreaAbout.setEditable(false); jtAreaAbout.setBackground(null); jtAreaAbout.setBorder(new EmptyBorder(15, 15, 0, 0)); p1.add(AboutImg, BorderLayout.NORTH); p1.add(calcImg, BorderLayout.WEST); p1.add(jtAreaAbout); getContentPane().add(p1, BorderLayout.CENTER); JPanel p2 = new JPanel(new FlowLayout(FlowLayout.CENTER)); jbnOk = new JButton(" OK "); jbnOk.addActionListener(this); p2.add(jbnOk); getContentPane().add(p2, BorderLayout.SOUTH); setLocation(300, 200); setResizable(false); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { Window aboutDialogWindow = e.getWindow(); aboutDialogWindow.dispose(); } } ); pack(); } public void actionPerformed(ActionEvent e) { if(e.getSource() == jbnOk) { this.dispose(); } } } // Help Menu Item class HelpDialog extends JDialog implements ActionListener { JButton jbnOk; Font f121 = new Font("MS Shell Dlg", 0, 12); HelpDialog(JFrame parent, String title, boolean modal){ super(parent, title, modal); setBackground(new Color(242,243,238)); JPanel p1 = new JPanel(new BorderLayout(0, 0)); p1.setBorder(new EmptyBorder(0, 0, 0, 0)); StringBuffer text = new StringBuffer(); text.append("Java Swing Calculator Overview\n\n"); text.append("You can use this calculator to perform any of the standard \noperations for which you would normally use a handheld \ncalculator. \n\nThis calculator performs basic arithmetic, such as addition, \nsubtraction, multiplication and division as well as functions. \n\nButtons definitions:\n\n"); text.append("/ Divide MC Memory Clear\n"); text.append("* Multiply MR Memory Remind\n"); text.append("- Minus MS Memory Save\n"); text.append("+ Addition M+ Memory Add\n\n"); text.append("sqrt = Square Root C Clear\n"); text.append("% = Percentage CE Clear Existing\n"); text.append("1/x - Reciprocal\n"); text.append("______________________________________________\n"); text.append("Help Line - 0843 289 2986\n"); JLabel calcImg = new JLabel(new ImageIcon("6039.png")); calcImg.setBorder(new EmptyBorder(0, 15, 0, 0)); JLabel AboutImg = new JLabel(new ImageIcon("AboutIMG.png")); JTextArea jtAreaHelp = new JTextArea(2, 21); jtAreaHelp.setText(text.toString()); jtAreaHelp.setFont(f121); jtAreaHelp.setEditable(false); jtAreaHelp.setBackground(null); jtAreaHelp.setBorder(new EmptyBorder(15, 15, 0, 0)); p1.add(AboutImg, BorderLayout.NORTH); p1.add(calcImg, BorderLayout.WEST); p1.add(jtAreaHelp); getContentPane().add(p1, BorderLayout.CENTER); JPanel p2 = new JPanel(new FlowLayout(FlowLayout.CENTER)); jbnOk = new JButton(" OK "); jbnOk.addActionListener(this); p2.add(jbnOk); getContentPane().add(p2, BorderLayout.SOUTH); setLocation(300, 100); setResizable(false); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { Window aboutDialogWindow = e.getWindow(); aboutDialogWindow.dispose(); } } ); pack(); } public void actionPerformed(ActionEvent e) { if(e.getSource() == jbnOk) { this.dispose(); } } }