.

Wednesday, 11 September 2019

Java Programming Math Problem Example | Topics and Well Written Essays - 1250 words

Java Programming - Math Problem Example import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridLayout; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JOptionPane; public class Calculator extends JFrame implements ActionListener { // Variables final int MAX_INPUT_LENGTH = 20; final int INPUT_MODE = 0; final int RESULT_MODE = 1; final int ERROR_MODE = 2; int displayMode; boolean clearOnNextDigit, percent; double lastNumber; String lastOperator; private JMenu jmenuFile, jmenuEdit, jmenuView, jmenuHelp; private JMenuItem jmenuitemExit, jmenuitemCopy, jmenuitemPaste, jmenuitemStd, jmenuitemSci, jmenuitemDigitGrp, jmenuitemAbout; private JDialog dialog; private JLabel display; private JButton button[]; private JPanel masterPanel; private JTextArea textarea; Font f12 = new Font("Times New Roman", 0, 12); Font f121 = new Font("Times New Roman", 1, 12); ... jmenuitemSci = new JMenuItem("Scientific"); jmenuitemSci.setFont(f12); jmenuitemDigitGrp = new JMenuItem("Digit Grouping"); jmenuitemDigitGrp.setFont(f12); jmenuView.add(jmenuitemStd);jmenuView.add(jmenuitemSci);jmenuView.addSeparator();jmenuView.add(jmenuitemDigitGrp); jmenuHelp = new JMenu("Help"); jmenuHelp.setFont(f121); jmenuitemAbout = new JMenuItem("About Calculator"); jmenuitemAbout.setFont(f12); jmenuHelp.add(jmenuitemAbout); JMenuBar mb = new JMenuBar(); // mb.add(jmenuFile); mb.add(jmenuEdit); mb.add(jmenuView); mb.add(jmenuHelp); setJMenuBar(mb); //Set frame layout manager setBackground(Color.gray); //adds menubar to frame (end) masterPanel = new JPanel(); display = new JLabel("0"); display.setAlignmentX(JLabel.RIGHT); display.setBackground(Color.gray); Container contentPane = getContentPane(); // Add components to frame contentPane.add(display, BorderLayout.NORTH); button = new JButton[23]; JPanel backSpace = new JPanel(); backSpace.setLayout(new GridLayout(1, 1, 2, 2)); button[20] = new JButton("Backspace"); backSpace.add(button[20]); JPanel control = new JPanel(); control.setLayout(new GridLayout(1, 2, 2 ,2)); button[21] = new JButton(" CE "); button[22] = new JButton("C"); control.add(button[21]); control.add(button[22]);

No comments:

Post a Comment