Adding Textbox For Users To Input Text Onto JFrame
Apr 2, 2014
I need adding a textbox for users to input text onto my JFRame. Also how come the
frame.add(o);
is getting an error under the "add".
Main method class:
import javax.swing.JFrame;
public class main
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
bot o = new bot();
[Code] ......
Other class (this is where I want the textbox to be)
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class bot {
int x;
int y;
JTextField f = new JTextField();
JTextArea a = new JTextArea(30, 50);
}
View Replies
ADVERTISEMENT
Aug 25, 2014
i've tried changing the path 10000 times. idk if its wrong in the code.
Java Code: import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
[Code]...
View Replies
View Related
Apr 8, 2015
Here is my code, basically I'll tell you what my program is suppose to do, I want to be able to leave the text box's empty if I like I want to skip 1 or more or all if I like skipping just basically means 0 but getting this error, it's forcing me to type in them all.
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unk nown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at StockControl.addToStock(StockControl.java:86)
[Code] .....
My code :
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
[Code] .....
View Replies
View Related
Apr 8, 2014
I'm doing a problem where I convert users input for the date (MM/DD/YY) into a written out date and year. That part is fine. The part I'm struggling with is then indicating what day that is in that year. how to use the user inputted MONTH, DAY, and YEAR to then get the day of year.
import java.util.Calendar;
import java.util.Scanner;
import java.util.regex.MatchResult;
import javax.swing.JOptionPane;
public class ConvertDate {
[code]...
View Replies
View Related
Feb 8, 2014
I want to limit the program to only accept a 12 digit input and an integer value but I don't know how to program it,
import java.util.Scanner;
public class testing4
{
public static void main(String []args) {
Scanner reader = new Scanner(System.in);
String input;
[Code]...
View Replies
View Related
Nov 20, 2014
im trying to make a small program where the user enters their selection choice and it prints out the corresponding information. for example, if they choose "3", i want "3. Soup de Jour" to print out
import java.util.Scanner;
public class rest
{
public static void main(String[] args)
[Code]....
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
Nov 9, 2014
So currently I am trying to use a JTextarea to display text and I then prompt users to type in certain words. I have a few problems that I have encountered. Firstly when I use setText and then if I say setText again after that it erases the previous text that was set. Ideally I want to set text once per line in my whenever a certain task is fulfilled. For example if the text says enter y/n, I want the program to go to the next line once I say y or n. Another problem of course is when I setEditable to true I can edit the whole textArea. I just want to be able to edit the line which I am currently at. Is there anything that I can use that mimics the ACM console program, or even the console down below in most IDE's where everything appears to be done line by line?
Also here is an example of what I am trying to do, along with comments:
Java Code:
console.setText("Math is good!");
console.setText("What is 2+2?: "); //using getText gets the whole line, I want
//everything checked after the colon. That is where the input will be
if(line==4){
console.setText("That is correct");
}
else {
console.setText("That is incorrect");
}
//previous text lines are overriden with new ones. I don't want that, nor do I want to be able to edit the
//whole JtextArea mh_sh_highlight_all('java');
A JtextArea is just not getting the job done.
View Replies
View Related
Apr 22, 2015
Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program:
calculateAverage This method should accept five test scores as arguments and return the average of the scores. determineGrade This method should accept a test score as an argument and return a letter grade for the score, based on the following grading scale
Score Letter Grade
90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F
double test1,test2,test3,test4,test5;
double average;
char grade;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the first score");
test1 = keyboard.nextDouble();
System.out.println("Enter the second score");
test2 = keyboard.nextDouble();
[code]....
View Replies
View Related
Mar 29, 2015
How do i add my applet to a JFrame? (Ex. When i click on a Menu Item on my frame, i need the applet to be displayed.
The code of my Frame:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
[Code].....
View Replies
View Related
Jul 2, 2014
I am trying to write a game which needs timer beginning from zero to.... , and show it in my jframe. How can I do that?
View Replies
View Related
Apr 18, 2014
The program loads, but nothing shows. I did some research and saw that I needed to set the JFrame to visible at the bottom of the frame section. I made the change, but it still does not show anything. Do I need to add everything that I added to the content pane to the frame? From my understanding you add elements to the panel, the panel to the contentPane, then the pane to the frame...
/*
* Filename: UserInformation.java
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
@SuppressWarnings("serial")
[code]...
View Replies
View Related
Jan 29, 2014
I am trying to put
Java Code:
import javax.swing.*;
import java.awt.event.*;
public class menu {
public static void main (String[] args){
JFrame frame = new JFrame("Menu");
frame.setVisible (true);
[Code] ....
View Replies
View Related
Jul 23, 2013
I am trying to add scrollbars to my frame containing many different components and appearing when user resizes the window with the mouse adds pictures and admin of this online application adds labels or other components.
I want scrollbars to appear when the frame is resized and has components you don't see under so you can scroll down.
If I have for example this code, how i add the scrollbars when i make frame smaller ?
public class Test extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
[Code] ....
View Replies
View Related
May 24, 2014
I decided to write a small Java program to experiment around with BorderLayout, because I'm developing a Java game and I need to have 2 objects placed in a single JFrame at the same time, and everyone I asked said I need BorderLayout to do that.Before you answer: Also, is using BorderLayout the best option for adding multiple video game oriented objects such a sprites to a JFrame?
So the Java program I wrote is supposed to place a JButton on the JFrame and ALSO place a graphic component (a rectangle in this case). The problem is, only the button shows up, as can be seen in the image link below: URL....
Here is the code:
**main.java** --> The main method class + JFrame/JPanel/JButton constructor
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class main {
[code]....
View Replies
View Related
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
Mar 14, 2015
trying to tranfer content of a text area on one jframe to a text area in another
View Replies
View Related
Feb 4, 2015
Basically , I'm trying to make a program that makes the Finch follow the object. I have made two classes :
NewOption52 and FollowClass.
Class NewOption52 contains a method which determines the properties of the GUI. Class FollowClass contains a main method which calls GUI method from class NewOption52 and it also contains several methods which dictates the Finch's behavior alongside with appending text to JTextArea feed.
When I connect the Finch and run the program , a GUI should appear and inside JTextArea should have text which says ""Please Place An Object in front of Finch And Then Tap Finch to Activate!". It didn't happen when I run the program.
Class NewOption52 :
import edu.cmu.ri.createlab.terk.robot.finch.Finch;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import javax.swing.*;
public class NewOption52
[code]....
View Replies
View Related
Apr 11, 2014
I am trying to make a text based game. the game has been working perfectly setting up the rooms, first couple of commands, and running it. I am now trying to add items to it but every time it try to run the game it returns :
java.lang.NullPointerException
at Room.addItem(Room.java:107)
at Game.createRooms(Game.java:133)
at Game.<init>(Game.java:28)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[Code] .....
Here are the classes that matter for this particular situation
import java.util.HashMap;
public class Item
{
private HashMap<String, Item> itemList;
private String name;
private String itemDescription;
[Code] ....
I know that it is the line
itemList.put(item.getItemName(), new Item(item.getItemName(), item.getItemDescription()));
In the game class that is causing the nullpointer exception i just really cant figure out why that keeps happening and how to add the values correctly....
View Replies
View Related
May 19, 2014
I just want to add a text field and a label next to it that says "Hourly Wage".
Also, when I run this in Xcode, it reports back with "Shell Script Invocation Error" "Command usr/bin/java failed with exit code 1".
Here's my program:
package summerIncome;
import java.util.Scanner;
public class SummerIncomeCalculator {
public static void main(String[] args) {
jFrame frame = new Jframe("Summer Income Calculator");
frame.setSize(400,300);
[Code] .....
View Replies
View Related
Apr 14, 2014
I am making a java text adventure and i am trying to add characters to it. I wrote it exactly the same as i wrote the items class (which works fine) but for some reason the character class keeps getting a null pointer exception when it gets to line 140 in the room class
characters.add(c);
game class
import java.util.ArrayList;
import java.util.HashMap;
/**
* Game class for Free Willy Five: an exciting text based adventure game.
*
[Code] ....
View Replies
View Related
May 5, 2014
Your Tester class main method must use an array or an ArrayList of Person objects. It must be populated from a text data file, friends_data.txt. Add the following data to your text file,
Michelle, 12/20/2008, Camilla
Bryan, 3/8/2007, Tom
Camilla, 6/7/2005, Michelle
Tom, 10/15/2007, Bryan
Charlotte, 3/2/2008, Michelle
Each line has the meaning:
-Person name, Person date of birth (MM/DD/YYYY), name of best friend
-Write a Java program that reads in the data from the friends_data.txt file, allocates a new
-Person for each and then stores the newly created object in either an Array or an ArrayList.
-Next print out a report showing the following information for each Person,
1. The Person's name
2. Their popularity counter
3. Their age on May 1, 2014
4. The name of their best friend
5. The age of their best friend on May 1, 2014
Finally, print the name of the most popular Person and the name of the oldest Person.
Person Class
import java.util.ArrayList;
public class Person {
public String personsName;
public String personsFriend;
public String personsBirthday;
public int personsPopularity;
public int popularity = 0;
[code]...
I keep getting this error from the compiler:
System.out.println("Popularity : " + personsOfInterest[i].getPopularityNumber());
"method getPopularityNumber in class Person cannot be applied to given type:
Required: java.lang.String[]; found: no arguments; reason: actual and formal argument lists differ in length.
View Replies
View Related
Dec 8, 2014
I need to write a program that will let a user input name, age, email, and cell phone number, and commit the input to a text file. They need to add multiple entries. I figured out how to create the file and write to it, but when the user enters a second set of information, the first is overwritten. How can I make the file be added to instead of overwritten? The following is my code:
try
{
FileWriter writer = new FileWriter("ContactInformation.txt");
BufferedWriter bw = new BufferedWriter(writer);
nameTextField.write(bw);
bw.newLine();
[Code] ....
View Replies
View Related
Mar 4, 2014
Is this even possible? I would like to make it so I can drag drop an image into a textbox . . .
View Replies
View Related
Oct 2, 2014
I could get my session values in my jsp, now I want to compare the session value whether it matches the textbox, if it matches, it will redirect the user to another page else it will remain the same page.
View Replies
View Related
Nov 9, 2014
I am a beginner . How to add output for both valid and invalid lines in text file scanned in java ...
View Replies
View Related