Results 1 to 7 of 7
Thread: JTextField setText problem
- 09-05-2012, 02:40 AM #1
Member
- Join Date
- Sep 2012
- Location
- South Carolina
- Posts
- 3
- Rep Power
- 0
JTextField setText problem
I am having this problem. This method is not working for me. i am new to java and sure i am making a stupid mistake.
When i try this i get a NullPointerException and the JtextField is not clearing. all code not showed using jdk 1.7
public void TheLayout extends Jframe
TheData data;
JTextField displayMessage = new JTextFeild();
JButton clear = new Jbutton("clear");
add.ActionEventListener(data);
displayMessage.setText("data.getMessage()");
add(displayMessage);
add("clear");
---New Class with action and method class---
again not all code here.. think its enough
public void TheData ..........
public String getMessage() {
i have code here to set message
action listener class ().......
if (command == "clear") {
TheLayout gui;
gui.displayMessage.setText(''');}
also tried setText(null);Last edited by LancePaxton; 09-05-2012 at 02:42 AM.
- 09-05-2012, 06:07 AM #2
Re: JTextField setText problem
Removed form Clean the content of the JTextField
When you have a question, start your own thread. Son't post to 5 year old threads and don't hijack another poster's thread.
To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem. Not all your code, but not uncompilable snippets devoid of any context as already posted. But before posting anything more, go through these links:
Forum Rules
Guide For New Members
BB Code List - Java Programming Forum
Do you really have a variable named add that has a method ActionEventListener? If oyu do, please go through Code Conventions for the Java Programming Language: Contents -- method names should start with a lowercase letter.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 09-09-2012, 06:23 AM #3
Member
- Join Date
- Sep 2012
- Location
- South Carolina
- Posts
- 3
- Rep Power
- 0
Problem with clearing JTextField. Getting NullPointerException
I have seen several problems related to this but can't seem to solve this problem.
I am not concerned with getting the correct output in the JTextField at
this time but I would like to at least make the field blank and not get a NullPointerException.
Then I can work on getting the correct result. Please check my SSCCE at google docs.
Please don't be to hard on me for mistakes, I am learning. Thank you for your time.
https://docs.google.com/document/pub...VQBsfpFIXRke4E
- 09-09-2012, 09:06 AM #4
Re: JTextField setText problem
Don't double post. I've merged the new thread you started.
If it's short, it should be possible to post it here. If it's not short, then it's too much to expect forum members to take time over.Please check my SSCCE at google docs.
Moreover, many file sharing sites are blocked by corporate firewalls, so the odd member who is willing to click an external link (I won't) may not be able to get there. Additionally, what's to stop you from taking down the code and leaving this thread with a dead link, of no use to anyone?
A forum is for sharing problems and their possible solutions -- not a free helpdesk.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 09-09-2012, 10:28 AM #5
Member
- Join Date
- Sep 2012
- Location
- South Carolina
- Posts
- 3
- Rep Power
- 0
Help before Darryl locks this please
I can't get the JTextField displayDown to clear and not get a NullPointerException. I was told this isnt a help desk but i see alot of people getting help
here is all the code i believe is relevant. Just want it to clear then I'll figrue out how to get the program to run corrctly as i go.
Darrly says my code has to be able to compile. so here it is please note this is 3 classes. Darryl I know you don't want to help
you made that clear.
Java Code:import java.awt.*; import javax.swing.*; public class TheLayout extends JFrame { TheEvent event = new TheEvent(); TheData data = new TheData(); JTextField displayDown = new JTextField(""); ButtonGroup option = new ButtonGroup(); JPanel row1 = new JPanel(); JButton pass = new JButton("PASS"); public TheLayout() { super("THE FOOTBALL GAME"); setSize(750, 270); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GridLayout layout = new GridLayout(5, 1, 10, 10); setLayout(layout); displayDown.setText(data.getDown()); displayDown.setEditable(true); //Would like this to be false add(displayDown); FlowLayout layout1 = new FlowLayout(FlowLayout.CENTER, 10, 10); pass.addActionListener(event); row1.setLayout(layout1); option.add(pass); row1.add(pass); add(row1); setVisible(true); } public static void main(String[] arguments) { TheLayout frame = new TheLayout(); } } import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; public class TheEvent implements ActionListener, Runnable { TheLayout gui; TheData data; public void run() { // TODO Auto-generated method stub } public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if ( command == "PASS"){ run(); data.setDownInt(); // int num = Integer.parseInt("0" + data.displayDown()); // working on this gui.displayDown.setText(" "); } } public class TheData { TheLayout gui; TheEvent event; public int down ; public String theDown; public int yardsGain; public String getDown() { this.down = getDownInt(); if (down == 1){theDown = (" FIRST DOWN");} if (down == 2){ theDown = (" SECOND DOWN"); } if (down == 3){ theDown = (" THIRD DOWN"); } if (down == 4){ theDown = (" FOURTH DOWN"); } if (down < 1 ||down > 4) { theDown = ("ERROR WITH DOWNS");} return theDown; } public int getDownInt() { return this.down; } public void setDownInt() { this.down = this.down++ ; } }
- 09-09-2012, 11:12 AM #6
Re: JTextField setText problem
You have been alerted to the Forum Rules, which specifically state
You have been specifically told about this:Any more threads with the same question and you will face a ban.Please do not start more than one topic (in the same OR different forums) with the same question or message.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 09-09-2012, 11:14 AM #7
Re: Help before Darryl locks this please
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Problem Loading JTextField in JFrame / Problema al cargar JTextField en JFrame
By thor_inc in forum AWT / SwingReplies: 0Last Post: 08-30-2011, 09:18 AM -
problem with JLabel.setText();
By nonabhai in forum AWT / SwingReplies: 5Last Post: 10-09-2010, 04:44 AM -
If statement and JLabel.setText() problem
By peterhabe in forum New To JavaReplies: 5Last Post: 07-25-2010, 10:11 AM -
setText() problem
By Jozo in forum Java AppletsReplies: 4Last Post: 04-27-2010, 05:29 AM -
setText() problem
By jls7168 in forum New To JavaReplies: 2Last Post: 02-20-2009, 10:34 PM


LinkBack URL
About LinkBacks


Bookmarks