Swing/AWT/SWT :: Add DocumentListener To Validate Multiple JTextFields

Apr 22, 2013

Code given below does real time validation for 2 JTextFields. While entering some values to txt1 and txt2 enables the save button and removing values from txt2 or txt1 reset the save button to disable. I use Netbeans as IDE.What I want to do is, enable Save button after checking multiple JTextFields for validity. If any of the text fields is empty, btnSave must be disabled.This program gives expected result up to some extent. But there is little issue. After form appears for the first time, When I type something on Textfield1, Save button enables without checking Textfield2. This happens only at the first time.

public class NewJFrame extends javax.swing.JFrame {
private Boolean isValidFromTextField1 = true;
private Boolean isValidFromTextField2 = true;
public NewJFrame() {
initComponents();
btnSave.setEnabled(false);

[code]....

View Replies


ADVERTISEMENT

JOptionPane With Multiple JTextFields?

May 27, 2014

Here's My code to create multiple JTextfields in a Single Option Pane.

My goal is simple.

Take some input from the user and then store it a TEXT File.

package printer;
import java.awt.Toolkit;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.*;
 public class Database {
 JTextField name = new JTextField();
JTextField roll = new JTextField();

[code].....

View Replies View Related

Creating Multiple JTextFields In A Loop

Sep 18, 2014

I need to create a JFrame with a user given amount of text fields in the form of a matrix. Say the user inputs 5 rows and 5 columns, I need to read those ints and create a 5 by 5 box of JTextFields in matrix form (i.e. 25 total text boxes in the form of a box). Here is some of the code I have been trying to use to do this...

int x = 10;
int y = 10;
for(int i = 0; i<rowSize; i++){
y= y+40;
for(int k =0; k<colSize; k++) {
newField = new JTextField("0");
newField.setBounds(x,y,40,20);
win2.add(newField,0);
win2.repaint();
x= x+60;
}
}

In order to go through the loop a given amount of times and create that amount of text fields in the correct places.Am I even close to doing this right?? Cuz I can't get the text fields to even show up on my window.

View Replies View Related

Swing/AWT/SWT :: Making JButton That Switches Text From 2 JTextFields On Click With Mouse

Aug 6, 2014

I have made a window using JFrame and on my JPanel I have added 3 components: 2 JTextFields ("field1" and "field2") and inbetween them a JButton ("switch"). My goal is to switch the value of field1 to field2 and vice versa when the JButton is clicked. I thought this ActionListener which I have added to my JButton would achieve my goal:

public void actionPerformed(ActionEvent e) {
field2.setText(field1.getText());
field1.setText(field2.getText());
}

However, it changes the value of field2 into the value of field1 but not the other way around.

View Replies View Related

Swing/AWT/SWT :: How To Validate User Input In Dialog Box

Oct 20, 2014

I need to validate an input box so that the user can enter only round numbers.

The user can't enter any other characters except 0 to 9, they shouldn't be able to enter decimal points either.

They would be answering questions like, 'What is 7 times 8?'

Also, I need to validate it so that the program doesnt crash if they leave the input box blank or empty.

View Replies View Related

Create A Matrix Of JTextFields?

Nov 16, 2014

I am making a Sudoku game and creating a matrix of JTextFields. However I am getting the following errors

Exception in thread "main" java.lang.NullPointerException
at SudokuView.board(SudokuView.java:30)
at SudokuView.<init>(SudokuView.java:18)
at SudokuMain.main(SudokuMain.java:5)

I know the problem is with this code

box[i][j] = new JTextField();
panel.add(box[i][j]);

I know this because when I do this:

panel.add(new JTextField());

It works. However it puzzles me why it is not working.

Whole Code:

import java.awt.GridLayout;
import javax.swing.*;
 public class SudokuView {
 JFrame frame;
JPanel panelBoard;
JTextField[][] box;
int row=10; int col=10;
 SudokuView(){
frame = new JFrame("Play Sudoku GOOD LUCK");

[code]....

View Replies View Related

Adding Two Matrices Using JTextFields

Sep 18, 2014

I was assigned to create a program that opens up a window that asked the user for an input of 0-10. This input will create three windows with the correct number of rows and columns of JTextFields in the form of a matrix. the third window has a button that adds the two matrices (which also take user input) and adds them together and prints them in the correct matrix fields. I am having trouble declaring the 2d array from the user input and creating the windows with the correct amount of jtextfields to move on with my program.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Matrices implements ActionListener {
private JFrame win1, win2, win3, win4;
private JButton button1, button2;

[Code] .....

View Replies View Related

Event Handler For Two JTextFields To Only Allow Numerical Input

Jun 25, 2014

I am trying to create an event handler for two JTextFields to only allow numerical input. It consumes all letter but for some reason the "n" key still gets through. I have the spaghetti code below.

public void keyTyped(KeyEvent in) {
char input = in.getKeyChar();
if (in.getSource() == scaleField){
if (!(Character.isDigit(input) ||
(input==KeyEvent.VK_BACK_SPACE) ||

[Code] ......

View Replies View Related

Looping Through JTextFields And Storing Data In Arrays

Aug 6, 2014

I am working on my second javafx program and I am getting confused. The program that I am writing is a payroll calculator. A secondary window opens at the start of the program where the user first enters the number of employees and clicks submit to save the number and to close this window. Then, the user begins to enters the employee information (first name, last name, pay rate and hours worked) when the user clicks the NextEmp button, I want the data in the text fields to be entered into arrays for later use, then clear the fields for the next use. I am running into 2 issues. The first is the close event for the secondary window that pops up. I cannot figure out the syntax. The second issue that I am running into is the loop to store the data into the arrays. I believe I am getting the text field data correctly, but I cannot figure out how to stop the loop until the NextEmp button is pressed again.

import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.input.KeyCode;

[Code] .....

View Replies View Related

Check IsEnabled In ArrayList Of JTextFields And Get Text

Oct 9, 2014

I have an ArrayList of JTextFields in a CAMSetup1 class that contains a bunch of named JTextFields: Layer_textField_1, Layer_textField_2, Layer_textField_3, ... etc

I would like to check the .isEnabled status of a particular JTextField in that ArrayList from my main class by passing the name of the JTextField to a method in the CAMSetup1 class as a string

The peice of code calling the method from the main class is something like this:

if (CAMSetup1.getFieldEnabledStatus("Layer_textField_1") == true) {
data.writeToFile(CAMSetup1.getFieldText("Layer_textField_2") + " LAYER 2 LIST FILE
");
}

The method for checking the .isEnabled that I have so far is:

public boolean getFieldEnabledStatus(String textFieldname) {
boolean status = false;
//<need code here>
return status;
}

I also need getting the text:

public String getFieldText(String textFieldname) {
String filename = false;
//<need code here>
return filename;
}

View Replies View Related

Swing/AWT/SWT :: Multiple Key Events?

Feb 5, 2014

Can you have multiple key events? by that I mean say you press the right arrow key, or a number on the numeric pad, then you press the letter c. does the second key event get fired? and i can catch both events?

View Replies View Related

Swing/AWT/SWT :: How To Run Multiple Frames In BlueJ

May 27, 2014

I've been doing a course with a heavy focus on applets and AWT using BlueJ. I've branched out and learn to convert my applets to applications. I can successfully use frames to do similar things to applets (in BlueJ's applet viewer) but I can not seem to run more than application at a time (unlike applets where I could run several at the same time).

Below is a simple Hello World program I wrote. When I re-run main() it closes the original and starts again. (I'm aiming to explore the java.net.* libraries and for testing would like to use more than one frame at a time which can communicate to each over via sockets).

import java.awt.*;
import java.awt.event.*;
public class HelloWorld extends Frame implements WindowListener {
public static void main (String[] args) {
HelloWorld app = new HelloWorld();
app.setSize(500,500);

[code]....

View Replies View Related

Swing/AWT/SWT :: Multiple Values In Dialog Box

Feb 20, 2014

The below program ask the user to enter the value of x 1 , Y 1 and radius in separate boxes , What would look nice is if the user can Enter the Value X ,Y and radius in the same box.

import javax.swing.JOptionPane;
public class C3E29GeometryTwoCircles {
public static void main(String[] args) {
// Ask the user to enter the x1 coordinate.
String strNumber = JOptionPane.showInputDialog("Enter the value of x1 coordinate " );
double x1 = Double.parseDouble(strNumber);
strNumber = JOptionPane.showInputDialog("Enter the value of y1 coordinate " );
double y1 = Double.parseDouble(strNumber);

[code]...

View Replies View Related

Swing/AWT/SWT :: Multiple Action Listeners?

Oct 25, 2014

So im making a calculator just basic 4 function with a clear button. as i am working into this project i am running into an issue of assigning which click sets what. For instance i click the two button how do i tell it to assign it to firstNum, versus secondNum?

private class theHandler implements ActionListener{
public void actionPerformed(ActionEvent event){
if(event.getSource()==one){
firstNum=1;
}
if(event.getSource()==two){
secondNum =2;
}
if(event.getSource()==three){
secondNum =3;
}

So this for instance allows me to set one to the firstNum and then add it to two or three but im not sure what to do next. I have in my mind i want to do something like make three listener classes, that operate in sequential order like you pick the first numbers, click an operation, and then select the second numbers then hit the operation(equal) button to display answer. Am i on the right track or what?

View Replies View Related

Swing/AWT/SWT :: Splitting GUI Into Multiple Classes?

Sep 12, 2014

I'm trying to create a Java swing chess application, but would like to divide the GUI part of it into at least two different classes (possibly more later, but I'm not sure yet). Currently I have a mainGUI class and a ChessBoard class, both of which extend JFrame. I want the main GUI class to contain a JPanel which will house several components, including a JPanel originating from the chessboard class that contains the actual board.

Is there any way to do this? I tried just creating a ChessBoard object in my main GUI class and then adding it to the component, but I got an illegal argument exception, because apparently you can't add one JFrame to another. How to do what I'm trying to do, or just how to split GUIs into multiple classes in general?

View Replies View Related

Drawing Multiple Objects Swing

Jun 30, 2014

I have to do an assigment using Swing, where I have to make a Board(extends JPanel) and add multiple instances of moving elements to it, with following requirements:

By adding a new object to the Board, the others must not slow down. Also the user interface must not be blocked by the moving objects. So, the movement of the objects must be handled in a separate thread.

and

The application must support adding lots of objects, so it is not okay if every object has its own thread, as this would take too many resources. Design the application in such a way that it uses a constant number of threads, meaning that the number of threads does not grow when adding more objects.

The question is:

How to do this thing with constant number of threads?

View Replies View Related

Swing/AWT/SWT :: Using Multiple SwingWorker Threads

Aug 23, 2014

I have a Swing UI in which on click of Search button, I trigger the Search in 6 different modules in 6 Swing Worker threads. The results are returned by each Swing Worker class to the calling class.

I tried to use the below code to get the values returned from each thread. Now, I want to continue further only after all threads finish their execution. How to achieve this?

thread1.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (StateValue.DONE == thread1.getState()) {
try {

[Code] ....

I got several examples where the UI is updated direstly from multiple threads. I want the values to be returned to calling class because of below reasons:

1) When even one worker thread fails for some reason, I dont want to show the any result in the UI
2) Earlier, I was updating the UI in done() of every worker class. But, UI became inconsistent. E.g When one thread is in progress, other threads were completed and updating the UI which I dont want to do.

View Replies View Related

How To Validate And Integer From 0 - 9

Nov 5, 2014

I created a GUI with a jTextField as an input box and am wondering how to validate that this data is an integer from 0 - 9. Here is what I have. However the if statement shows an error that says int cannot be dereferenced.

private void doneButtonActionPerformed(java.awt.event.ActionEvent evt) {
//Create and Initialize Variable
int category = Integer.parseInt(categoryInput.getText());
if (category.matches(0-9)); //int cannot be dereferenced error here
{

[Code]...

View Replies View Related

Swing/AWT/SWT :: Implementing Multiple Event Handlers

May 3, 2014

I'm having difficulty implementing keyboard and mouse event handlers at the same time for a program designed to notify the user when a key has been pressed or a mouse button clicked.

I can make and understand a program that does one or the other, but when I try to combine them, either the keyboard only or the mouse only works.

here is the code:

import java.awt.Color;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import java.awt.event.MouseListener;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Display And Recolor Multiple Circles?

Feb 22, 2014

I have created two classes. The FrameViewer is my driver class, and Circle is my constructor.

The first problem is, the program seems to be creating both circles, but it only displays displaying the last added circle (in this case, circle2).

The second problem is, I want to pass the color I wish to use to the constructor, but I'm having problems figuring out the proper method to do so. In the constructor, I have assigned Color.BLUE as a default. On circle two, I want to override this color choice and assign Color.Orange. I am not having any luck setting this to work either.

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
public class FrameViewer {
public static void main(String[] args) {
JFrame frame = new JFrame();

[code]....

View Replies View Related

Swing/AWT/SWT :: Multiple JFrames - Thread And Progress Bar

Mar 29, 2014

I'm struggling with a small project. I have 2 jFrames. The first frame has a button that...

- Display's the second frame containing a progressbar
- Starts a heavy processing thread

I need to update the progressbar on the second jFrame, from a thread started on the first jFrame.

I have 2 problems:

- How do I update the progressbar?
- When the button is clicked, an empty second frame is displayed with no controls. The controls are only rendered/shown, after the large thread process is finished...

I've attached to this post a small screenshot, showing the main idea ...

Source code:

Button action on the first frame:

private void btnGoActionPerformed(java.awt.event.ActionEvent evt) {
Progress progress = new Progress(); // The second frame
progress.setVisible(true);
clsProcess myProcess = new clsProcess(); // The thread process
myProcess.start();

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Multiple Textfields Using FocusGained Event

Oct 11, 2014

I have a bunch of textboxes in a panel and I wanted to perform the same code when the user clicks into a textbox (select all the text in it). Right now I've started adding a focusgained listener to each textbox like this:

private void textField1FocusGained(java.awt.event.FocusEvent evt) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
textField1.selectAll();
}
});
}

[Code]...

Is there a way I can have one focusgained listener that all the textfields can point to but have it pick the right textfield in the textFieldx.selectAll();?

View Replies View Related

Swing/AWT/SWT :: Setting Multiple Values To Textarea

Jun 18, 2014

I am making use of NetBeans IDE 8.0 to build a GUI. The idea is that I set multiple values received from textfields to textarea. This will enable me print the work. But ONLY ONE value from textfields is set(appear on textarea); the others do not appear at all. Below is example of what I mean:

String s = jTextField1.getText();
JTextArea1.setText(s);
String x =
jTextField2.getText();
JTextArea1.setText(x);

Only one is being set. The rest are not.

View Replies View Related

JSP :: Validate Username And Password

Apr 21, 2014

I want to validate username and password in JavaScript. I want to validate username and password with database values. If login failed i want to display alert message...ok. But problem is that i have index.jsp page. After clicking login button control goes to homepage.

jsp..okk.. in index.jsp I have taken dropdown to show designation. I select design then control goes to respective homepage... in homepage. I am checking username and password with database values. If login successful it goes to respective pages but if login failed it has to show me alert message. How can i do that ?

View Replies View Related

JSP / JSTL :: Pass Value And Validate

Feb 15, 2013

Why will this NOT validate correctly in my IF Statement? Basically, a user chooses an option from the drop down list. The value is passed to t.jsp (itself) and if the option "All" is chosen, then it does something. If any of the years are chosen, then it does something else.

t.jsp (simplified version of what I want)

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<html>
<form method="get" action="t.jsp">
Select Year:

[Code] ....

View Replies View Related

Swing/AWT/SWT :: How To Cater For Multiple Special Events Of Life

Jan 15, 2014

My program has the following requirements.

Several kinds of celebration dates are displayed.

Say Marriage, a new baby is born and so on. Such special dates are not fixed to be once or twice.

Such that a person can have a marriage and a new born baby celebration or both. One of my thoughts was to used several (up to 3). JLabels and JDateChoosers, but it is quite limiting.

How should I design such a component so that it can accommodate several major events of life.

View Replies View Related







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