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);
Re: JTextField setText problem
Removed form http://www.java-forums.org/awt-swing...textfield.html
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
http://www.java-forums.org/forum-gui...w-members.html
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.
db
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
Re: JTextField setText problem
Don't double post. I've merged the new thread you started.
Quote:
Please check my SSCCE at google docs.
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.
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.
db
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.
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++ ;
}
}
Re: JTextField setText problem
You have been alerted to the Forum Rules, which specifically state Quote:
Please do not start more than one topic (in the same OR different forums) with the same question or message.
You have been specifically told about this: Quote:
Originally Posted by
DarrylBurke
Don't double post.
Any more threads with the same question and you will face a ban.
db
Re: Help before Darryl locks this please
Quote:
Originally Posted by
LancePaxton
Darryl I know you don't want to help
you made that clear.
Don't put words in my mouth. State your assumptions for what they are: your assumptions.
Oh, and forum members are going to be falling over themselves to help you after that. Not.
db