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?
I want to make a calculator program as my first ever program and I've been working on the layout and I think I have it close to where I want it but will probably tweak it in the future after I get it to work. My problem is I'm trying to add a MenuBar to it but it is not showing up. I tried having it all over my code but whereever I put it the MenuBar doesn't show up.
I have to make a gpa calculator for 5 courses of grades A B+ C+ D F, and worth 4, 3.5, 3, 2.5, 2,1,0 respectively. using 10 input text boxes, and a button
Create two arrays of length 5: one to hold the numerical values of letter grades, the other to hold the number of credit hours. Initialize both to have 0’s. Write a function that takes a letter grades entered by a user and returns its numerical equivalent.
Use an ‘if…else if… else’ construct.
Write a function that can operate on the two arrays and return the GPA. Use a for loop that runs from 0 to 5, multiplies the corresponding array elements and adds them together, divides that total by the total number of credit hours, and returns that value.
Input elements:
In the first 10 textfields, use the onchange attribute to fill the arrays with user entries.
Hint: For the course grade entries it should look like
onchange= ‘array1[0] = first_function(this.value)’ etc.
The button should make the value of the last text area equal to the return value of the second function.
i have my whole code completed but when i press the button it returns the points value '0' so i think there is an error in my if else statements (ltonum function)
<DOCTYPE! html> <html> <head> <title> Assignment 9: Javascript 3 </title> <!-- Assignment 9, Due November 8, 2014, Jamie Zajac, TA Kartik--> <style> body { background-color: lemonchiffon; color: midnightblue;
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
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";
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];
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.
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
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 {
I need to do a simple while loop pay calculator. I am very new and not sure what I need to do to put all the requirements in the new code from another code. Here is my code that doesn't work yet.
1.Place the wage calculation routines in a while loop. 2.Allow the user to input an individual's hours worked. 3.Accumulate the total regular hours worked, the overtime hours worked, the amount of the regular pay, the amount of overtime pay, and the total payroll, for all of the employees entered. 4.Allow the user to enter a zero (0) as the Boolean expression to end the loop. 5.When the loop ends print out all of the accumulated totals with appropriate labels, each on a separate line.
import java.util.Scanner; public class WhileLoopPayCalc { public static void main(String [] args) { final double REGULAR_HOURS = 40f; final double HOURLY_WAGE = 12.5f; final double OVERTIME = 1.5f; double wage = 0f;
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.
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.
Our goal is to write a pretty simple program, one that takes the 12 digit UPC code entered by a user and to not only spit it back out in a format with dashes using toString, and also returns the first digit, a 2 more groups of digits numbering 2-6 and 7-11, and finally display the 12th digit. It then performs an equation to check the last digit and make sure the UPC code is correct.
However, being so new to java (I only learned visual basic before), with this I was introduced to two new concepts that for some reason I simply cannot grasp for the life of me: Using and calling the toString method, and calling on methods that are created in a completely different class file.
The first section of code is my UPC class, which is meant to contain all my methods as well as the toString to be called on:
public class UPC { // Instance variables private int itemType; // digit 1 private int manufacturer; // digits 2,3,4,5,6 private int product; // digits 7,8,9,10,11 private int checkDigit; // digit 12
How can i write a java program that simulate a simple calculator that performs the basic arithmetic operations of JAVA. (JOption Pane and Repeat control structure)
Example : Addition, Subtraction, Multiplication, Division.
The program will prompt to input two floating point numbers and a character that represents the operations presented above. In the event that the operator input is valid, prompt the user to input the operator again.
I would like to make a database using HTML and Java. I already made something like this using swing. I am just looking for some pointers here. I just started looking into Java Play 2 and I have a feeling this is what I am looking for. JavaEE is very complicated and I have read that it is being phased out. What is your opinion on this?
I want to make a static HTML page and put it on my home network and treat one of my computers as the sever accessing mySQL.
I want a completely unique GUI with unique buttons, like I could make it a giraffe if I wanted to! (not going to, but a giraffe seemed like a pretty irregular shape) ....
One of my assignments was to make a program that would read a sequence of names and then list them all.Just to be clear, it would read them all first, and then it would list them all at the same time.
i am trying to make a platform game in java and to do this im trying to make a scrolling bacground. i can get the background image to scroll. However, i cant get the image to scroll forever, here is the code.
GamePanel class ( the jpanel ) public class GamePanel extends JPanel implements ActionListener{ static ArrayList<BackGround> store = new ArrayList<BackGround>(); public GamePanel(){ setFocusable(true); Timer time = new Timer(5,this); time.start(); store.add(new BackGround(0,-200));
the problem i have is that i want the bacground to loop. however, once the first instance of the background is done scrolling it freezes and doesnt load anymore. here is the code for adding a new background to the list