J
justineee
Hi everyone, I really suck at this..
I have made many frames for my project but my problem is that when I
close one of them.. the whole program closes
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class ConfigGui extends JPanel implements ActionListener {
private JButton okButtonConfig;
private JButton cancelButtonConfig;
private JTextField inputConfig;
public ConfigGui() {
okButtonConfig = new JButton ("Ok");
cancelButtonConfig = new JButton ("Cancel");
inputConfig = new JTextField (5);
setPreferredSize (new Dimension (229, 84));
setLayout (null);
add (okButtonConfig);
add (cancelButtonConfig);
add (inputConfig);
okButtonConfig.setBounds (35, 55, 50, 20);
cancelButtonConfig.setBounds (95, 55, 95, 20);
inputConfig.setBounds (35, 10, 155, 25);
okButtonConfig.addActionListener(this);
cancelButtonConfig.addActionListener(this);
}
public void actionPerformed(ActionEvent jnd)
{
if (jnd.getSource()==cancelButtonConfig)
{
configGui().exit(0);
}
}
public void configGui()
{
JFrame frame = new JFrame ("Set the Dictionary");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new ConfigGui());
frame.pack();
frame.setVisible (true);
}
}
my problem here is in the if statement.. it says "void cannot be
dereferenced"..
I made the frame in void method because I am calling it in another
class..
Any tips please?
I have made many frames for my project but my problem is that when I
close one of them.. the whole program closes
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class ConfigGui extends JPanel implements ActionListener {
private JButton okButtonConfig;
private JButton cancelButtonConfig;
private JTextField inputConfig;
public ConfigGui() {
okButtonConfig = new JButton ("Ok");
cancelButtonConfig = new JButton ("Cancel");
inputConfig = new JTextField (5);
setPreferredSize (new Dimension (229, 84));
setLayout (null);
add (okButtonConfig);
add (cancelButtonConfig);
add (inputConfig);
okButtonConfig.setBounds (35, 55, 50, 20);
cancelButtonConfig.setBounds (95, 55, 95, 20);
inputConfig.setBounds (35, 10, 155, 25);
okButtonConfig.addActionListener(this);
cancelButtonConfig.addActionListener(this);
}
public void actionPerformed(ActionEvent jnd)
{
if (jnd.getSource()==cancelButtonConfig)
{
configGui().exit(0);
}
}
public void configGui()
{
JFrame frame = new JFrame ("Set the Dictionary");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new ConfigGui());
frame.pack();
frame.setVisible (true);
}
}
my problem here is in the if statement.. it says "void cannot be
dereferenced"..
I made the frame in void method because I am calling it in another
class..
Any tips please?