Could you please help me with something I am trying to acheive. I am using Java 6 and Eclipse 3.5.0.
I am new to programming generally and have created two java files. Driver loads the UserForm and will go on to control a number of other files eventually. UserForm is just a really basic form to allow data entry which I will tidy up later.
As it stands, when Driver is run, UserForm is called and run, the user can input two numbers for e.g "1" and "5", which (and this is the bit I am struggling with) I then need to send to the Driver script when OK is clicked.
Can anyone help please?
PS I could also do with some way to shut down the UserForm without closing the whole program, ideally after UserForm has been closed, it would relinquish control back to Driver, but I am not sure how to do this either. - any thoughts?
Thanks a lot.
phil.
public class Driver
{
public static void main(String[] args)
{
//brings in UserForm class and sets it up to be displayed by Driver
UserFormNew userformnew = new UserFormNew();
userformnew.setVisible(true);
}
}
And
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class UserFormNew extends JFrame
{
private JTextField textFieldHigh;
private JTextField textFieldLow;
public String strLow;
public String strHigh;
public int intrecordnolow;
public int intrecordnohigh;
//This actually builds form using the methods I have put in private voids
public UserFormNew()
{
createTextFields();
createOKButton();
setSize(300,400);
setTitle("test");
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private void createTextFields()
{
textFieldHigh = new JTextField(10);
add(textFieldHigh, BorderLayout.NORTH);
textFieldLow = new JTextField(10);
add(textFieldLow, BorderLayout.SOUTH);
}
public void createOKButton()
{
JButton OkBtn = new JButton("OK");
add(OkBtn, BorderLayout.EAST);
class ClsOKBtn implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
//do something when action performed
strLow = textFieldLow.getText();
strHigh = textFieldHigh.getText();
System.out.print(strHigh);
System.out.print(strLow);
return;
}
}
//Need to add listener to ok button object here
ActionListener listener = new ClsOKBtn();
OkBtn.addActionListener(listener);
}
}