Swing/AWT/SWT :: Taking Inputs Based On Previous User Input
Jun 7, 2014
I'm developing a Swing application for the first time. To test my application, I have currently hardcoded some text labels and fields in a JPanel, so that a user can enter input details for a maximum of 3 segments. But this limits the maximum number of segments to 3. However, the requirement is that when the user enters the number of segments (could be greater than 3 as well), corresponding number of input sets need to be taken.
Screenshot attached, with values entered.
Basically I want to know how I should go about taking the inputs from the user.
View Replies
ADVERTISEMENT
Oct 25, 2014
What I have so far are two classes, Movie class and MovieTestDrive class. I've to get the title, genre and ratings for movies and then put them into an array and call the playIt() method.
I would like to create a for loop to iterate three times for three instances of the Movie class but I don't know how to do it.
When I try to run the code, it won't work and I don't know if this is because I have Scanner running incorrectly whilst encapsulating my data. What I have so far:
class Movie {
// Create instance variables for the Movie class.
private String title;
private String genre;
private int rating;
// Use getters and setters to set and display the variables.
[Code] .....
View Replies
View Related
Apr 9, 2014
Write a java program that will ask a user to input grades until the user inputs the sentinel value -1. The program should test each input to determine whether 0<=grade<=100. If the grade entered is within this range, the program should print "Grade accepted;" if not, the program should print "Invalid input".
View Replies
View Related
Feb 1, 2015
There is a problem that I am facing while using the Scanner class for taking inputs from the user. Suppose if I need to take an integer and a String input from the user, and I take the integer input first then the place where the user has to input the String skips and the variable shows a "" nothing on printing it. Suppose in this code snippet
import java.util.Scanner;
public class Test
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
int n = sc.nextInt();
System.out.println("Enter a word");
String str = sc.nextLine();
System.out.println("Enter integer is " + n);
System.out.println("Entered statement is " + str);
}
}
The output is
Enter a number
13
Enter a word
Enter integer is 13
Entered statement is
I need to know why this happens and how should I avoid it. I've seen that taking the String input first solves the issue but while taking the input in a loop to populate a database the program only lets the user enter the first statement and the following statements are skipped.
View Replies
View Related
Jan 18, 2015
I need to take the users input from 2 boxes and reference that to a sqlite database and populate the fields with the data in the database. I know the database code work.
Here is the code for the "user" form;
Java Code:
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextField;
import java.awt.Font;
[Code] .....
View Replies
View Related
Jan 31, 2015
I am new to learning Java and I am trying to print an unfilled diamond using asterisks. The height of the diamond has to be based on user input. My code currently prints out a filled diamond based on user input but I cannot figure out how to print an unfilled one. Every time I change one of the loops it messes something else up.
[public static void diamond(){
int i = 0;
int j = 0;
int k = 0;
int height = 0;
[code]...
View Replies
View Related
Jul 18, 2014
I am using a GUI to display search results based on user's input server name. I am using MS Access as DB and I have the DSN set up correctly.But the search results are displayed for the first typed value in text filed. I am getting same result set every time though i input different server names .
import java.sql.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.DefaultTableModel;
public class SearchResult implements ActionListener{
[Code]...
View Replies
View Related
May 8, 2014
I have a basic html form with one user input text box labeled "Enter a number" and a submit button labeled "Create a multiplication table". This is the working with a servlet to display an html formatted multiplication table. Everything else is working fine just the formatting is off; I can't seem to get the top row and far left column to number properly. It should look like this with the top row of numbers beginning with a blank cell and then numbering 1 thru n (depending on what the user selects. The first column should be the same, a blank cell and then 1 thru n. Then the multiplication table should be in the rows/columns of the table. Picture this:
I can't get mine to start with a blank cell in the top left-hand corner, instead it has 1 in that cell and the table starts calculating with 2x2.
Servlet code:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
[Code] ....
View Replies
View Related
May 5, 2014
This program contains a superclass and a subclass that will gather the following information from the user:
name, address, phone number, and customer number.
Everything works fine except that I have to create a boolean method in this program that is required to determine based on user input whether they want to be added to a mailing list.
I cannot get this method to work with main, each time it is called it will always return the value but main will constantly read the last statement (else, where it will read "not wanting to be added to the mailing list).
The only way I can get this part of the program to work is by adding an equals method in main that ignores the case, but I am required to write a boolean method so this is not allowed.
Superclass:
public class Person
{
private String name;
private String address;
private String phoneNum;
public Person(String pName, String add, String number)
{
name = pName;
address = add;
[Code] ...
View Replies
View Related
Dec 5, 2014
java program that will determine if the matrix is a lower or upper triangular matrix. I only need to use java.util.Scanner;.
View Replies
View Related
Oct 29, 2014
I have a small bug in my program. The user is asked what person(s) information they want to access but lets say they want captain they must enter "captain" twice. I think it will make more sense to you with the code. I have searched all over to see what is causing the bug but still have found no resolution. I even tried making two different scanners but that didn't work either.
I know the while loop (line 16) I am using is causing the bug because it works fine without that but then I cannot validate the input.
package myproject;
import java.util.Scanner;
public class Enterprise {
public static void main (String[]args){
String userInput;
[Code]......
View Replies
View Related
Feb 3, 2014
I am stumped on a coding project I am working on. I am making an inventory program with predefined values for the items. I am not sure how to iterate through my arrayList, and allow the user to input the "number sold."
I have made an arrayList and populated it using the add(), but I am not sure if it is working correctly. This is my inventoryItem class :
package inventory;
import java.text.DecimalFormat;
public class inventoryItm {
String itemName;
double unitPrice;
int numberSold;
[Code] .....
View Replies
View Related
Sep 28, 2014
I am making a quiz app and stuck with this problem. User is presented with question with options he select one radio button and move on to next question by clicking next button.
Now when user clicks on the previous button to change the previous selction , I want his previous selection to be shown selected. How can I do that.
View Replies
View Related
Feb 7, 2014
I am trying to test the instanceof keyword. To do this, I've made a method with a simple logical test like so:
Java Code:
Vehicle vehicle1 = new Vehicle();
public void Type(){
if (vehicle1 instanceof Vehicle) {
System.out.println("Type = Vehicle");
}
else if (vehicle1 instanceof Car) {
System.out.println("Type = Car");
}
else if (vehicle1 instanceof Truck) {
System.out.println("Type = Truck");
}
}
} mh_sh_highlight_all('java');
I wanted to try implementing it into the class definitions for Vehicle, then extend that to Car and Truck, but I'm not sure how to use this test in a general case.
The only way this method works is if I set the test to specifically accept a specific object as a parameter.
I want to test multiple objects, but I'm not really sure how else to do this without simply copy-pasting the logical test multiple times and changing the respective objects that are used as parameters.
View Replies
View Related
Feb 1, 2013
Previous page can be seen even after user logs out from the JSP page.
My code is:
Logout.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<title>JSP Page</title>
[Code] ....
how to resolve this?
View Replies
View Related
Jun 6, 2014
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
if (input == "next") {
System.out.print("good Job!");
}
else {
System.out.println("Why ?");
}
//If I type in next it prints out "Why ?" instead of "Good Job!" - Why though ?
View Replies
View Related
Sep 21, 2014
I'm doing a problem where someone will input a name and it will show their title or vice versa. It works fine when the user inputs the name but whenever they input a title it is coming back not found. Not sure what I did wrong.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
@SuppressWarnings("serial")
public class JEmployeeTitle2 extends JApplet implements //class extends JApplet and AL.
ActionListener
[code]....
View Replies
View Related
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
Feb 8, 2014
I have a LoginScreen class and one other class in my project. I want use user inputs (Username And Password) on other class if users details is true. I am stcuk at this point because when user attempt to Login connection is succesfully and other frame is coming to screen but i can reach user details anymore. Let me explain with codes;
LoginScreen class
/*
* 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 deneme3;
import java.sql.Connection;
[code]....
You can see Button Action in MainProgramWindow " System.out.println( ??? );" How i can retrieve users inputs from this class ?
View Replies
View Related
Feb 15, 2015
We are writing our own classes and methods. My instructor has provide the code
/*-------------------------------------------------------------------------
import java.util.*;
public class Assignment5 {
public static void main (String[] args) {
[Code].....
I am having trouble with the question counter. I need the counter to increase when c, d or e are entered. I think I need to set up a if or while loop but I'm not sure how to setup the variables. This is what I have for the counter so far.
[public int getNumberOfQuestions(){
numQuestions = 0;
numQuestions ++;
return numQuestions;
}
View Replies
View Related
Aug 9, 2014
I realized that I was not filling the array with anything but now I'm having issues filling it correctly. It's only filling the array with three of the user inputs ....
import java.util.Scanner;
public class DriverSort {
public static void main(String[] args) {
Scanner scan =new Scanner(System.in);
Sorter sorter = new Sorter();
int choice; // variable which says which sorting algorithm to use
[Code] .....
View Replies
View Related
Feb 28, 2015
I need to generate a league table in Java based on results provided in the shape of user input. I have the 6 teams in an array. I need to ask the user how many wins, draws, losses each team has had.
for (String element : teams) {
System.out.println(
"Please enter the number of wins, draws and losses for " + element);
int[] wins = new int [6];
int[] draws = new int [6];
int[] losses = new int [6];
}
How do I pull 3 separate values from the user and then store each value in a separate element of each array? so if one team wins 3, draws 2 and loses 1 - I need to put 3 into the wins array, 2 into the draws array and 1 into the losses array? I then need to total all this in a table.
View Replies
View Related
Apr 18, 2015
I'm working on an assignment for my Java Programming class that requires me to work with Multiple Classes.
Overview of the assignment: Create a "Database" that allows a user to input information about a College Class.
My program has three Classes:
The information that must be tracked in the Course Class is:
- Section Number
- Instructor
- Classroom
- Students (an ArrayList of class Student)
The information that must be tracked in the Student Class is:
- Name
- Major
- GPA
- Hours
The Driver class will use the main method to print the user a prompt asking for inputs, then display all of the user's inputs after he/she wished to exit the program.
I'm having no trouble with asking the user for inputs and then checking the validations for the inputs, I'm currently struggling with return a String that houses all of the user's inputs for the variables above. The information must be returned in a method called toString(). Both the Student and Course Class must have a toString() method that returns the information in the class (value of the variables), I must then call upon these methods from the main method of the Driver Class to print them back to the user.
The toString methods within the Student & Course Classes are at the bottom of the code
To Summarize: What I need to do within the toString() methods to return the values the user has inputted for the various variables? Such as.. Should I pass something through the method? Do I need the this keyboard to pass through the variable again? I just fear that I'm currently misunderstanding a very critical part of programming.
My Driver Class
import java.util.Scanner;
public class Driver {
Course courseInputs = new Course();
Student studentInputs = new Student();
public static void main(String[] args) {
[Code] .....
View Replies
View Related
Jan 30, 2014
import java.util.Scanner;
public class CountStringNumbers { // show the number of Strings that were numbers . . ..
public static void main(String []args){
int count = 0;
int countNumbers=0;
Scanner input=new Scanner(System.in);
[code]...
can count the numbers from 0-9 if the user puted but if it is 10 it doesnt count it , and i need to write all the numbers to have that option. . . . Is there an easy way that includes all the numbers? like if(word.equals(number)){<<<???? (numbers) i know htat doesnt work but is there anything similar ?? ??
countNumbers++;
}
System.out.println("Type Something , , , and to end the the termination type STOP");
word=input.nextLine();
count++;
}
System.out.println("You wrote "+count+" lines wich from those lines "+countNumbers+" were numbers and the programe terminated ");
}
}
View Replies
View Related
Sep 21, 2014
I have an assignment where I'm supposed to write a program where the user inputs a month between 1-12 and then the right amount number in every month. I've tweaked the code a bunch of times, but I keep getting this error message:
insert "}" to complete StatementKALENDER_3.java
insert "}" to complete BlockKALENDER_3.java
The code:
import java.util.*;
import java.util.Scanner;
public class KALENDER_3
}
public static void main(String[] args){
Scanner scanner = new Scanner (System.in);
System.out.print("Skriv ett manadsnummer: ");
[code].....
I think I have just forgot to put in a few { } symbols, maybe an open loop?
View Replies
View Related
Apr 27, 2014
I've built up an unreasonably large and unreasonably complicated JPanel. Unfortunately, when I use setViewportView to add it to a JScrollPane, a get an extended UI freeze—that operation takes several seconds. I'm trying to figure out what's taking so long. I've tried some fairly extreme things, like overriding the paintComponent, PaintComponents, paintChildren, paint, repaint, validate, revalidate, and validateTree methods in the panel with no-ops to try to figure out what's taking so long, but to no avail. I've tried validating the JPanel before adding it, but that has no effect. If I override the addImpl method of the scroll pane, that makes things quick, but it doesn't really narrow things down much.
View Replies
View Related