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


ADVERTISEMENT

Swing/AWT/SWT :: Add JTextField And Additional Output Within ComponentEvent Handlers

Jan 30, 2014

Using the code from the Java Docs (listed below) I am getting behavior that was a bit unexpected. The only changes were to add JTextField and additional output within the ComponentEvent handlers. Run the code and when the frame appears, think of each side as North, South, East (right side) and West (left side) as you are looking at it. This was run using JDK 1.7.0_25.

Run the code.

1 - Click the East edge (right) of the frame and drag to be wider or more narrow. Only the "Resized" is executed for all components which makes sense.

2 - Click the West edge (left) of the frame and drag to be wider or more narrow. This time "Resized" is executed for all components EXCEPT it is "Moved" for JFrame. Why is it "Moved" here for JFrame but not in Step 1?

3 - Click the South edge (bottom) of the frame and drag to be taller or shorter. This time only 2 components are affected. JPanel is "Moved" while JFrame is "Resized".Why isn't both JFrame and JPanel just "Resized"?

4 - Click the North edge (top) of the frame and drag to be taller or shorter. This time only 2 components are affected again but the output is slightly different. JPanel is "Moved" while JFrame is BOTH "Resized" and "Moved".

There just doesn't seem to be consistency here. What are the guidelines or criteria for when these Events are to be executed?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ComponentEventDemo extends JPanel
implements ComponentListener,
ItemListener {

[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

JTextField That Accept Only Integer Input?

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

GUI JTextField Input Not Storing / Displaying

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

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

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

Populate JTable With Input From JTextField And JComboBox

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

JTextfield And Jtable - Get Users Input From Field To Table

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

Reading User Input From JTextField As Int To Create Matrix

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

Code JButton To Test Input From JTextField And Search For Array Then Display Information

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

Formatted Input And Output In Java?

Feb 23, 2014

What are formatted input & output in Java? I want to know the difference between general "input & output" & "formatted input & output"? And what is the reason of the naming it as formatted.

View Replies View Related

String Input / Output And Casting

Oct 2, 2014

I have to create a program that uses the Scanner in String input and Output that will enable the user to convert

double -> int
int -> byte
int -> short
int -> hex-string

The output should look something like this:

Syntax: convert <value> <type>
convert 15.5 int~> 16
convert 128 byte~> -128
<type>: int, byte, short, hex, decimal
Syntax: max <type>
max byte~> 127
<type>: int, byte, short

[Code] ....

View Replies View Related

Use While Loop With Input And If Statement For Output

Apr 26, 2015

Here is my code so far. I am trying to get the WHILE LOOP to work so the user inputs a number, the if statement prints the output and then it returns to ask for another number and goes again and again looping :

import java.util.Scanner;
public class ifwhileloop {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
double nmbr;

[Code] ....

View Replies View Related

Input / Output Using Process Class?

Jun 6, 2014

I want to do basic input/output using Process class. I basically wish that, I should ask user his name and when user provides his name then I would print "Hello '[name]'"

import java.io.*;
public class ReadAndPrintName
{
static Process p;

[Code]....

View Replies View Related

Input Letter - Output Whether Vowel Or Consonant?

Mar 16, 2015

I am trying to create a program for my class that requires the input of a letter and the output of whether or not it is a vowel or a consonant. I am using eclipse, it is giving me no errors, but when entering the letter i get an error in the console

import java.util.Scanner;
public class w0571505_a2a {
private static Scanner a;
public static void main(String[] args) {
// enter letter
System.out.println("Enter a Lowercase Letter");

[Code] .....

This is what i have...

View Replies View Related

Java Input / Output Program Using Threads

Feb 24, 2014

I am trying to write a program in Java that uses threads.Below is the program requirements:The goal of this assignment is to create a routine which creates multiple threads, has them do work in parallel, and terminates when the last thread has finished.

The Scenario: There are several groups of people in a bar watching the Olympics cheering for their country. Each group will cheer for their country some given number of times, with a random pause (between 2 and 5 seconds) between each cheer. There is enough room at the bar for up to ten different groups to sit (each would be cheering for a different country).

The Program: The task is to write a program that will simulate these cheers using threads. The program should be called cheer.X (X being the language of choice). You may use any language that supports threading. When the program is run it should ask for the number of countries and then the name and how many times it will be cheered for. The main function will then create a thread for each team and each thread is responsible for cheering the specified number of times for the correct team at the random interval. You will submit the proper source code file for me to open and compile myself, not an executable.

An example run would look something like this: How many countries are supported at the bar? 3 Enter the first: China How many cheers? 2 Enter the second: USA How many cheers? 4 Enter the third: Russia

View Replies View Related

Custom Input Management Class - No Output

Aug 25, 2014

My input class

package core;
import java.util.ArrayList;
import org.lwjgl.input.Keyboard;
public class Input{
public static final int num_key = 78;
private static ArrayList<Integer> currrentkeys = new ArrayList<Integer>();
private static ArrayList<Integer> downkeys= new ArrayList<Integer>();
private static ArrayList<Integer> upkeys = new ArrayList<Integer>();

[Code] ....

View Replies View Related

Program Should Output Depending On Input Number

Apr 15, 2014

The program should has the output depending the number I'll input. (The number should be from 1-9) . This is the program's output should be:

Input number: 4

Output:
# # # 1 # # # # #
# # # 2 # # # # #
# # # 3 # # # # #
1 2 3 4 5 6 7 8 9
# # # 5 # # # # #
# # # 6 # # # # #
# # # 7 # # # # #
# # # 8 # # # # #
# # # 9 # # # # #

(Example 2):
Input numbers: 8

Output:
# # # # # # # 1 #
# # # # # # # 2 #
# # # # # # # 3 #
# # # # # # # 4 #
# # # # # # # 5 #
# # # # # # # 6 #
# # # # # # # 7 #
1 2 3 4 5 6 7 8 9
# # # # # # # 9 #

(Example 3):
Input number: 5

Output:
# # # # 1 # # # #
# # # # 2 # # # #
# # # # 3 # # # #
# # # # 4 # # # #
1 2 3 4 5 6 7 8 9
# # # # 6 # # # #
# # # # 7 # # # #
# # # # 8 # # # #
# # # # 9 # # # #

I'm not asking the code to make this program, I have trouble to understand the algorithm to make this program ...

View Replies View Related

How To Use File Input / Output In Addition To Exception Handling

Dec 2, 2014

I am trying to learn how to use file input/output in addition to exception handling... The problem is my textbook wrote this chapter for a version of Java that hasn't come out yet, so everything I do "according to the textbook" doesn't work. any feedback on correcting these exception errors because I am not sure what is causing them or how to fix them.

I was able to have it display the name of the book in the Book.txt file, but when I added the second part if the file doesn't exist, that's when the errors came up and it wouldn't compile.

import java.io.*;
import java.util.*;
public class DisplayBook
{
public static void main(String[] args) {
try {
File book = new File("Book.txt");
FileInputStream in = new FileInputStream(book);

[Code]...

These are the compilation error messages I am receiving: (I have managed to get it down from 7 errors to just 4, but now I'm stuck)

DisplayBook.java:15: error: unreported exception IOException; must be caught or declared to be thrown
while ((letter = in.read()) != -1) //if file exists, displays book title
^
DisplayBook.java:24: error: unreported exception FileNotFoundException; must be caught or declared to be thrown

[Code] ....

4 errors

View Replies View Related

Take Input From User And Append Some Text To It - Output Null

Sep 20, 2014

I'm using one method to take input from the user and append some text to it, then I am trying to return the value of the variable and use another method to print it out. But for some reason whenever I try doing this I can't print out anything and I only get a "null" output. Why this is happening?

package Homework3;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Homework3 {

[Code] .....

View Replies View Related

Input Ten Words And Output Them Backwards In MSDOS Environment

Sep 4, 2014

how would a program code look like, input ten words and output them backwards in a msdos environment. My code this far is:

package baktext;
import java.util.*;
import java.io.*;
import java.awt.*;
//public static String baklänges(String s) {
//}
public class Baktext {

[Code] ....

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

Display User Input In Lower Case - Why No Output In Second TextField

Jun 2, 2014

I've done a lot of hardwork for this assignment but I don't know what's why the second textfield which is for output is blank.

All I want is to get the input from user in textfield a and display it in textfield b in lower case.

public void KeyPressed (KeyEvent ke) {
String letter2="";
if(ke.getKeyCode()==KeyEvent.VK_A)
{
letter2=letter2+"a";
btextfield.setText(letter2);

[Code] .....

View Replies View Related

JOption Pane - Output Number With Greatest Value From User Input

Nov 7, 2014

Using JOptionPane,ask for 10 numbers from the user.Use an array to store the values of these 10 numbers.Output on the screen the number with the greatest value.

View Replies View Related

User Input 3 Sides - Output Invalid If Does Not Make A Triangle

Nov 4, 2014

I had to make a program that allows the user to enter 3 sides and it should output "invalid" if it does not make a triangle and if it does make a triangle it calculates the area of the triangle and it doesnt seem to do anything but say "invalid" as the out put.

import java.util.Scanner;
public class MyTriangle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
boolean valid = true;
double side1, side2, side3, area, A;
 
[Code] ....

View Replies View Related







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