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
ADVERTISEMENT
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
View Related
Sep 16, 2014
I am required to read user input to create two matrices which will eventually be added together. I am unsure as to how I can read the input from the user as an int and not a String. The input is from size 0-10 for both column and row size. Also, can you have a new button created in the actionPerformed method of a previous button?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Matrices implements ActionListener {
private JFrame win1, win2, win3, win4;
[Code]...
View Replies
View Related
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
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
Jul 5, 2014
I have a GUI with a JTextField. I need to check that the input entered by the user is made up of only integers.
For example I accept: 1, 10, 530, ...
I do not accept: -10, 1.5, -6 ...
I would like to implement this control by using a regular expression so I would have a code like that.
JTextField text = new JTextField();
String input = text.getText();
boolean bool = checkInteger(input);
if(bool)
System.out.println("Ok");
else
System.out.println("Error");
The checkInteger(String input) method should check if the input string is correct or not.
How can I do to implement this control with regular expressions?
Is there an easier way to do it?
View Replies
View Related
Oct 21, 2014
I'm trying to get data from a GUI input window into an ArrayList and back out via a JTable. I can get the array lists to print to the console within the input class, but I need to wire it to a data container and out through a different class. Here is code from one input class, and its corresponding output class:
Input:
public class AddClassroom extends JFrame implements java.awt.event.ActionListener {
// UI components
// are declared here...
[code]....
View Replies
View Related
Dec 4, 2014
I am trying to populate a JTable using Several JTextFeild a JComboBox and a JLabel.
The textfields are originalPrice and itemName
JComboBox is departmentComboBox
label is salePriceLable.
When hitting the button i need the program to calculate the price after discount and add the item name, department, original price, and discounted price to a table. I have the calculation down, but am lost on populating the table.I used NetBeans 8.2
/*
* Program: JavaRetailCalculator
* Purpose: To calculate the ammount of a discount and display results in a Table
*/
import java.awt.*;
import javax.swing.*;
public class CalculatorFrame extends javax.swing.JFrame {
/**
* Creates new form CalculatorFrame
*/
public CalculatorFrame() {
initComponents();
[Code] .....
View Replies
View Related
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
Sep 13, 2014
I have project to get from users input like name,surname,to save to Jtable,i have table and jtextfiled but when user get input they don t save to table here is my code:
Project.zip (33.54K)
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();
public JList lista = new JList(podaci);
String kolone[] = {"ID","Name","Age"};
[Code] ....
View Replies
View Related
Apr 8, 2014
I have an xhtml file with this content:
<h:inputText tabindex="7" styleClass="input" id="title" value="#{register.title}"
required="true">
</h:inputText>
Basically I want the user to enter his title (e.g. Mr., Dr.), which would be passed on to a bean which would send this information to me in email.
I also have a bean called register, along with setters and getters:
private String title;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
I want to pass this information to a String called body, within the bean:
body = body+"Title: "+this.title+"
";
I would then send the String in an email.
View Replies
View Related
Jan 29, 2014
I have been creating a Java program to track inventory using an array. I need to add a search function to it to take a term, input through a text field, and locate a matching instance within the array. How can I code a JButton to grab test input from a JTextField and search for it within the array then display the corresponding information? I also need to add buttons to add and delete items as well.
View Replies
View Related
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
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
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
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
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
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
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
Jun 20, 2014
I have to write sorting algorithm for numbers given on standard input(console) with following requirements:
The application must remember the distinction between double and integer numbers. This must be evident in the sorted output. Double type numbers are written using a period (.) to separate the fraction from the whole part.
The problem is I don't know how to efficiently distinct whether something is an int or double on standard input, to save them into 2 different arrays.
Only idea I've come to so far is to read each number as String and check if it has '.' character, to figure out if it's double and than convert it into right type and add it to correct array.
Also thought that maybe this would be achieveable using Pattern but how to do that?
View Replies
View Related
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
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
Jan 11, 2012
I am using jdk 6 ... I came to know that how we can read strings from user input ... and how we can convert a string to int .. but i dont fount how to read a character by character from user ..
View Replies
View Related
May 1, 2015
The following program should read in a file on my desktop (I have the path set in Netbeans to that location) and produce a Histogram. Instead I am receiving this error.
Exception in thread "main" javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1301)
at Histogram.main(Histogram.java:9)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Here is the code for the Histogram:
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class Histogram {
public static void main(String[] args) throws Exception {
int[][][] ch = new int[4][4][4];
[code]...
Why it's not reading the file?
View Replies
View Related
Apr 7, 2014
public void savePlants(ArrayList flowerPack) throws IOException
{
Scanner input = new Scanner(System.in);
String name;
[Code].....
When I open the saved file the information I need seems to be saved, but when I try to load and search it the data is not there. This is homework that was due about 2 days ago. I just want to get it right in my head for next time.
This is my text file: ¬í sr java.util.ArrayListxÒ™Ça I sizexp w sr FlowerNÏŠ¨r;¾ Z hasScentZ hasThornsL flowerColort Ljava/lang/String;xr Plant"ô²Ò0¢ I IDL Nameq ~ xp t Roset redsr Fungus“ +) Z isPoisonousL fungusColorq ~ xq ~ t toadstool t brownsr Weed #©éÇÙN Z isEdibleZ isMedicinalZ isPoisonousL weedColorq ~ xq ~ t dandylion t yellowsq ~ t tulip t pinkxq ~ q ~ q ~
View Replies
View Related
Jul 10, 2014
This is my code
// TODO Auto-generated method stub
File file=new File("D:/input.txt");
java.io.FileInputStream is=new java.io.FileInputStream(file);
int a=is.read();
try {
while((a=is.read())!=-1) {
System.out.print((char)a);
[Code] .....
My text in file is :my birthday Hello World
But in out i see only:y birthday Hello World
Why is first character is missing here?
View Replies
View Related