I am new to Java and I want to put a text field of a certain size in a certain coordinate location for a program I am creating. I don't know how to put it in a coordinate location , only in a cardinal location(top, bottom, center, ect). Here is what I have so far:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.text.*;
public class For extends JPanel implements PropertyChangeListener {
private JFormattedTextField amountField;
private NumberFormat amountFormat;
public For() {
super(new BorderLayout());
setUpFormats();
amountField = new JFormattedTextField(amountFormat);
amountField.setValue(3.0);
amountField.setColumns(10);
amountField.addPropertyChangeListener("value", this);
JPanel fieldPane = new JPanel(new GridLayout(0,1));
fieldPane.add(amountField);
setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
add(fieldPane, BorderLayout.CENTER);
}
public void propertyChange(PropertyChangeEvent e) {
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("FormattedTextFieldDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
frame.setSize(dim.width, dim.height);
frame.add(new For());
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
UIManager.put("swing.boldMetal", Boolean.FALSE);
createAndShowGUI();
}
});
}
private void setUpFormats() {
amountFormat = NumberFormat.getNumberInstance();
}
}