I was able to make the code do what i want except for the fact i can't get input from this now. What i want to do now is still get text from the JTextfield and return it to the main method that creates the frame object. Can somebody help me get the input from the following code?
package assignment5;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame2 extends JDialog implements ActionListener
{
private String a;
private JTextField field = new JTextField(30);
public Frame2(JFrame parent, String title, String message)
{
super(parent, title, true);
if (parent != null)
{
this.setSize(500,150);
this.setLocation(400,200);
}
JPanel messagePane = new JPanel();
messagePane.add(new JLabel(message));
getContentPane().add(messagePane, BorderLayout.PAGE_START);
JPanel buttonPane = new JPanel();
JPanel button2Pane = new JPanel();
JButton button = new JButton("OK");
JButton button2 = new JButton("Cancel");
buttonPane.add(button);
button2Pane.add(button2);
getContentPane().add(buttonPane, BorderLayout.PAGE_END);
getContentPane().add(button2Pane,BorderLayout.EAST);
//button.addActionListener(this);
button.addActionListener(new ActionListener()
{
@Override
public void actionPerformed( ActionEvent event)
{
parent.dispose();
}
});
button2.addActionListener(new ActionListener()
{
@Override
public void actionPerformed( ActionEvent event)
{
parent.dispose();
}
});
JPanel textPane = new JPanel();
JTextField field = new JTextField(30);
textPane.add(field);
getContentPane().add(textPane, BorderLayout.CENTER);
field.addActionListener(this);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
//pack();
setVisible(true);
}
public void b ()
{
a = field.getText();
}
public String g ()
{
System.out.println("wasdfsdf" + a);
return a;
}
@Override
public void actionPerformed(ActionEvent event)
{
a = field.getText();
System.out.println("wasdfsdfsafddsfsdfsdfsafdsggsdfsdf" + a);
// TODO Auto-generated method stub
}
}