In this code, I am trying to get the window to hide away when I click the hide button. Clicking the button activates the makeHidden()
method I have, but it's made on the same level as public static void main(String[] args)
, and that's where the window visibility is set. I can't seem to reference myWindow
from the makeHidden
method, and I don't know what put put before myWindow.setVisability();
to make it reference it.)
I can't figure this one out, and need help.
import java.awt.*;
import java.awt.event.*;
public class Main extends Frame implements WindowListener,ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
Label text = new Label("not Posted");
Button authentweet, hide;
final static String newline = "\n";
public static void main(String[] args) {
Main myWindow = new Main("TwitterBot");
myWindow.setSize(350,100);
myWindow.setVisible(true);
}
public void makeHidden() {
//this is where i want to make the window hide
}
public Main(String title) {
super(title);
setLayout(new FlowLayout());
addWindowListener(this);
authentweet = new Button("Make Post");
hide = new Button("Hide");
add(authentweet);
add(text);
add(hide);
authentweet.addActionListener(this);
hide.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == authentweet)
{
TwitterPost.makepost();
text.setText("Posted");
}
if (e.getSource() == hide)
{
makeHidden();
}
}
public void windowClosing(WindowEvent e) {System.exit(0);}
public void windowOpened(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
}