So I would like to create a bar where people can type a message into my application (this message isn't doing anything in the application itself). After the user is finished typing their code (after they hit submit or hit enter), I would like the application to create an external text document with the input that the user had just typed. This text document would be in the same folder as the application, preferably. The code is from another stackoverflow post, Java swing getting input from a JTextField. Any help would be greatly appreciated. Sorry for the previous lack of detail ;)
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
//start of the Swing application
public class ClassFrame extends JFrame {
private static final long serialVersionUID = 2451829341034438685L;
public static JButton inputButton = new JButton("Send");
public static JTextArea editTextArea = new JTextArea("Type Here!");
public static JTextArea uneditTextArea = new JTextArea();
private String myString;
public ClassFrame(String title) {
setLayout(new BorderLayout());
uneditTextArea.setEditable(false);
editTextArea.setBackground(Color.BLUE);
editTextArea.setForeground(Color.WHITE);
Container c = getContentPane();
c.add(uneditTextArea, BorderLayout.CENTER);
c.add(editTextArea, BorderLayout.SOUTH);
c.add(inputButton, BorderLayout.WEST);
ClassFrame.inputButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
myString = editTextArea.getText();
editTextArea.setText("");
System.out.println(myString);
}
});
}
}
//end of the Swing application
Aucun commentaire:
Enregistrer un commentaire