Welcome to Dream.In.Code
Become a Java Expert!

Join 150,423 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,085 people online right now. Registration is fast and FREE... Join Now!




Closing an open JFrame

 
Reply to this topicStart new topic

Closing an open JFrame

Mastergeek666
15 Mar, 2008 - 06:18 PM
Post #1

D.I.C Head
Group Icon

Joined: 10 Aug, 2007
Posts: 120


Dream Kudos: 75
My Contributions
I was just wondering if there was a way besides frame.setVisible(false); to close a JFrame that has been called as a Method??? Thanks in advance! icon_up.gif
User is offlineProfile CardPM
+Quote Post

letthecolorsrumble
RE: Closing An Open JFrame
15 Mar, 2008 - 06:38 PM
Post #2

Student of The Sun
Group Icon

Joined: 7 Nov, 2007
Posts: 550



Thanked: 1 times
My Contributions
You could try frame.dispose() that will close the JFrame.

More info here: http://java.sun.com/j2se/1.4.2/docs/api/ja....html#dispose()

Hope that helps. :)
User is offlineProfile CardPM
+Quote Post

Mastergeek666
RE: Closing An Open JFrame
15 Mar, 2008 - 07:14 PM
Post #3

D.I.C Head
Group Icon

Joined: 10 Aug, 2007
Posts: 120


Dream Kudos: 75
My Contributions
Cool, that worked great. Although, I'm still having a problem, the problem is I have a button on the frame and when I click it it is suppose to basically close the frame and it works...the first that is and thats the only time. Can someone help me out. Heres my code:

Here's the frame:
java

public JFrame Extra()
{
extra = new JPanel();
Container zeb = Extra.getContentPane();
eASCII = new JLabel(new ImageIcon("eAsciiTable.jpg"));
Iwonder = new JLabel("I wonder what I could use these for!?!?!?");
exit = new JButton("Exit");
exit.addActionListener(this);
extra.add(Iwonder);
extra.add(eASCII);
extra.add(exit);
zeb.add(extra);
Extra.setTitle("Extended Ascii Table");
Extra.setBounds(475, 425, 600, 420);
Extra.setResizable(false);
Extra.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Extra.setVisible(true);
return Extra;
}


And heres part of my actionPerformed method:
java

public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
String men = e.getActionCommand();
if(source == start)
{
JOptionPane.showMessageDialog(null, "The Objective of the Game is to get the highest score!!!");
Stat();
Board();
Intro.setVisible(false);
}
else if(source == enter)
{
if(inputZ.getText().length() == 0 || inputZ.getText().length() > 1 || inputZ.getText().equals(" "))
{
JOptionPane.showMessageDialog(null, "Please use symbols that are of single digit length!");
inputZ.setText("");
}
else
{
inputZ.setVisible(false);
enter.setVisible(false);
symbol.setVisible(false);
for(int i = 0; i < btns.length && i < btnz.length && i < btnc.length; i++)
{
btns[i].setEnabled(true);
btnz[i].setEnabled(true);
btnc[i].setEnabled(true);
}
}
}
else if(men.equals("Extra's")) // using a menu that will open Extra frame
{
Extra.setVisible(true);
Extra();
}
else if(source == exit) // the exit button on the Extra frame, only works once
{
Extra.dispose();
}
else if(men.equals("Save Game"))
{
SaveGame();
}
else if(men.equals("Close"))
{
System.exit(0);
}
else if(men.equals("Instructions"))
{
JOptionPane.showMessageDialog(null, "Step 1: Put mouse over the 'New Game' menu.\nStep 2: Put your mouse over the desired Game Mode.\nStep 3: Select who is to go first!\nStep 4: Who ever is going first type in a desired symbol to use.\nStep 5: Get the highest score to win!");
}
else if(men.equals("About"))
{
JOptionPane.showMessageDialog(null, "Eradication Co.\nCopyright © 2008 Eradication Co.\nVersion 1.6\n3-D Tic-Tac-Toe\nCreated by Jeffrey Napier");
}
else if(men.equals("Human1") || men.equals("Human2"))
{
inputZ.setText("");
inputZ.setVisible(true);
symbol.setVisible(true);
enter.setVisible(true);
turn.setText("");
sc1 = 0;
sc2 = 0;
p1Score.setText("Player One Score: " + sc1 + "");
p2Score.setText("Player Two Score: " + sc2 + "");
for(int i = 0; i < btns.length && i < btnz.length && i < btnc.length; i++)
{
btns[i].setText("");
btnz[i].setText("");
btnc[i].setText("");
btns[i].setEnabled(false);
btnz[i].setEnabled(false);
btnc[i].setEnabled(false);
btns[i].setSelected(false);
btnz[i].setSelected(false);
btnc[i].setSelected(false);
}
if(men.equals("Human1"))
{
turn.setText("Human1's turn!");
p1 = true;
}
else if(men.equals("Human2"))
{
turn.setText("Human2's turn!");
p1 = false;
}
}
else{}


This post has been edited by Mastergeek666: 15 Mar, 2008 - 07:15 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 08:35PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month