Temperature Conversion Project - Send Input Value To Calculation Area And Get Value To Display In JLabel

Sep 30, 2014

The problem I'm trying to resolve now is getting my ActionEvent to send the value input in the JTextArea out to be calculated, then to display the result in my result JLabel.

Here is an image of the GUI :

The basic procedure the teacher is asking for is the user is supposed to enter a temperature in the input. The user then clicks the input scale, and then on the output scale selection the converted value is to be displayed in the output area.

As I mentioned my problem is in the sending of the input value to my calculation area, and getting the value to display in the JLabel.

How should I approach this solution? Do I need to have a listener after the JTextArea of the input box? Will that allow me to limit the input values to numbers only?

final JTextArea inputText = new JTextArea("" + (char)176,1,4);
//ReadConsole equivalent to specific input was a number?

Here is the section of code my ActionListener is:

//celOut represents the Celcius output scale JRadioButton.
celOut.addActionListener (new ActionListener () {

@Override
public void actionPerformed(ActionEvent e) {
//if the Celcius Input Scale is selected.
if(cel.isSelected())

[Code] ....

All the calculations are required to occur in a separate java file, which what I think is tripping me up. How do I send a value from the JTextArea into the Calc.celToFahr method?

//contents of my Calc.java calculation class.
public class Calc {
public static double celToFahr(double cel){
return cel * (9./5.) + 32.;
}
public static double fahrToCel(double fahr){
return (fahr - 32.)*(5./9.);
}
}

View Replies


ADVERTISEMENT

Temperature Conversion GUI Java

Apr 21, 2015

I'm having trouble getting the text entered in my JTextField to be converted to the conversion formula. The line I'm getting error in is:

String text = text.getText();

Also I created another JTextField in which I want the answer to be displayed in, but I'm not too sure how to go about that.
This is my attempt at it, but it doesn't work because it doesn't make sense;
result.setText1(Integer.toString(celsius));

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class TempConversion extends JFrame
{
private final JLabel ask;
private final JLabel result;
private final JTextField text;
private final JTextField text1;

[code]....

View Replies View Related

Temperature Conversion Celsius To Fahrenheit

Jun 16, 2014

I have followed the instructions carefully but the conversion values are not correct.

Write a program that displays a table of the Celsius temperatures 0 through 20 and their Fahrenheit equivalents. The formula for converting a temperature from Celsius to Fahrenheit is
F - | C + 32
where ¥ is the Fahrenheit temperature and C is the Celsius temperature. Your program must use a loop to display the table.

Code

public class TempConversion
{
public static void main(String[] args) {
for(double i = 0; i <= 20.0; i++) {

[Code] ....

View Replies View Related

ArrayIndexOutOfBoundsException In A Single Dimensional Array For Temperature Conversion

Aug 31, 2014

I have a simple code for temperature conversion using single dimensional array, but I am getting ArrayIndexOutOfBoundsException error.

import java.io.*;
class arraycelcius
{
public static void main()throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(read);

[code]...

View Replies View Related

Coordinate Conversion Project - Rectangular To Polar

Mar 6, 2014

Ok Im trying to create a code right now that will take a table of rectangular coordinates and convert them to Polar coordinates in the constructor. I will eventually calculate the total distance between all points in the calculateDistancePolar method but for now I am using it to test.

It doesnt like line 29 and 31 of the class Polar and I cannot figure out why.

public class Test {
public static void main(String[] args) {
double[][] coords = {{86.92, 2.47},{70.93, 27.81},{97.74, 34.36},{30.90, 35.14},{51.66, 31.70},{0.830, 21.77},{55.91, 66.62},{32.92, 75.23},{65.26, 72.53},{83.90, 4.710}};
System.out.println("X,Y Coordinates are:");
outputArray(coords);
Polar myTest = new Polar(coords);

[Code] .....

View Replies View Related

Hurricane Java Project - Unknown Format Conversion Exception

Mar 9, 2015

I am having some issues with errors. Here is my code...

import java.io.*;
import java.util.Scanner;
public class StormChaser {
public static void main(String[] args)
{
// Constants
final int MAX_STORMS = 319;
 
[Code] .....

I am having issues with these error messages.... I have tried a couple of different things with each error but haven't been able to figure it out.

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '1'
at java.util.Formatter.checkText(Unknown Source)
at java.util.Formatter.parse(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.lang.String.format(Unknown Source)
at Storm.toString(Storm.java:98)
at StormChaser.DisplayStorms(StormChaser.java:141)
at StormChaser.main(StormChaser.java:53)

View Replies View Related

Take Input Of Temperature In Fahrenheit And Convert It To Celsius And Kelvin

Oct 28, 2014

I’m trying to write a program in Java that will take the input of a temperature in Fahrenheit and convert it to Celsius and Kelvin. This is what I have so far but when I run the program on Eclipse it says the temp. in Celsius is infinity and the same for kelvin. Why is it not preforming the operation and spiting out the correct numbers?

import java.util.Scanner;
public class Temperature {
public static void main(String[] args) {
// This program converts temperatures from Fahrenheit to Celsius to Kelvin.
double temperature1;// operands
double temperature2;
double temperature3;

[Code] ....

View Replies View Related

How To Get Calculation To Work Using User Input From Textfields

Feb 23, 2014

As stated in the subject I'm a newbie when it comes to Java Programming (I'm in my second week of class). I'm trying to create a Retail Calculator for a class and need to multiply two values together (Price, Discount) in order to get the sale's price when the user hits a Calculate button. The price and discount are user input values from textfields in the beginning of the code.

public void actionPerformed(ActionEvent e) {
String price;
String discount;
float salePrice;
//Get the original price from price textfield
price = priceValueField.getText();

[Code] ....

View Replies View Related

Age Calculation Based On Input (Date Of Birth)

Nov 9, 2014

I am trying to solve this problem but it is not working properly, when i enter the date of birth, such as 1993 12 14 it comes up as 21 years old instead of 20.

import java.util.*;
class Age
{
public static void main( String [] args)
{
Calendar rightNow = Calendar.getInstance();
 
[Code] ....

View Replies View Related

Read Chars In Text Area And Produce Desired Output For Text Editor Project?

Nov 27, 2014

I am working on a personal project and want to create a text editor to write my code. I am wondering how could I read the last input from the user and if say it was an open curly brace {, then like netbean's my editor will supply the closing curly brace. My java experience is limited but I have tried to read key board input and a few other options that did not work.

View Replies View Related

Swing/AWT/SWT :: JLabel Does Not Display

May 8, 2014

I'm having problems getting my program to display a JLabel. The program draws shapes of random size and color across a panel. I have this part working. (There is more code for the drawing of shapes, I left it out for easier reading). When I try to add a JLabel in the main method, it does not display.

import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TestDraw {

[Code] .....

View Replies View Related

Payroll Code - If Input Hours Greater Than 40 Cost To Employer Calculation Goes Wrong

Feb 28, 2014

I think I fixed the first error, but now I'm receiving another error in my Net Pay print statement at the end.

Here is what I'm supposed to receive:

Net Pay: 599.86

Here is my sample run:

run-single:
Enter hourly rate in dollars and cents --> 27.16
Enter number of hours and tenths worked --> 37.9

PAYROLL REPORT
Rate: 27.16
Hours: 37.9

Gross Pay: 1029.36
Federal Tax: 257.34
State Tax: 93.41
FICA: 78.75
Net Pay: 771.86

Employer's FICA contribution: 78.75
Employer's UEI and DI contribution: 20.59
Cost to Employer: 1128.70

Enter hourly rate in dollars and cents -->

Here is my updated code:

package assignmentproject1;
/* CHANGE (FINAL) VAR NAMES, SCAN & VERIFY,
ORGANIZE AND PUT FORMULAS ON BOTTOM, ORGANIZE VAR @ TOP, */
import java.util.*;
public class Project1 {
public static void main (String[] args)

[Code] ....

View Replies View Related

GUI Program - Enter File Name And Display Text Area

Apr 14, 2014

I have to write a gui program where I can enter a file name and then it gets displayed in a text area when I click Open. Conceptually, I do not get this. I was thinking of appending the text file into a string or something, but I guess I'm confused on how it all works and how I can open the text file. Not asking for the code, but just a compass or something.

View Replies View Related

Display Image On JLabel Or JPanel With Respect Of Components Size?

Mar 27, 2015

i have very critical problem in my collage project i have try many code but still i cant solve this problem, i want to display image on jlabel or jpanel with respect of components size without use of drawimage method

View Replies View Related

Swing/AWT/SWT :: Can Text Area Also Be Used For Input

Apr 7, 2014

I have a popup that displays textual info and sometimes gets text input from the user. I'm using the following code:

JTextArea textArea = new JTextArea( getGameHistory( true, -2 ) );
JScrollPane scrollPane = new JScrollPane(textArea);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setFont(new Font("courier", Font.PLAIN, 12));
scrollPane.setPreferredSize( new Dimension( 30, 100 ) );
String input = JOptionPane.showInputDialog(null, scrollPane, "Fun Chess ",
JOptionPane.YES_NO_OPTION);

This shows a nice text area and an input field underneath it.The getGameHistory() method just returns a long string detailing the current game.Is there a way of just showing the text area without the input field underneath?Can the text area also be used for input instead?

View Replies View Related

Area Calculator - How To Move All Input / Output To Main

Nov 11, 2014

I am stuck on one of the projects: Area Calculator

I am able to code an area calc that works, but am unsure how to move all the input/output to main like the project wants. here is a piece of my code so far:

public static void main( String[] args )
{
Scanner kb = new Scanner(System.in);
int base = 0, height = 0, width = 0, radius = 0, choice;
System.out.println( "-=-=-=-=-=-=-=-=-=-=-" );
System.out.println( "1. Triangle" );
System.out.println( "2. Rectangle" );
System.out.println( "3. Square" );
System.out.println( "4. Circle" );
System.out.print( "Pick a shape: " );

[Code] ....

I have the same thing for rectangle, square, and circle (of course with the correct formulas) and the program works perfect, but the assignment is still wrong until I can move the input/output to main. what do I do?

View Replies View Related

Dealing With Spaces During Input String Conversion?

Oct 5, 2014

I am working on a small brain teaser project where I am taking a string input from a Scanner, and turning into ascii. The problem comes into play when the string has a space in it, so if the question is what's your name? and you say Michael Jackson, Michael gets converted then Jackson becomes the answer to the next question, rather then the second portion of the current string.

This is an older version of what I'm doing currently, but it had the same basic problem with spaces.I will say I did my current version entirely different.

nner user_input = new Scanner (System.in);
//Creates a string
String favoriteFlick;
System.out.println("Enter the title of your favorite film?");
favoriteFlick = user_input.next();

[Code] .....

View Replies View Related

Input Length And Width - Calculate And Print Perimeter And Area Of A Rectangle

Feb 16, 2015

Create a program to input the length and width of a rectangle and calculate and print the perimeter and area of the rectangle. To do this you will need to write a Rectangle class and a separate runner class. Your program should include instance variables, constructors, an area method, a perimeter method, a toString method, accessor and mutator methods, and user input. Your runner class should include 3 Rectangle objects. One default rectangle, one coded rectangle, and one user input rectangle. All methods should be tested in the runner class.

This is my code:

import java.util.Scanner;
 public class Rectangle {
double length;
double width;
public Rectangle() {

[Code] ...

What have I done??? I have created this program using the few different resources with which I am supplied, but I don't understand the resources.

View Replies View Related

Swing/AWT/SWT :: Movement And Conversion Of GetText Input In OrderCalc Method

Mar 7, 2014

My OrderCalculator class is throwing an exception. The input from my HourPanel that is supposed to add to my OrderCalc is cooperating.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
public class OrderCalculator extends JFrame
{
private JobPanel jobs;
private HourPanel rate;

[Code] .....

View Replies View Related

Generate QR Code From Input Text And Display Information About Input / Output Bits

Nov 12, 2014

I am trying to write a program that will generate a QR Code from an input text and also display some information about the input/output bits. So far I have created the frame and what to do next. And I'm not sure if I am on the right track since my level of programming is not that great. By the way, I am using zxing libraries from GitHub. I know, there are plenty of generators online for the QR Code, but that is not what I am looking for. As you can see on the attached image, I am more interested in the efficiency of encoding 2D data. Also, I noticed that almost all the online projects regarding 2D codes are for Android. Which is not very useful.

// QR Code Generator
package qrcode;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

[Code]....

View Replies View Related

User Enter A File On Text Field And Display Its Hex Representation In Text Area

Apr 17, 2015

I'm supposed to write a GUI application letting the user enter a file on the text field and display its hex representation in a text area and vice versa.

Here's my code:

/*
* 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 hexconvertor;
import java.util.*;
import java.io.*;
public class HexConvertor extends javax.swing.JFrame {

[Code] .....

It's not doing anything, I don't understand why.

View Replies View Related

Minus Expenses From Monthly Income And Display Net Income In JLabel

Jun 26, 2014

I am trying to build an app for managing expenses to practice with java programming. I am stuck on the ActionEvent block. The program i am trying to make needs to minus the expenses from the monthly income and display the net income in JLabel.

package mybudgetapp;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

[Code] .....

View Replies View Related

Assembling Database Project From A Downloaded Project Zip File?

Apr 12, 2014

i downloaded a sample database code of an online payroll system. How can i assemble it to know how it works.
the files include php and mysql files. it is to build an online payroll system

View Replies View Related

How To Return A String From Project Into Android Project

Jun 26, 2014

I tried many times to return a string from java project to an android project But it keeps sending incorrect values as in 2 as it should be 1 here is an example.

Java Project:

boolean somethingboolean = false;
if(something.equals("1")){
somethingboolean = true;
}
public static String getString(){
if(somethingboolean == true){

[Code]...

Android project:

System.out.println(JavaProject.getString())

and in the android project it prints "FALSE"

So what should i do?

View Replies View Related

Accept Integer As Input - Display Even Or Odd

Apr 14, 2014

This program is supposed to accept an integer as an input and display the message that the number is even or odd. The main method calls a Boolean method. Write a method private static boolean iseven(int number and the message is printed from the Main method. This is what I have.

import java.util.Scanner;
public class OddorEven {
int number;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

[Code] ....

I know the message is not being printed from the Main method. I'm not sure how to do that.

View Replies View Related

Reading File Input - Display All Values

Apr 8, 2014

I've been trying to learn how to read in file input and have a question about this piece of code:

Java Code:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class readFile {

public static void main(String args[]) throws FileNotFoundException{
File file = new File("file.txt");
int sum[]=new int[5];
int i=0;

[Code] .....

"file.txt" holds the following information:

1
2
88
42
56
89

But my output looks like:

2
42
89

if I take out sum[i]=input.nextInt(); it will display all values in the file.

View Replies View Related







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