Java Calculator - Making Numbers To Stay At Textfield

Jul 12, 2014

How can I make the numbers to stay at the textfield of my calculator instead of disappear like when I type 1 then hit the + sign the number 1 disappears from the textfield I would like to have this (1+1) showing in the text field and also if try to press only + , * , - , / to show error.

this is my code

public class Calculator extends javax.swing.JFrame {
private double TEMP;
private double SolveTEMP;
Boolean addBool = false;
Boolean subBool = false;
Boolean divBool = false;
Boolean mulBool = false;
String display = "";

[Code] ....

View Replies


ADVERTISEMENT

Why Cannot Change Size Of TextField In Java For Calculator Application

Jan 13, 2014

package name;swing library found in javax called to use the graphical contents.

import javax.swing.*;
//creating the contents for the calculator
public class calc {
JButton btn1= new JButton("1 ");
JButton btn2= new JButton("2");
JButton btn3= new JButton("3");

[code]....

I have tried different sizes for the 'TextField' but when I change the size, the position changes instead of the size itself.

View Replies View Related

Making Plus Sign To Add Two Numbers In Java

Mar 7, 2015

I am having a bit of trouble making the '+' add two numbers in java. For example:

When the user enters " + 4 5 " I want it to come out as " 4.00e+00 + 5.00e+00 = 9.00e+00 "

Here is what I have so far:
 
public static void main(String[] args) {
 Scanner in = new Scanner(System.in);
 while (in.hasNextDouble()) {
 double num1 = in.nextDouble();
double num2 = in.nextDouble();
String s = "";
 
[Code] .....

View Replies View Related

Java Calculator - Numbers Are Not Adding

Jul 12, 2014

So I was making a Java Calculator that only adds. The problem is that the numbers are not adding. I think it is because whatever has been clicked is not being saved to be added.

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;

[Code] .....

View Replies View Related

Making Time Calculator Work / Modulo Division Not Working

Oct 22, 2014

Prompt for the project is "Write a program that will ask the user for a number of seconds and output the equivalent period of time in days, hours, minutes, and seconds.The program should:

-Use modulo division to calculate the number of days, hours, and minutes.
-Use compound operators when making assignments.
-Proper formatting and use of comments
-Symbolic constants defined as the number of seconds in a minute, hour, and day.

For example: final int sec_in_min = 60;"

public class Mod1
{
public static void main (String[] args)
{
int sec, min, hr, day;
final int SEC_IN_MIN = 60;
final int SEC_IN_HR = 60 * 60;
final int SEC_IN_DAY = 60 * 60 * 24;
 
[code]....

View Replies View Related

Making Squares Of Numbers Without Multiplication?

Oct 22, 2014

so for my computer science class, we have the following problem:

In your documentation be sure to say which loop you thought was easier to implement for this program and why Write a program that produces the following outputs. The first line of output must be written using a For-Loop. The second, using a While-Loop and the third using a Do-Loop.

You look at the program and smile because you see that the series is just the numbers 1-10 squared...just one line is in reverse order. No problem! As you start typing you discover that the number 8 key on your keyboard is not working. For this program you are unable to use the multiplication key

So, back to the drawing board. By staring at the sequence a light comes on and you are able to quickly finish this program WITHOUT using mulitiplication (or the Math class/ solve with arithmetic operators +, - or / ) .

Sample output:

For Loop
1 4 9 16 25 36 49 64 81 100

While Loop
100 81 64 49 36 25 16 9 4 1

Do While Loop
1 4 9 16 25 36 49 64 81 100

I have the "for" done, but I did it with a "for" in the beginning but then had a multitude of nested "if" loops so that I could do 7*7=7+7+7+7+7+7+7

View Replies View Related

Making Integers Have Limited Numbers?

Aug 14, 2014

I want users to input their phone Number But I want to make sure it is a phone number so they don't just do 1 and then leave it.

public static void main(String[] args) {
// Create the Scanner
Scanner in = new Scanner(System.in);
// Create the Variables
int phone;
if(phone > 100000000000 || phone < 100000000000) {
System.err.println("Error");
}

By the Way there are 12 digits in the if statement so that is 11 0's. Because all phone numbers are 12 digits.But when I run it, it comes up with an error saying The literal 100000000000000000000 of type int is out of range.I don't know how to make it so that the int has a limited number.

View Replies View Related

Making Integers Have Limited Numbers

Aug 14, 2014

I want users to input their phone Number But I want to make sure it is a phone number so they don't just do 1 and then leave it.

public static void main(String[] args) {
// Create the Scanner
Scanner in = new Scanner(System.in);
// Create the Variables
int phone;
if(phone > 100000000000 || phone < 100000000000) {
System.err.println("Error");
}

By the Way there are 12 digits in the if statement so that is 11 0's. Because all phone numbers are 12 digits.But when I run it, it comes up with an error saying The literal 100000000000000000000 of type int is out of range.I don't know how to make it so that the int has a limited number.

View Replies View Related

JSP Calculator - Performing Basic Operations On Numbers

Jul 8, 2014

I want a simple jsp page that performs basic operations on numbers such as addition, subtraction, multiplication, division and modulus . How to run that file?

View Replies View Related

Extending Calculator - Added Function To Square Numbers

Feb 14, 2014

I am new to java and during my classes we built a basic calculator. I want to extend my calculator and added function to square numbers.Here is my program:

Java Code:

package calculator02;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

[code]...

View Replies View Related

Postfix Calculator Doesn't Compute Negative Numbers

Nov 16, 2014

My verify method also always returns false. So I'm given three classes to begin with. Calculator, Expression, and InfixExpression and they are listed below.

The goal is to create a class called PostfixExpression that extends Expression and can read and calculate postfix expressions.

My evaluate() method works for most calculations but when it needs to return a negative value it just returns the positive equivalent.

Also, my verify method always returns false and I can't pinpoint why.

Here's my current code. Some things are commented out for debugging purposes.

import java.util.Scanner;
/**
* Simple calculator that reads infix expressions and evaluates them.
*/
public class Calculator
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

[Code] .....

View Replies View Related

How To Use Validation On Label Or Textfield In Java

Apr 28, 2014

How to use validation on a label or textfield in java.

I have a textfield and i want that only username with @ sign will be taken by the program or gives an error.or a textfield that can only take numeric values or whatever the developer wants to take from user..

View Replies View Related

How To Make All Shapes Fully Stay Within Frame Border

Feb 16, 2014

I have a problem with a shape generator. It randoms the shapes just fine, I just do not know how to make all the shapes fully stay within the frames border.

RandomShapeMaker.java

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import java.util.Random;
public class RandomShapeMaker extends JPanel{
private static final Random randomShape = new Random();
public void paintComponent( Graphics g ){
super.paintComponent( g );

[Code] ....

View Replies View Related

Applet Open But Stay Blank And Error Message Appear In Terminal

Jul 29, 2014

What's wrong with my Java program? When I open it using appletviewer, the applet opens but stays blank and an error message appears in Terminal.

Java Code:

import java.applet.*;
import java.awt.*;
public class DemoColor extends Applet
{
Font littleFont = new Font("Helvetica", Font.ITALIC, 6);
public void paint(Graphics gr)

[Code] ....

Error Message:

Exception in thread "AWT-EventQueue-1" java.lang.IllegalArgumentException: Color parameter outside of expected range: Red Green Blue

at java.awt.Color.testColorValueRange(Color.java:310)
at java.awt.Color.<init>(Color.java:395)
at java.awt.Color.<init>(Color.java:369)
at DemoColor.paint(DemoColor.java:24)

[Code] ....

HTML file:

<HTML>
<APPLET CODE="DemoColor.class" WIDTH = 420 HEIGHT = 300>
</APPLET>
</HTML>

View Replies View Related

Making Dynamic Website In Java

Jul 23, 2014

This might make me look pretty silly but I was curious if there was a way to make a dynamic web page in java. Basically only using pure Java, with only HTML5, CSS and mySQL.

View Replies View Related

Making Executable From Simple Java Code

Feb 16, 2014

I am totally new to java. How to convert the below java code to an executable file?

var intInterval = 0
function importdata(){
filename = "C:1.txt";
AmiBroker1 = new ActiveXObject("Broker.Application" );
AmiBroker1.Import( 0, filename, "custom.format" );
AmiBroker1.RefreshAll();
}

It simply imports numerical data from 1.txt into an application amibroker. Also this import function has to be in a loop of 60 seconds.

View Replies View Related

Making Username All Lower Case In Java Code

Apr 21, 2014

I need the username produced by this program to be in all lower case. The code is below.

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package dcollinshw03;
import java.util.Scanner;
import java.util.Random;
public class DcollinsHW03 {
public DcollinsHW03() {

[Code] .....

View Replies View Related

Making A Window For Java Text Based Game

Jan 10, 2015

So, Iv'e been trying to make a simple Text Based RPG with Java, and it is going quite well, and my friends want to play it too but they aren't very tech savvy, so it's hard to tell them to get an IDE or use the CMD, so I wanted to know if there was a way to make my text-based game into a window, like using JFrame or something. All i need is a window that displays the text, and a bar on the bottom that lets the user input what they want (Kind of like a CMD).

I want it sort of like this window: This Pic

View Replies View Related

Calculator In Java

Oct 28, 2014

I can not this to work correctly.

public static void main(String[] args) {
FloatWrapper x1=new FloatWrapper(0);
FloatWrapper x2=new FloatWrapper(0);
do{
switch(menu()){
case 'a': if(dataInput(x1,x2)) add(x1,x2); break;
case 'b': if(dataInput(x1,x2)) subtract(x1,x2); break;

[code]....

View Replies View Related

Make A Calculator Using Java GUI

Jul 29, 2014

I am trying to make a calculator using Java GUI. I've managed to make an ActionListener and add it to a button, but I've made an error in my code that I'm unsure of how to solve. Because of how I've written the code, only one number can be placed in the text field. For example, the an ActionListener for the three button on the calculator was added to the button, but no matter how many times the user presses the button, only one 3 will appear in the text field. The code is below:

import javax.swing.*;//import the packages needed for gui
import java.awt.*;
import java.awt.event.*;
public class Calculator {
public static void main(String[] args) {
JFrame window = new JFrame("Window");//makes a JFrame
window.setSize(300,350);

[code].....

As you can see, because the compiler forces the String variable to be final, so when the user presses the button, the code simply shows how a space character and three character would look like, because the String variable can't change. How do I write my code so that every time the user presses the button, a character is added to the text field?

View Replies View Related

Build A Calculator In Java?

Aug 28, 2014

I wanted to build a calculator in java but I have a problem I wanted to when I type "plus" , go to This IF but don't go

import java.util.Scanner;
public class Session {
static String amal;

[code]....

View Replies View Related

Grading Calculator In Java Program?

Sep 26, 2014

i have a similar problem but what i need to do is to detect an exused absent of which in my notepad is represented by 00 and 0 being an unexcused absent, anyway if a student has an excused absent example a quiz for that day will be deducted from the total quizzes example if i was the teacher and had 2 quizzes of 10 items each and she was absent in one of the quizes instead of let say her score was 9 on the first quiz it should go 9/10 and if it was an unexcused absent 9+0/20 anyway this is my java code and notepad example

import java.io.*;
import java.util.*;
import java.lang.*; 
public class GradingSystem {
public static void main (String[] args) throws FileNotFoundException

[code]...

View Replies View Related

GPA Calculator In Java Using Loops And Switch

Apr 25, 2015

I am trying to make GPA calculator. I decided to use only switch statement and make it as simple as possible. The point is to enter as many classes and students as user wants. I keep getting credit points 0 at the end and also text format is not good too. Here is the code.

import java.util.Scanner;
import java.io.*;
public class SwitchExercise{
public static void main(String[] args) {
String grade = "";
String grades="";
String coursename="";
String headingleft="COURSES";

[code]....

View Replies View Related

Java Calculator - Multiplication And Division

Apr 24, 2015

I am having problems with my code I have added the multiplication and division but they will not display also how can I correct any error when dividing by zero?

import java.awt.*;
import java.awt.event.*;
public class calculator2 extends java.applet.Applet implements ActionListener {
TextField txtTotal = new TextField("");
Button button[] = new Button[10];

[Code] .....

View Replies View Related

Simple Calculator Swing Java

Dec 13, 2014

I am a beginner with Java. I have never used SWING before but I have to use it now and I am clueless. I don't know if what I am doing is right.I need to create a simple calculator. My problem is getting the buttons the user clicks to appear in a text field. I know I haven't added the =/*- buttons yet.

I have left actionPerformed practically blank, what to put in ?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* Created by IntelliJ IDEA.
* Date: 11/12/2014
* Changing Face Program.
*/
public class Calc extends JFrame implements ActionListener

[code]...

View Replies View Related

Java Calculator Using Stack Data Structure

May 21, 2014

My assignment is to design a simple GUI calculator using the stack data structure to perform additions, subtractions, multiplications and divisions. But i having error while i press the action there.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.util.Stack;
public class JCalculator implements ActionListener {

[Code] ...

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved