Can anyone help me and tell me how to write to a field after someone has pressed the update button in the frame.
I Have the texfield and the button but dont know how to use actionlistener and send info to file.
Thank you
here is my code:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.JComponent.*;
public class update extends JFrame
{
// instance variables - replace the example below with your own
private JTextField text;
private JButton button1;
/**
* Constructor for objects of class update
*/
public update()
{
// initialise instance variables
GridBagLayout layout = new GridBagLayout();
GridBagConstraints layoutConstraints = new GridBagConstraints();
getContentPane().setLayout(layout);
JTextField text = new JTextField ("");
layoutConstraints.gridx = 2; layoutConstraints.gridy = 1;
layoutConstraints.gridwidth =1; layoutConstraints.gridheight = 1;
layoutConstraints.fill = GridBagConstraints.BOTH;
layoutConstraints.ipadx = 2;
layoutConstraints.ipady = 0;
layoutConstraints.insets = new Insets(150, 50, 250, 50);
layoutConstraints.anchor = GridBagConstraints.NORTH;
layoutConstraints.weightx = 1.0; layoutConstraints.weighty = 1.0;
layout.setConstraints(text, layoutConstraints);
getContentPane().add(text);
button1 = new JButton("Update");
layoutConstraints.gridx = 2; layoutConstraints.gridy = 1;
layoutConstraints.gridwidth =1; layoutConstraints.gridheight = 1;
layoutConstraints.fill = GridBagConstraints.HORIZONTAL;
layoutConstraints.ipadx = 2;
layoutConstraints.ipady = 0;
layoutConstraints.insets = new Insets(530, 180, 3, 50);
layoutConstraints.anchor = GridBagConstraints.NORTH;
layoutConstraints.weightx = 1.0; layoutConstraints.weighty = 1.0;
layout.setConstraints(button1, layoutConstraints);
getContentPane().add(button1);
}
//This makes the GUI
public static void main( String args[] )
{
// Create an instance of the test application
update mainFrame = new update();
mainFrame.setSize(600,800);
mainFrame.setVisible( true );
}
}
I Have the texfield and the button but dont know how to use actionlistener and send info to file.
Thank you
here is my code:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.JComponent.*;
public class update extends JFrame
{
// instance variables - replace the example below with your own
private JTextField text;
private JButton button1;
/**
* Constructor for objects of class update
*/
public update()
{
// initialise instance variables
GridBagLayout layout = new GridBagLayout();
GridBagConstraints layoutConstraints = new GridBagConstraints();
getContentPane().setLayout(layout);
JTextField text = new JTextField ("");
layoutConstraints.gridx = 2; layoutConstraints.gridy = 1;
layoutConstraints.gridwidth =1; layoutConstraints.gridheight = 1;
layoutConstraints.fill = GridBagConstraints.BOTH;
layoutConstraints.ipadx = 2;
layoutConstraints.ipady = 0;
layoutConstraints.insets = new Insets(150, 50, 250, 50);
layoutConstraints.anchor = GridBagConstraints.NORTH;
layoutConstraints.weightx = 1.0; layoutConstraints.weighty = 1.0;
layout.setConstraints(text, layoutConstraints);
getContentPane().add(text);
button1 = new JButton("Update");
layoutConstraints.gridx = 2; layoutConstraints.gridy = 1;
layoutConstraints.gridwidth =1; layoutConstraints.gridheight = 1;
layoutConstraints.fill = GridBagConstraints.HORIZONTAL;
layoutConstraints.ipadx = 2;
layoutConstraints.ipady = 0;
layoutConstraints.insets = new Insets(530, 180, 3, 50);
layoutConstraints.anchor = GridBagConstraints.NORTH;
layoutConstraints.weightx = 1.0; layoutConstraints.weighty = 1.0;
layout.setConstraints(button1, layoutConstraints);
getContentPane().add(button1);
}
//This makes the GUI
public static void main( String args[] )
{
// Create an instance of the test application
update mainFrame = new update();
mainFrame.setSize(600,800);
mainFrame.setVisible( true );
}
}