Question: Need someone to edit this code to look like the calculator below. FOR HELP BUTTON YOU CAN GET IMAGE OF HELP OPTION ON WINDOW CALCULATOR.
Need someone to edit this code to look like the calculator below.
FOR HELP BUTTON YOU CAN GET IMAGE OF HELP OPTION ON WINDOW CALCULATOR. DONT NEED TO CREAT "HELP" PROGRAM.

Disable Dword, Word, Byte, but keep the buttons there. Also, no interaction of the mouse on the binary bits area is required. Just display 64 bits for all the items with appropriate bits filled in based on the value in the number field.
Code:
import java.awt.*; import java.awt.datatransfer.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*;
public class Completecalculator extends JFrame { //====================================================================== // [DATA] Static class instance data fields. private static final int BUTTON_WIDTH = 50; private static final int BUTTON_HEIGHT = 30; private static final int HZ_MARGIN = 8; private static final int VT_MARGIN = 8; private static final int PAD_OFFSET_X = 15; private static final int PAD_OFFSET_Y = 85; private static final int PAD_GRID_ROW = 6; private static final int PAD_GRID_COL = 10; private static final Font GLOBAL_FONT = new Font("Lucida Sans Unicode", Font.PLAIN, 13); private static final Font MENU_FONT = new Font("Verdana", Font.PLAIN, 13); private static final Font SCREEN_FONT = new Font("Cambria Math", Font.PLAIN, 24); private static final Insets NO_INSETS = new Insets(0, 0, 0, 0); private static final Color BG_GENERIC = new Color(217, 228, 241); private static final Color BG_SCREEN = new Color(238, 242, 247);
private final JLabel[] scrLabels = new JLabel[3]; private final JButton[] buttons = new JButton[54]; private final design_Calculator calc = new design_Calculator(); private String numMode = null; private String sysMode = null;
//====================================================================== // [FUNC] Program's main entry point of execution. public static void main(String[] args) { new Completecalculator().launchFrame(); }
//====================================================================== // [FUNC] Primary constructor for the program frame. public Completecalculator() { this.setLayout(null); this.setResizable(false); this.setSize(608, 373); this.setTitle("design_Calculator"); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.drawVisualComponents(); this.getContentPane().setBackground(BG_GENERIC); }
//====================================================================== // [FUNC] Draws the various visual components of the JFrame. private void drawVisualComponents() { JMenuBar menuBar = new JMenuBar(); JMenu[] menus = new JMenu[4]; JMenuItem[] menuItems = null; JPanel scrPanel = new JPanel(); JPanel hexPanel = new JPanel(); ButtonGroup buttonGroup = null; JRadioButton[] radioButtons = new JRadioButton[4]; String[] texts = { design_Calculator.DGA, design_Calculator.MCX, design_Calculator.MRX, design_Calculator.MSX, design_Calculator.MPX, design_Calculator.MMX, design_Calculator.XXX, design_Calculator.NLG, design_Calculator.BR1, design_Calculator.BR2, design_Calculator.DGB, design_Calculator.BSP, design_Calculator.CEX, design_Calculator.CXX, design_Calculator.NEG, design_Calculator.SRT, design_Calculator.AVG, design_Calculator.SIN, design_Calculator.FCT, design_Calculator.SQR, design_Calculator.DGC, design_Calculator.DG7, design_Calculator.DG8, design_Calculator.DG9, design_Calculator.DIV, design_Calculator.PER, design_Calculator.SUM, design_Calculator.COS, design_Calculator.CRT, design_Calculator.CUB, design_Calculator.DGD, design_Calculator.DG4, design_Calculator.DG5, design_Calculator.DG6, design_Calculator.MUL, design_Calculator.REC, design_Calculator.LST, design_Calculator.TAN, design_Calculator.INT, design_Calculator.POW, design_Calculator.DGE, design_Calculator.DG1, design_Calculator.DG2, design_Calculator.DG3, design_Calculator.SUB, design_Calculator.EQU, design_Calculator.CLS, design_Calculator.LOG, design_Calculator.MOD, design_Calculator.PWT, design_Calculator.DGF, design_Calculator.DG0, design_Calculator.DOT, design_Calculator.ADD}; this.setJMenuBar(menuBar); for (int i = 0; i 0 && i = PAD_GRID_COL) { x = 0; y++; } } this.getContentPane().add(scrPanel); this.getContentPane().add(hexPanel); }
private void sendKey(String key) { calc.inputKey(key); if (key != design_Calculator.GRP) { scrLabels[0].setText(calc.hasMemValue() ? "M" : ""); if (key != design_Calculator.MSX) scrLabels[1].setText(calc.getSecScreenText()); buttons[6].setText(calc.getSetSize() + ""); } scrLabels[2].setText(calc.Text_getPrmScreen()); }
private void Mode_setSys(String mode) { boolean b = mode == design_Calculator.SCI; for (int i = 6; i 6 ? i : 7; j
private void Mode_setNum(String mode) { switch (mode) { case design_Calculator.HEX: setDecEnabled(true); setHexEnabled(true); break; case design_Calculator.DEC: setDecEnabled(true); setHexEnabled(false); break; case design_Calculator.OCT: setDecEnabled(true); setHexEnabled(false); for (int i : new int[]{22, 23}) buttons[i].setEnabled(false); break; case design_Calculator.BIN: setDecEnabled(false); setHexEnabled(false); break; } buttons[52].setEnabled(mode == design_Calculator.DEC); numMode = mode; calc.inputKey(mode); }
private void setDecEnabled(boolean b) { int[] arr = {21, 22, 23, 31, 32, 33, 42, 43}; for (int i : arr) buttons[i].setEnabled(b); }
private void setHexEnabled(boolean b) { for (int i = 0; i
public void launchFrame() { //this.pack(); Mode_setSys(design_Calculator.STD); Mode_setNum(design_Calculator.DEC); this.setVisible(true); } }
//////////////////////////////////////////////////////
import java.math.BigDecimal; import java.util.ArrayList;
public class design_Calculator { public static final String SCI = "Scientific"; // Scientific Mode public static final String STD = "Standard"; // Standard Mode public static final String GRP = "Digit Grouping"; // Digit Grouping
public static final String HEX = "Hex"; // Hexadecimal public static final String DEC = "Dec"; // Decimal public static final String OCT = "Oct"; // Octal public static final String BIN = "Bin"; // Binary
public static final String MCX = "MC"; // Memory Clear public static final String MRX = "MR"; // Memory Recall public static final String MSX = "MS"; // Memory Store public static final String MPX = "M+"; // Memory Add public static final String MMX = "M-"; // Memory Subtract
public static final String XXX = null; // Reserved public static final String NLG = "ln"; // Natural Logarithm public static final String BR1 = "("; // Bracket Open public static final String BR2 = ")"; // Bracket Close public static final String BSP = "\u2190"; // Backspace public static final String CEX = "CE"; // Clear Entry public static final String CXX = " C "; // Clear
public static final String SIN = "sin"; // Sine public static final String COS = "cos"; // Cosine public static final String TAN = "tan"; // Tangent public static final String NEG = "\u00b1"; // Negate public static final String REC = "1/x"; // Reciprocal public static final String INT = "int"; // Integral public static final String LOG = "log"; // Logarithm public static final String PWT = "10\u02E3"; // X Power of Ten public static final String F2E = "F-E"; // Fine to Exponential public static final String EXP = "Exp"; // Exponential
public static final String SRT = "\u221a"; // Square Root public static final String CRT = "\u221bx"; // Cube Root public static final String SQR = "x\u00b2"; // Squared public static final String CUB = "x\u00b3"; // Cubed public static final String FCT = "n!"; // Factorial public static final String PER = "%"; // Percentage public static final String DMS = "dms"; // DMS public static final String POW = "x\u02B8"; // Power
public static final String DG0 = "0"; // Digit 0 public static final String DG1 = "1"; // Digit 1 public static final String DG2 = "2"; // Digit 2 public static final String DG3 = "3"; // Digit 3 public static final String DG4 = "4"; // Digit 4 public static final String DG5 = "5"; // Digit 5 public static final String DG6 = "6"; // Digit 6 public static final String DG7 = "7"; // Digit 7 public static final String DG8 = "8"; // Digit 8 public static final String DG9 = "9"; // Digit 9 public static final String DOT = "."; // Dot/Point
public static final String DGA = "A"; // Hex digit A public static final String DGB = "B"; // Hex digit B public static final String DGC = "C"; // Hex digit C public static final String DGD = "D"; // Hex digit D public static final String DGE = "E"; // Hex digit E public static final String DGF = "F"; // Hex digit F
public static final String MUL = "\u00D7"; // Multiply public static final String DIV = "\u00F7"; // Divide public static final String MOD = "mod"; // Modulus public static final String ADD = "\u002B"; // Add public static final String SUB = "\u2212"; // Subtract public static final String EQU = "\u003D"; // Equal to
public static final String PIX = "\u03C0"; // Constant PI public static final String AVG = "\u03BC"; // Statistical Average public static final String SUM = "\u2211"; // Statistical Sum public static final String LST = "lst"; // Statistical Add public static final String CLS = "clr"; // Clear stat list
//====================================================================== // [DATA] Class instance data fields. private Logic_Cal[] expr = null; private String memValue = null; private String prmScreenText = null; private boolean clearPrmScreen = false; private boolean groupDigits = false; private boolean hasError = false; private String numMode = null; private String lastKey = null; private ArrayList nset = null;
//====================================================================== // [FUNC] Primary class constructor. public design_Calculator() { expr = new Logic_Cal[2]; nset = new ArrayList(); for (int i = 0; i
private void initFields() { clear(); prmScreenText = "0"; clearPrmScreen = true; hasError = false; lastKey = null; }
private boolean isDigit(String val) { return val == DG0 || val == DG1 || val == DG2 || val == DG3 || val == DG4 || val == DG5 || val == DG6 || val == DG7 || val == DG8 || val == DG9 || val == DGA || val == DGB || val == DGC || val == DGD || val == DGE || val == DGF; }
public boolean hasMemValue() { return memValue != "0"; }
public int getSetSize() { return nset.size(); }
public String getSecScreenText() { return expr[1] + (lastKey == EQU ? " =" : ""); }
public String Text_getPrmScreen() { if (!hasError && groupDigits) { if (numMode == BIN || numMode == HEX) return groupText(prmScreenText, 4, " "); else if (numMode == OCT) return groupText(prmScreenText, 3, " "); else return groupText(prmScreenText, 3, ","); } return prmScreenText; }
private static String dec2rad(String str, BigDecimal rad) { BigDecimal bd = new BigDecimal(str); String ret = ""; int rem = 0; bd = bd.setScale(0, BigDecimal.ROUND_DOWN); while (bd.compareTo(BigDecimal.ZERO) > 0) { rem = bd.remainder(rad).intValue(); if (rem >= 0 && rem = 10) ret = (char) (rem + 'A' - 10) + ret; bd = bd.divide(rad, 0, BigDecimal.ROUND_DOWN); } return ret == "" ? "0" : ret; }
private static String rad2dec(String str, BigDecimal rad) { BigDecimal bd = new BigDecimal(0); int chr = 0; for (int i = str.length() - 1, p = 0; i >= 0; i--, p++) { chr = Character.toUpperCase(str.charAt(i)); if (chr >= '0' && chr = 'A' && chr
private static String dec2rad(String str, String mode) { if (mode == BIN) return dec2rad(str, new BigDecimal(2)); else if (mode == OCT) return dec2rad(str, new BigDecimal(8)); else if (mode == HEX) return dec2rad(str, new BigDecimal(16)); return str; }
private static String rad2dec(String str, String mode) { if (mode == BIN) return rad2dec(str, new BigDecimal(2)); else if (mode == OCT) return rad2dec(str, new BigDecimal(8)); else if (mode == HEX) return rad2dec(str, new BigDecimal(16)); return str; }
private static String groupText(String str, int cnt, String sep) { String ret = ""; int i = 0, a = 0, z = str.lastIndexOf("."); if (z 0 && str.charAt(0) == '-') a++; for (i = z - cnt; i > a; i -= cnt) ret = sep + str.substring(i, i + cnt) + ret; return str.substring(0, i + cnt) + ret; }
private static void beep() { java.awt.Toolkit.getDefaultToolkit().beep(); }
private void clear() { for (int i = 0; i
private void push(Object obj) { expr[1].push(obj); if (obj instanceof String) { expr[0].push(rad2dec((String) obj, numMode)); } else expr[0].push(obj); }
private void pop() { expr[0].pop(); expr[1].pop(); }
private String stripZeros(String s) { if (s.indexOf(".") >= 0) while (s.length() > 1 && (s.endsWith("0") || s.endsWith("."))) s = s.substring(0, s.length() - 1); return s; }
private void throwError(String msg) { prmScreenText = msg; hasError = true; beep(); }
public void inputKey(String key) { if (hasError) { if (key == CXX || key == GRP) {} else if (key == HEX || key == DEC || key == OCT || key == BIN) initFields(); else { beep(); return; } } else if (lastKey == EQU && key != BSP) { clear(); } switch (key) { case GRP: groupDigits = !groupDigits; if (hasError) return; break; case BIN: case OCT: case DEC: case HEX: prmScreenText = dec2rad(rad2dec(prmScreenText, numMode), key); numMode = key; clearPrmScreen = true; break; case MCX: memValue = "0"; clearPrmScreen = true; break; case MRX: if (memValue != "0") prmScreenText = dec2rad(memValue, numMode); else { prmScreenText = "0"; lastKey = DG0; return; } clearPrmScreen = true; break; case MSX: memValue = rad2dec(prmScreenText, numMode); clearPrmScreen = true; break; case MPX: memValue = new BigDecimal(rad2dec(prmScreenText, numMode)).add( new BigDecimal(memValue)).toPlainString(); clearPrmScreen = true; break; case MMX: memValue = new BigDecimal(rad2dec(memValue, numMode)).subtract( new BigDecimal(prmScreenText)).toPlainString(); clearPrmScreen = true; break; case BSP: if (clearPrmScreen) { beep(); return; } else if (prmScreenText.length() > 1) prmScreenText = prmScreenText.substring(0, prmScreenText.length() - 1); else if (prmScreenText != "0") prmScreenText = "0"; else if (expr[0].hasItems()) pop(); else beep(); break; case CEX: prmScreenText = "0"; break; case CXX: this.initFields(); break; case AVG: if (nset.size() > 0) { BigDecimal bd = BigDecimal.ZERO; for (int i = 0; i
///////////////////////////////////////////////////////////////////////////////////////////
public class InvalidInputException extends Exception { public InvalidInputException() { super(); }
public InvalidInputException(String msg) { super(msg); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import java.util.ArrayList; import java.math.BigDecimal;
public class Logic_Cal { //====================================================================== // [DATA] Brackets, roots, exponents and factorial. public static final byte BRO = 0x00, BRACKET_OPEN = BRO; public static final byte BRC = 0x01, BRACKET_CLOSE = BRC; public static final byte SRT = 0x02, SQUARE_ROOT = SRT; public static final byte CRT = 0x03, CUBE_ROOT = CRT; public static final byte REC = 0x04, RECIPROCAL = REC; public static final byte SQR = 0x05, SQUARED = SQR; public static final byte CUB = 0x06, CUBED = CUB; public static final byte POW = 0x07, POWER = POW; public static final byte FCT = 0x08, FACTORIAL = FCT;
//====================================================================== // [DATA] Common mathematical functions. public static final byte SIN = 0x10, SINE = SIN; public static final byte COS = 0x11, COSINE = COS; public static final byte TAN = 0x12, TANGENT = TAN; public static final byte LOG = 0x13, LOGARITHM = LOG; public static final byte NLG = 0x14, NATURAL_LOG = NLG; public static final byte INT = 0x15, INTEGRAL = INT; public static final byte NEG = 0x16, NEGATE = NEG;
//====================================================================== // [DATA] The ubiquitous binary operators. public static final byte MUL = 0x20, MULTIPLY = MUL; public static final byte DIV = 0x21, DIVIDE = DIV; public static final byte MOD = 0x22, MODULO = MOD; public static final byte ADD = 0x23, ADDITION = ADD; public static final byte SUB = 0x24, SUBTRACTION = SUB;
//====================================================================== // [DATA] Class instance data fields. private ArrayList list = null; private Logic_Cal parent = null;
//====================================================================== // [FUNC] Primary class constructor. public Logic_Cal() { this(null); }
//====================================================================== // [FUNC] Private constructor that makes objects with parents. private Logic_Cal(Logic_Cal parent) { this.list = new ArrayList(); this.parent = parent; }
//====================================================================== // [FUNC] Returns a boolean value indicating whether this expression is // embedded within another expression. private boolean hasParent() { return this.parent != null; }
//====================================================================== // [FUNC] Returns the parent expression of this expression. private Logic_Cal getParent() { return this.parent; }
//====================================================================== // [FUNC] Returns a boolean value indicating whether the passed // parameter is an operator. private static boolean isOperator(Object obj) { byte opr = obj instanceof Byte ? (byte) obj : -1; return (opr >= BRO && opr = SIN && opr = MUL && opr
//====================================================================== // [FUNC] Returns a boolean value indicating whether the passed // parameter is an operand (just BigDecimal for now). private static boolean isOperand(Object obj) { return obj instanceof BigDecimal; }
//====================================================================== // [FUNC] Returns a boolean value indicating wheher the passed // parameter is an expression. private static boolean isLogic_Cal(Object obj) { return obj instanceof Logic_Cal; }
//====================================================================== // [FUNC] Computes and returns the factorial of the argument. private static BigDecimal factorial(BigDecimal n) { BigDecimal r = BigDecimal.ONE; while (n.compareTo(BigDecimal.ONE) > 0) { r = r.multiply(n); n = n.subtract(BigDecimal.ONE); } return r; //return n.compareTo(BigDecimal.ONE) > 0 ? // factorial(n.subtract(BigDecimal.ONE)).multiply(n) : n; }
//====================================================================== // [FUNC] Returns a boolean value indicating whether there are items on // the internal stack. public boolean hasItems() { return list.size() > 0; }
//====================================================================== // [FUNC] Adds a new item onto the internal list. // Think of it like a stack ;) public Logic_Cal push(Object ... args) { for (Object obj : args) this.list.add(obj); return this; }
//====================================================================== // [FUNC] Removes the last item (if any) from the internal stack. public Object pop() { int index = list.size() - 1; return (index >= 0) ? list.remove(index) : null; }
//====================================================================== // [FUNC] Evaluates and returns the result of this expression. public BigDecimal eval() throws SyntaxErrorException, InvalidInputException, UnknownOperatorException { Object obj = null; Logic_Cal curr = this; BigDecimal lhs = null, rhs = null; // STEP 0: Evaluate brackets to determine sub-expressions for (int i = 0; i
// STEP 2: Roots, powers, reciprocal and factorial. for (int i = 0; i 0 ? list.get(i - 1) : -1; if (isOperand(obj)) lhs = (BigDecimal) obj; else if (isLogic_Cal(obj)) lhs = ((Logic_Cal) obj).eval(); else throw new SyntaxErrorException("Missing operand"); obj = i + 1 0 ? list.get(i - 1) : -1; if (isOperand(obj)) lhs = (BigDecimal) obj; else if (isLogic_Cal(obj)) lhs = ((Logic_Cal) obj).eval(); else throw new SyntaxErrorException("Missing operand"); list.set(i - 1, BigDecimal.ONE.divide(lhs, 30, BigDecimal.ROUND_DOWN)); list.remove(i); i -= 1; break; case FACTORIAL: obj = i > 0 ? list.get(i - 1) : -1; if (isOperand(obj)) lhs = (BigDecimal) obj; else if (isLogic_Cal(obj)) lhs = ((Logic_Cal) obj).eval(); else throw new SyntaxErrorException("Missing operand"); //if (lhs.compareTo(BigDecimal.ZERO) 0) // throw new InvalidInputException("Factorial input too large (>5000)"); list.set(i - 1, factorial(lhs.setScale(0, BigDecimal.ROUND_DOWN))); list.remove(i); i -= 1; break; } } // STEP 3: Common mathematical functions. for (int i = list.size() - 1; i >= 0; i--) { obj = list.get(i); if (obj.equals(SIN) || obj.equals(COS) || obj.equals(TAN) || obj.equals(LOG) || obj.equals(NLG) || obj.equals(INT) || obj.equals(NEG)) { obj = i + 1 15) rhs = rhs.setScale(15, BigDecimal.ROUND_HALF_EVEN); list.set(i, rhs); list.remove(i + 1); } } // STEP 4: Multiplicative and additive operations. for (int s = 0; s 0 ? list.get(i - 1) : -1; if (isOperand(obj)) lhs = (BigDecimal) obj; else if (isLogic_Cal(obj)) lhs = ((Logic_Cal) obj).eval(); else throw new SyntaxErrorException("Missing operand"); obj = i + 1 0 ? list.get(i - 1) : -1; if (isOperand(obj)) { list.set(i - 1, rhs = rhs.multiply((BigDecimal) obj)); list.remove(i); i -= 1; } obj = i + 1
// STEP 4: Multiply any remaining items. A cheap way to get my math right :) // For example, 2 sin 30 == 2 * sin 30 while (list.size() > 1) { obj = list.get(0); if (isLogic_Cal(obj)) lhs = ((Logic_Cal) obj).eval(); else if (isOperand(obj)) lhs = (BigDecimal) obj; else throw new UnknownOperatorException(); obj = list.get(1); if (isLogic_Cal(obj)) rhs = ((Logic_Cal) obj).eval(); else if (isOperand(obj)) rhs = (BigDecimal) obj; else throw new UnknownOperatorException(); list.set(0, lhs.multiply(rhs)); list.remove(1); } if (list.size() == 0) throw new SyntaxErrorException("Empty " + (this.hasParent() ? "brackets" : "expression")); else if (isLogic_Cal(list.get(0))) list.set(0, ((Logic_Cal) list.get(0)).eval()); lhs = (BigDecimal) list.get(0); if (lhs.scale() > 30) lhs = lhs.setScale(30, BigDecimal.ROUND_HALF_EVEN); return lhs.stripTrailingZeros(); }
//====================================================================== // [FUNC] Returns the string representation of this expression. public String toString() { String ret = ""; Object obj = null; for (int i = 0; i 0 && (list.get(i - 1).equals(SRT) || list.get(i - 1).equals(CRT) || list.get(i - 1).equals(NEG))) ret += obj; else ret += " " + obj; } ret = ret.replaceAll("\\s\\s+", " "); ret = ret.replaceAll("\\(\\s+", "("); return ret.trim(); } }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public class SyntaxErrorException extends Exception { //====================================================================== // [FUNC] Primary class constructor with no parameters. public SyntaxErrorException() { super(); }
//====================================================================== // [FUNC] Constructor accepting exception message as parameter. public SyntaxErrorException(String msg) { super(msg); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public class UnknownOperatorException extends Exception { public UnknownOperatorException() { super(); }
public UnknownOperatorException(String msg) { super(msg); } }
Calculator View Edit Help Menu Items View -> Hide and Show the calculator Edit - Copy the Text Help ->Perform the same as the actual Windows calculator 63 47 32 31 15 0 Quot Mod A Hex Dec Oct Bin o Qword Dword E 1 23 Word 0
Step by Step Solution
There are 3 Steps involved in it
To make your Java calculator resemble the image heres a detailed guide focusing on key areas 1 Layout and Components Radio Buttons Number Systems Add ... View full answer
Get step-by-step solutions from verified subject matter experts
