Passing Value From JTextField In One Class To Another

Apr 6, 2015

I enter a value in the text box in one class and want to pass that value to another class in order to compare it and color the cell in a table. In the first class I have

package cege.ui;
 import cege.controller.HtmlController;
import cege.controller.ScreenCaptureController;
...
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

[Code] .....

How to pass the threshhold from the first to the second class?

View Replies


ADVERTISEMENT

Reading Input From JTextField And Passing It To Another Class

Sep 7, 2014

I am having trouble taking user input and passing it to another class as a variable. If I assign the value explicitly (see line 59), it works just fine. What I want to do though, is assign the input from inputField to the variable inputVariable. I tried using:

inputVariable = inputField.getText();

This does not work. Regardless of what is typed into inputField, the output I get is just:

"The user typed "

package example;

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

[Code] .....

View Replies View Related

Error Passing Value Of A Variable From One Class To Main Method Of Another Class

Jan 8, 2014

I've 3 classes.

1. Circle
2. GetInputFromUser
3. testCircle

package ABC;
public class Circle {
private double radius;
public double getRadius() {
return radius;

[Code] .....

In the testCircle class, in the line: getRadius = ui1.GetInput();

It's showing the error: The method GetInput(float) in the type GetInputFromUser is not applicable for the arguments ()

And when I do: getRadius = ui1.GetInput(rad);

It's showing the error: rad cannot be resolved

View Replies View Related

Passing Value From Sub Class To Super Class

Oct 19, 2014

So the first thing we did was make a program called memory calculator. now we are supposed to make a sub class that modifies the program to also do exponents and natural logs. Then to make a new class that acts as the driver for what is now called the scientific memory calculator which includes the exponent and log. I have watched this through debug and im a little confused. first off it creates a variable for currentValue in current and in sci which are my instances, which i dont think is what i really want to do, I am unsure how to get the things in the Scientificmemcalc to do stuff without calling them directly. so when i try to do the power feature it does everything correct but it sets the sci current value to the correct answer, and now i cant figure out how to pass it on to the current current value.

This is the memory calculator :

public class MemoryCalculator {
public static void main(String[] args) {
MemoryCalculator current = new MemoryCalculator();//creates an instance
int choice = 0;
do{//main loop
System.out.println("Current value: " + current.getCurrentValue() + "

[Code] .....

View Replies View Related

Value Not Passing From Second Class?

Nov 8, 2014

I am trying to pass value from class to another using net beans but it seems that I am doing something wrong.

find my basic code at sourceforge.net/projects/val1toval2/files/SRC/

I would like to have both VAL1 and VAL2 having same value in Jlabel.

//Main.java 
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Second SEC = new Second();
l_dis.setText(String.valueOf(getInput()));
l_tot.setText(String.valueOf(SEC.getTotal()));

[code]...

View Replies View Related

Using Jtextfield On Jframe (Swing) To Enter Search Terms In Different Class

Dec 4, 2014

I have a swing jFrame set up with a control group which contains 3 radio buttons.

When one is clicked it sends its label to a jtextfield in a different class i have code parsing text by a term

Java Code:

Scanner s = null;
try {
s = new Scanner(new BufferedReader(new FileReader("/Stage_One.txt")));
s.useDelimiter("*");
String total = (s.next());
Pattern p = Pattern.compile("[]+");

[Code] ....

I just need to know how to access the jframe variables (textfields, panels and such) so i can use their inputs in code to filter a text file.

View Replies View Related

Passing In Variable From One Class To Another?

Aug 16, 2014

It just wont work... Everytime I try to pass a variable into a class it sets it to 0. What to do.

The variable should be '2', but it prints out as 0!?

Java Code: package Zoo;
import java.util.Random;
public class Animal {
Random random = new Random();
public void Eat(){
System.out.println("The animal starts to eat.");

[Code]...

The method bash, needs the variable 'playerTwo' to be 2, to carry on. But it prints out 0.

Int the animal constructor, I passed in the variable from another class, and it prints out 2 in the constructor like it should. But outside of the constructor it is equal to 0.

View Replies View Related

Getting Values From One Class To Another Without Passing Into It

Feb 19, 2015

I am trying to get the username and password for one class and send them to another. However I cannot send them in the constructor because a database class is getting them and I need that constructor blank. However if I do not pass the class in the constructor I get a NULL error, even better when I do pass it in I seem to get a thread lock. I do try to do my own housekeeping and close the one frame before I open a new one but it doesn't work. I will do my best to show the design of the program.

program starts
Java Code: public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// connects to database and generates a GUI
new UserPromptScreen();

[code]....

I have to pass in UserPromptScreen in for it to work. This will cause me issues later with my design.

View Replies View Related

JSF :: Passing Backing Bean To Another Class

Mar 7, 2014

I am new to JSF and was trying to find an example.

My question is in the processPage() method... how do i pass the managed bean to the ProjectDAO insert statement?

Faces-config.xml

<managed-bean>
<managed-bean-name>projectBean_backing</managed-bean-name>
<managed-bean-class>com.att.ped.backing.Project</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

[Code] .....

View Replies View Related

Passing JComboBox To Another Class - JAVA GUI

Nov 15, 2014

Java Code:

createConnection();
try{
String str = "select * from Stocks";
stmt = conn.prepareStatement(str);
ResultSet rs = stmt.executeQuery();
while(rs.next())
jcbStock.addItem(rs.getString("stockID"));
}catch(Exception e){
e.printStackTrace();
} mh_sh_highlight_all('java');

I want to put this code in a class then call it in another class , but i do not how to do that. This code is working fine in my main class , but i want to write this code to another class for call it in main class.

View Replies View Related

Swing/AWT/SWT :: Error At Class Name - Type JTextField Must Implement Inherited Abstract Method

Oct 27, 2014

This code is directly from Swing: I'm using Eclipse and keep getting an error on line 10 saying :

"The type JTextField must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)."

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

[Code] ......

View Replies View Related

Passing Variable From Class A To B To Do Calculation But Getting Error?

Mar 23, 2015

I'm getting this error, I definitely know that is my error trying to pass method/variable because when I commented received part of my code it ran and worked.

I get this error

at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Here are my 2 classes

Java Code:

import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[Code] .....

View Replies View Related

Passing Parameter From Object Of Class B To Object Of Class C By Use Of Class A?

Dec 13, 2014

Assuming that we have two classes B and C which inherit from class A. What is the best way to pass a parameter from an object of class B to an object of class C by the use of class A without using static variable and without defining a get function in B?

View Replies View Related

Adding Values Within Jtextfield?

Mar 25, 2015

I have a supermarket checkout line where i have a list of available products on the left and then a basket on the right with the products in. The products are listed in an array, here is the product class

public class Product {
private String name;
private double weight;
private double price;

[Code] ....

with getters and setters excluded, and the list these are put into

public class productList extends DefaultListModel {
public productList (){
super();
}
public void addProduct (String name, double weight, double price, int code){
super.addElement(new Product(name, weight, price, code));

i have the price for each product to be displayed in a text field with the following code

addBasketItem = new JButton();
getContentPane().add(addBasketItem);
addBasketItem.setText("Add >");

[Code] ....

defaultCheckoutList contains my available items and defaultMainList is the basket, with mainTillPrice being the jtextfield.

This works to get the price however it just replaces each time i make a new entry with the price for the next item, i want a total of the price of all the items i have added, but not sure how.

View Replies View Related

How To Put Default Int / Float For JTextField

Feb 4, 2014

Will I'm tying in my code to set a default number for the JTextField that when the user decide not to put any numbers. Like let say that I want the textfield set to 0 , so then the user do not file it it won't make any problem to the program because its already has a default number.

if (stringGQ != null && stringGW != null && stringGP != null){
 stringGQ = gMQ.getText();
stringGW = gMW.getText();
stringGP = gMP.getText(); 
weightPrice_1M = Double.parseDouble(stringGW) * Double.parseDouble(stringGP);

[Code] .....

Note: This is a small part of my code. when I leave it empty it take the 0 as a value, However, when I write in text field it also take the value of a 0 and the finalTotal is also = to 0.what I'm doing wrong.

View Replies View Related

Private JTextField Update

Jan 22, 2015

I am creating a slot machine using eclipse. I am trying to get the "winnings" JTextField to be updated in a way so that when the random images have been selected it adds to the number that is already displayed in the JTextField as opposed to what it is doing at the minute which is just displaying how much was won on that particular spin. I am also struggling to set a code for when noting is won, nothing is added. My code is below.

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.*;
import javax.swing.Timer;

[Code] ....

View Replies View Related

Using JtextField As Google Toolbar?

Mar 4, 2015

how build a Google toolbar to search on web with java? I have this code but something is wrong...

View Replies View Related

Retrieving Values From A JTextField

Jan 18, 2015

I currently building a hotel reservation system, and I'm having issues with retrieving and setting other values from a JTextField.

What I'm trying to do is to retrieve the value that was inputted into a textfield, and then setting that value to a string in another class.

In here, I'm trying to retrieve values from the JTextField:

@Override
public void actionPerformed(ActionEvent event) {
GuestInfo gi = new GuestInfo();
if (event.getSource()==roomView)
{
roomViewFrame.setVisible(true);
roomViewFrame.setSize(1000, 600);

[Code] .....

View Replies View Related

Decimal Point On Jtextfield

Apr 26, 2014

designing a program which allows you to buy stuff from the jframe with 10x items each with different pricing, so once you click the image button the cost of that is displayed in the textfield, ive been trying to set the jtextfield to a decimal point but have not been able to so far,

if (source == jBSofa) {
System.out.println("Sofa");
{
dTotal = dTotal + 599.99;

jTotal.setText(Double.toString(dTotal));
DecimalFormat myFormatter = new DecimalFormat("#####.#");
String output = myFormatter.format(dTotal);
a visual aspect of it.

View Replies View Related

Input And Output Via JTextField

Jun 29, 2014

How would I display certain output text if the text entered equaled "text".

So lets say you enter a question into a JTextField. You press a button that submits the text. The output displayed depends on what the question you asked was.

Think about it as "If question = What color is the sky? On submit, display text "Blue". How to implement this.

View Replies View Related

Create JTextField And A Button

Jan 6, 2015

i am new to GUI.i create a JTextField and a Button("ok").and i want to get the String of the text after i push the button.what did i do wrong?

JTextField theText=new JTextField("Type a new question here",40);
JButton addButton=new JButton("Add");
mainPanel.setLayout(new FlowLayout());
mainPanel.add(theText);
mainPanel.add(addButton);
mainPanel.add(showAllQuestionsLabel);
mainPanel.add(showAllQuestionsButton);

[code]....

View Replies View Related

Swing/AWT/SWT :: Autocomplete In JTextField

Apr 2, 2014

I have been reading several suggested solutions for implementing autocomplete for a JTextField. However, the documentation is a bit confusing to me. It seems like they mostly require switching to a JComboBox. Can I or can I not continue to use a JTextField and implement an autocomplete feature? I also saw what I thought was a built-in autocomplete "decorator" for swing objects (although it was not clear if it can be used for JTextField) but most of the implementations seem to start from scratch. Any simplest way to implement this (assuming those 2 conditions are not mutually exclusive)?

View Replies View Related

Swing/AWT/SWT :: Inputting One Letter Into JTextField

Mar 9, 2014

I'm writing a java program in eclipse of a tic-tac-toe game. I have to create it using JTextField's only I'm having trouble where the JTextField will only accept one letter and will only accept X and O is there any particular way to do this I started off with this piece of code

String text=tf1.getText();
if(text.length()>1) {
System.out.println("this is not allowed");
tf1.setText("");

But it doesn't work so is there something I'm missing....

View Replies View Related

Swing/AWT/SWT :: How To Get Data From JTextField Over To JTable

Jun 20, 2014

I am trying to get the data entered in a JTextField into a JTable but not clear on how. The LeftPanel is where the button is located and the RightPanel is where the JTable is. I want the actionPerformed to update the row of the JTable but I can't figure out how. There is another class that controls the GUI but did not think it was necessary to include. Also, I am aware that I am getting an error at the addRow line, can't seem to alleviate it.

public class LeftPanel extends JPanel {

private static final long serialVersionUID = -2311952438693382407L;
private RightPanel rPanel;
public LeftPanel(){
Dimension size = getPreferredSize();
size.width = 250;
setPreferredSize(size);

[code]....

View Replies View Related

Get User Input From JTextField And Set It To JTable

Sep 13, 2014

I need to get users input from jtextfield and set it to JTable. This is my code:

public class Projektni extends JFrame {
public final JTextField ime = new JTextField(10);
public final JTextField prezime = new JTextField(10);
public final JTextField index = new JTextField(10);
public DefaultListModel podaci = new DefaultListModel();
JButton imeB=new JButton("Upisi u tabelu");

[Code] ....

View Replies View Related

Store Content Of JTextField To Char

Mar 9, 2015

I was trying to store the content JTextField on char..... Here's the instruction of program--->>create a GUI program that convert letter into corresponding no. EXAMPLE:

if user enter "c" then it will output "3"......
like a=1,b=2,c=3,......

Here's my code

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class convert extends JFrame {
private static final int width = 400;
private static final int height = 300;
private JLabel EN,EQN;

[code]....

View Replies View Related







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