I'm new to Java programming. I'm using JDK 1.7.
I can not get this field to clear, tired many different methods i've seen online.
Not sure what i'm doing wrong. Can someone please help?
Here is my SSCCE, there is 3 different Classes.
import java.awt.*; import javax.swing.*; public class TheLayout extends JFrame { private static final long serialVersionUID = 1L; 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++ ; } }
I'm not concerned with the output to work properly just want to get JTextField displayDown to clear for now.