I am writing a program from class, and I am attempting to have it set up so a window is created which shows search results in the form of buttons. I would like it if there are no search results, that the window would call a pop-up warning stating such and then just close the window.
I have it setup that whenever I want to make the window close, I call a CloseWindow() method that just contains a this.dispose(); command. If I call it from the actionEvent method once a button is pushed, the window closes fine, but if I try to call it almost anywhere else in the method, it will not close the window. Is there some basic Java concept I am missing? I know the JFrame has the dispose method from the Window class, but "this" seems to only work under certain conditions.
The relevant code is below:
public class MovieSearch extends JFrame implements ActionListener, Serializable{
private static final long serialVersionUID = 7526471155622776147L;
private Container con = getContentPane();
int llSize, searchResults = 0;
MovieNode currentNode;
String searchText;
JPanel listPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
JScrollPane scrollPane = new JScrollPane(listPanel);
public MovieSearch(String searchText){
super("Search Results");
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.searchText = searchText;
con.add(scrollPane);
currentNode = MovieView.firstNode;
for(int i = 0; i < llSize; i++){
if (currentNode.getTitle().indexOf(searchText) != -1) {
BufferedImage Thumbnail = new BufferedImage(200, 300, BufferedImage.TYPE_INT_ARGB);
Thumbnail.getGraphics().drawImage(currentNode.getImage().getImage(), 0, 0, 200, 300, null);
ImageIcon icon = new ImageIcon(Thumbnail);
JButton button = new JButton("Go to " + currentNode.getTitle());
button.addActionListener(this);
button.setVerticalTextPosition(AbstractButton.BOTTOM);
button.setHorizontalTextPosition(AbstractButton.CENTER);
button.setIcon(icon);
listPanel.add(button);
searchResults++;
currentNode = currentNode.getLink();
} else {
System.out.println("String " + currentNode.getTitle() + " does not contain String " + searchText);
currentNode = currentNode.getLink();
}
}
if(searchResults == 0){
int messageType = JOptionPane.ERROR_MESSAGE;
JOptionPane.showMessageDialog(null, "No results match that query.", "NO RESULTS!", messageType);
CloseWindow();
}else{
currentNode = MovieView.firstNode;
repaint();
}
}
public void actionPerformed(ActionEvent e){
Object source = e.getSource();
for(int i = 0; i < llSize; i++){
JButton button;
button = (JButton) source;
if(button.getText().equals(("Go to " + currentNode.getTitle()))){
MovieView.currentNode = currentNode;
MovieView.searchTextField.setText("");
CloseWindow();
}
System.out.println("button is " + button.getText());
System.out.println("text is: " + "Go to " + currentNode.getTitle());
currentNode = currentNode.getLink();
}
}
private void CloseWindow(){
System.out.println("Closing Window");
this.dispose();
}
}
Again, the CloseWindow() method [and hence the this.dispose() method] works when called form the ActionEvent method but not from anywhere else. [I have inserted it into other places just to test and it is reached but it still does not close the window.]
As you can see, I put a println in the CloseWindow() method to make sure that it was being reached and it is reached every time, it just isn't working.
Any insight into this would be very appreciated. Thank you for your time.
A JOptionPane creates a "modal dialog" which means that the statements after the "showMessageDialog" to not execute until after the dialog is closed.
You have two options:
a) create you own custom "non modal dialog" that displays your message and then closes.
b) Read the JOptionPane API. It shows you how to manually access the dialog that is create by the JOptionPane class so you have a reference to the dialog.
In both cases you would need to start a Swing Timer before you display the dialog. Then when the Timer fires you can dispose the dialog.
Related
I'm coding a memory matching game using pictures and a JButton array, but I've run into a problem when I try to compare two buttons that were clicked. How do you store the index of/get the index of the second button? All of my buttons in the button array are linked to the same actionListener but e.getSource() will only get the first button clicked, as far as I'm aware. I'd really appreciate some help. (I didn't want to paste in my entire code, because that's a lot, so I'm just putting in parts I think are relevant):
public DisplayMM(ActionListener e)
{
setLayout(new GridLayout(6, 8, 5, 5));
JButton[] cards = new JButton[48]; //JButton board
for(int x = 0; x < 48; x++) //initial setup of board
{
cards[x] = new JButton();
cards[x].addActionListener(e);
cards[x].setHorizontalAlignment(SwingConstants.CENTER);
cards[x].setPreferredSize(new Dimension(75, 95));
}
private class e implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
for(int i = 0; i < 48; i++)
{
if((e.getSource())==(cards[i]))//1st button that was clicked
{
cards[i].setIcon(new ImageIcon(this.getClass().getResource(country[i])));
currentIndex = i;
}
}
//cards[i].compareIcons(currentIndex, secondIndex);
}
}
Also, in my Panel class, I attempted to do something similar, but ended up moving it to the Display class because Panel didn't have access to the button array.
//Panel
public void actionPerformed(ActionEvent e)
{
/*every 2 button clicks it does something and decreases num of tries*/
noMatchTimer = new Timer(1000, this);
noMatchTimer.setRepeats(false);
JButton source = (JButton)e.getSource();
guess1 = source.getText(); //first button clicked
numGuess++; //keeps track of number of buttons clicked
JButton source2 = (JButton)e.getSource();
guess2 = source2.getText();
numGuess++;
if(numGuess == 1)
display.faceUp(cards, array, Integer.parseInt(e.getSource()));
else
display.compareIcons(guess1, guess2);
if(tries != 12 && count == 24)
{
displayWinner();
}
}
You can give your ActionListener class private fields, even if it's an anonymous inner class, and one of those fields can be a reference to the last button pushed. Set it to null after the 2nd button is pushed and you'll always know if the button press is for the first or second button.
e.g.,
class ButtonListener implements ActionListener {
private JButton lastButtonPressed = null;
#Override
public void actionPerformed(ActionEvent e) {
JButton source = (JButton) e.getSource();
if (lastButtonPressed == null) {
// then this is the first button
lastButtonPressed = source;
} else {
// this is the 2nd button
if (source == lastButtonPressed) {
// the dufus is pushing the same button -- do nothing
return;
} else {
// compare source and lastButtonPressed to see if same images (icons?)
// if not the same, use a Timer to hold both open for a short period of time
// then close both
lastButtonPressed = null;
}
}
}
}
I am a noob to java and I have hit a snag building my gui...What I need to do is run my shipmentApp program which displays my EnterShipInfo frame that has several text fields to enter data and an enter button that when clicked passes the entered data to my ShipmentFrame. Initially when the frame pops up there should be three labels that just say "label" in them and a display button, then when you click the display button it the data from the text fields pops up in the three labels along with some other words to make a phrase.
// ShipmentFrame code begins here
private static final long serialVersionUID = 1L;
private Label headerLbl = null;
private Button displayButton = null;
private Button Exit = null;
private Label shipLbl = null;
private Label empLbl = null;
private Label dateTimeLbl = null;
private Shipment s;
private Shipment sf;
public ShipmentFrame(Shipment ship){
super();
this.s = ship;
initialize();
s = ship;
}
public void actionPerformed(ActionEvent e) {
shipLbl.setText("Shipment number " + s.getShipmentNum() +
" was received from " + s.getSupplierName());
empLbl.setText("By employee number " + s.getEmployeeNum());
dateTimeLbl.setText("On " + s.getRevDate() + " at " + s.getRevTime());
}
// this is my code from EnterShipInfo
private static final long serialVersionUID = 1L;
private Label headerLbl = null;
private Button displayButton = null;
private Button Exit = null;
private Label dateLbl = null;
private Label timeLbl = null;
private Label suplLbl = null;
private Shipment s;
private Label shipNumLbl = null;
private Label empNumLbl = null;
private TextField empNumTF = null;
private TextField shipNumTF = null;
private TextField dateTF = null;
private TextField timeTF = null;
private TextField supplTF = null;
Shipment ship = new Shipment (" ", " ", " ", " ", " ");
// #jve:decl-index=0:
public EnterShipInfo(){
super();
// this.s = ship;
initialize();
}
// This is the part that was wrong
public void actionPerformed(ActionEvent e) {
String employeeNum = empNumTF.getText();
String shipmentNum = shipNumTF.getText();
String revDate = dateTF.getText();
String revTime = timeTF.getText();
String supplierName = supplTF.getText();
ShipmentFrame sf = new ShipmentFrame(null);
}
//Below is what I was looking for...maybe someone knows more efficient way to accomplish this though
public void actionPerformed(ActionEvent e) {
ship.setEmployeeNum(empNumTF.getText());
ship.setShipmentNum( shipNumTF.getText());
ship.setRevDate( dateTF.getText());
ship.setRevTime(timeTF.getText());
ship.setSupplierName( supplTF.getText());
ShipmentFrame sf = new ShipmentFrame(ship);
}
EDIT
So here's the general process for displaying a Component in a JFrame:
1 - Set up your JFrame (Layouts, borders, etc):
JFrame frame = new JFrame("Frame Title");
JPanel contentPane = ((JPanel) frame.getContentPane());
contentPane.setLayout(new GridLayout(4,1)); //use whatever kind of layout you need
contentPane.setBorder(new EmptyBorder(10,10,10,10)); //use whatever kind of border you need
2 - Initialize your Component(s) (in this case, two JTextFields and a JButton):
JTextField empNumTF = new JTextField("Initial text in field");
JTextField shipNumTF = new JTextField("Initial text in field");
JButton displayButton = new JButton("Display");
3 - Add your component(s) to the JFrame's contentPane:
contentPane.add(empNumTF);
contentPane.add(shipNumTF);
contentPane.add(displayButton);
4 - Pack and make visible:
frame.pack();
frame.setVisible(true);
Then your JFrame should be displayed with those Components.
ADDED
Now, if we want to manipulate what the user enters into those text fields, we need to add an action listener for the button. To do this:
1 - Make one of your classes an action listener (you can use the same class that the JButton is created in if you want) by stating that it implements ActionListener:
public class EnterShipInfo implements ActionListener{
2 - Add an action-listening object to the button like so:
displayButton.addActionListener(this);
//using "this" means that the object this JButton was created in is the action listener.
3 - Add an actionPerformed() method to your ActionListener (as it seems you have already done correctly):
public void actionPerformed(ActionEvent e){
//insert code to execute whenever your button is clicked.
}
So now, specifically to you, inside your actionPerformed() method, you probably want to handle it something like this:
public void actionPerformed(ActionEvent e){
if (e.getActionCommand().equals("Display")){ //"Display" is the text on the JButton
String employeeNum = empNumTF.getText();
String shipmentNum = shipNumTF.getText();
String revDate = dateTF.getText(); //These text fields
String revTime = timeTF.getText(); //not coded in
String supplierName = supplTF.getText(); //my example
ShipmentFrame sf = new ShipmentFrame(new Shipment(shipmentNum, supplierName, revDate, revTime, employeeNum)); //I'm just guessing at the order these come in
sf.setVisible(true);
}
}
Some key documentation you may want to take a look at:
javax.swing.JFrame
javax.swing.JPanel
javax.swing.JTextField
javax.swing.JButton
javax.swing.border.EmptyBorder
java.awt.GridLayout
I'm trying to write the contents of an array to a JTextArea. I've tried everything I can think of, and I can't understand what isn't working here. I've stripped the unnecessary stuff out of my code, here's the two relevant classfiles:
Main class:
package irclogtest;
public class BriBotMain {
public static void main(String args[]) throws Exception {
boolean startup = true;
//frame test launch
BriDisplayGUI data = new BriDisplayGUI(startup);
data.irclog.append("BriBot Startup Successful!" + "\n");
//example access through function when startup is false (only in main class for sample code to demonstrate issue)
try {
BriDisplayGUI data2 = new BriDisplayGUI(false); //tells us which class we're accessing
String[] textForGUI = new String[2]; //tells us the array has 2 lines
textForGUI[0] = "this is the first line"; //set the first line of the array to this text
textForGUI[1] = "this is the second";
data2.arrayToDisplay(textForGUI); //appends contents of array to text window
}
catch(Exception e) {
System.out.println(e);
}
}
}
GUI display class:
package irclogtest;
import java.awt.event.*;
import java.io.IOException;
import javax.swing.*;
public class BriDisplayGUI extends JFrame implements ActionListener {
private static final long serialVersionUID = -7811223081379421773L;
String file_name = "C:/Bribot/logfile.txt";
//these lines create the objects we use
JFrame frame = new JFrame();
JPanel pane = new JPanel();
JButton pressme = new JButton("Click here");
JButton pressme2 = new JButton("Also here");
JTextArea irclog = new JTextArea( 20, 70);
JScrollPane scrollirc = new JScrollPane(irclog);
public BriDisplayGUI(boolean startup) { //startup function, opens and sets up the window
if(startup == true){
frame.setTitle("Bribot Test Frame"); frame.setBounds(100,100,840,420); //sets title of window, sets position and size of window
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //tells program to end on window close
frame.add(pane); //adds the main display pane to the window
//panel customization goes here
pressme.addActionListener(this);
pane.add(pressme);
pressme2.addActionListener(this);
pane.add(pressme2);
pressme.requestFocusInWindow();
irclog.setEditable(false);
scrollirc.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
pane.add(scrollirc);
irclog.setLineWrap(true);
irclog.setWrapStyleWord(true);
//pane.add(inputthing);
frame.setVisible(true);
} else {
System.out.println("Display Class Called");
}
}
public void arrayToDisplay(String[] text) throws IOException {
int i;
for ( i=0; i < text.length; i++) {
irclog.append( text[i] + "\n");
System.out.println( i + ": " + text[i]);
}
}
public void singleToDisplay(String text) throws IOException {
irclog.append(text + "\n");
System.out.println(text);
}
//basic event handler
public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
if (source == pressme) {
} else if(source == pressme2) {
}
}
}
The first append works fine, but the second doesn't, and I can't figure out why (although the for loop does, as the contents of the array get written to console). I've searched quite a bit and nothing I've tried works. Can anyone point out the inevitable obvious oversight here? I'm the definition of a novice, so any advice is appreciated.
Thanks!
The default constructor doesn't do anything, meaning it doesn't construct any kind of UI or display, what would be, an empty frame.
You seem to be thinking the text will appear in data when you are appending it to data1
Try calling this(false) within the default constructor
A better solution would be to construct the core UI from the default constructor and from the "startup" constructor call this() and then modify the UI in what ever way this constructor needs
It seems like you write a new program. Why do you use Swing? Did you take a look at JavaFX?
I am not sure if that is going to fix your problem but you could try a foreach
for(String s : text){
irclog.append(s+"\n");
}
I am building a family tree. The application is creating one JLabel by pressing JButton (with the icon as the person's picture) with this code:
JButton newPersonButton = new JButton("New Person");
newPersonButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
final Data data = NewPerson.createPerson(frame);
if (data != null) {
if (Val == "mother") {
JLabel lblHomer = new JLabel(data.names);
lblHomer.setIcon(new ImageIcon(data.fileID));
cooX = cooX + 20;
cooY = cooY - 20;
panel_1.add(lblHomer, "cell " + cooX + " " + cooY);
panel_1.revalidate();
}
I need a JLabel created dynamically by clicking an existing JLabel. I can create another JLabel the same way I created the first one, and the new JLabel use the coordinates of the created JLabel as reference. Not just one, I need ALL of the JLabels to generated like that. When I click on them then it creates another. I know how to make one new JLabel by clicking on it:
JLabel lblHomer = new JLabel(data.names);
lblHomer.addMouseListener(new MouseAdapter() {
#Override
public void mouseClicked(MouseEvent arg0) {
final Data data = NewPerson.createPerson(frame);
if (data != null) {
String Val = data.CBvalue;
if (Val == "mother") {
JLabel lblHomer = new JLabel(data.names);
lblHomer.setIcon(new ImageIcon(data.fileID));
cooX = cooX + 20;
cooY = cooY - 20;
panel_1.add(lblHomer, "cell " + cooX + " " + cooY);
panel_1.revalidate();
}
}
}
But, I can't just copy/paste that same code infinitely. I need to write a while loop or something to keep creating mouse listener for every JLabel I create. I need help with that.
Whole code: http://pastebin.com/zLx1zK9Z
EDIT: Data.java:
public class Data {
public final String names;
public final String dateBirth;
public final String bio;
public final String fileID;
public final String CBvalue;
public Data(String names, String dateBirth, String bio, String fileID, String CBvalue) {
this.CBvalue = CBvalue;
this.names = names;
this.dateBirth = dateBirth;
this.bio = bio;
this.fileID = fileID;
}
// getters
}
First...
if (Val == "mother") {
Is not how you compare Strings in Java, instead you should be using "mother".equals(Val)
Next, you could create a factory method which creates your labels, maybe even a utility class that has several different methods for creating yr labels, although I might consider a builder pattern of you got to this point...
public static JLabel createPersonLabel(Data data, MouseListener listener) {
JLabel lblHomer = new JLabel(data.names);
lblHomer.setIcon(new ImageIcon(data.fileID));
lblHomer.addMouseListener(listener);
}
I would then create a custom MouseListener to handle the core functionary
public class DataMouseHandler extends MouseAdapter {
public void mouseClicked(MouseEvent evt) {
final Data data = NewPerson.createPerson(frame);
if (data != null) {
String Val = data.CBvalue;
if ("mother".equals(Val)) {
JLabel lblHomer = createPersonalLabel(data, this);
cooX = cooX + 20;
cooY = cooY - 20;
panel_1.add(lblHomer, "cell " + cooX + " " + cooY);
panel_1.revalidate();
}
}
}
}
As an example. Your even create a custom MouseListener for each type data you might need
Updated
There are any number of options, for example, you could create a factory style method in your NewFamilyTree class that creates and adds the data label based on your needs and the data type...
protected void createAndAddDataLabel(Data data) {
JLabel lblHomer = new JLabel(data.names);
lblHomer.setIcon(new ImageIcon(data.fileID));
cooX = cooX + 20;
cooY = cooY - 20;
panel_1.add(lblHomer, "cell " + cooX + " " + cooY);
panel_1.revalidate();
if (!"mother".equals(data.CBvalue)) {
lblHomer.addMouseListener(new DataMouseHandler());
}
}
Then call it from within your button...
JButton newPersonButton = new JButton("New Person");
newPersonButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
final Data data = NewPerson.createPerson(frame);
if (data != null) {
createAndAddDataLabel(data);
}
}
});
And, as an inner class, you could define the DataMouseHandler...
public class DataMouseHandler extends MouseAdapter {
#Override
public void mouseClicked(MouseEvent e) {
final Data data = NewPerson.createPerson(frame);
if (data != null) {
if ("mother".equals(Val)) {
createAndAddDataLabel(data);
}
}
}
}
If you need this as an external class, you would need to pass the reference of the NewFamilyTree
public class DataMouseHandler extends MouseAdapter {
private NewFamilyTree tree;
public DataMouseHandler(NewFamilyTree tree) {
this.tree = tree;
}
#Override
public void mouseClicked(MouseEvent e) {
final Data data = NewPerson.createPerson(frame);
if (data != null) {
if ("mother".equals(Val)) {
tree.createAndAddDataLabel(data);
}
}
}
}
Updated
Now, having said all that, this is a classic example of where a Model-view-controller approach would be most suitable.
What you should be doing is modelling the family tree in some way, which is divorced from the UI, so it simply focuses on the requirements of the model, how it's structured and how it's managed.
The model would provide feedback from event notification when it's changed in some way.
From there you would wrap a UI around it, so the UI would simply be responsible for rendering the output of the model.
The controller would take actions from the UI and update the model accordingly, which will in turn trigger updates from the model to the UI...
As said in comments, there are a couple of ways to do this. I think the first suggestion is probably best, based on what little I/we understand of what you want to do.
public class ListenerLabel extends JLabel implements MouseListener
{
public void mouseExited() {}
public void mouseEntered() {}
// etc.
public void mouseClicked() {}
{
// here put the code you have for creating another person
// 'this' refers to the label that was clicked on; you can get coordinates
// and whatever you need from that.
}
}
Now instead of creating JLabels to hold your people, you create ListenerLabels; they will interact with your UI just the same as JLabels, but have this extra feature of listening for their own clicks. And their name might be something do with people instead of listening, if they're going to contain code specific to people. ('PeopleLabels', or whatever).
-- edit -- more detail, as requested.
As I look at this again, it seems to me your NewPerson.createPerson() method must be popping up a dialog or something to get information for the new person. I will continue the example assuming that works, though I'd probably have done that differently.
public void mouseClicked()
{
final Data data = NewPerson.createPerson(frame);
if (data != null)
{
if (data.CBvalue.equals("mother")) // I would use a constant or enums here instead
{
ListenerLabel label = new ListenerLabel(data.names);
label.setIcon(new ImageIcon(data.fileID));
int xPosition = this.getX() + 20;
int yPosition = this.getY() - 20;
JPanel enclosingPanel = (JPanel)this.getParent();
enclosingPanel.add(label, "cell " + cooX + " " + cooY);
// set position of new label here?
enclosingPanel.revalidate();
}
}
}
Adding the new panel to the enclosing panel (which is panel_1 in your example, I assume) is a little 'black magic' to me -- unless that panel has a special layout manager, or you've extended JPanel so that add() means something special, I don't see how that's going to do anything useful. But this more-filled-out method shows where to get the existing label coordinates, a way to get the panel enclosing the two labels, and a suggestion where I would expect you to set the position of the new label.
There are a lot of assumptions here, because you haven't shown us executable code. I know it's difficult to extract running code out of a larger system, but be aware (you and other readers) that any answer for incomplete code is based on partly on assumptions made filling it in and partly on assumptions not made about what else is needed or coded elsewhere.
I have a school assignment that i need to create. Below is the info:
Create a frame with ten buttons, labeled 0 through 9. To exit the program, the user must click on the correct three buttons in order, something like 7-3-5. If the wrong combination is used, the frame turns red.
I already finish the frame and the buttons with online research helps, but i just cant make the functionality to work. Please take a look at my codes and thanks in advance.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ComboNumber extends JFrame implements ActionListener{
//variable declaration
int ans1 = 3;
int ans2 = 7;
int ans3 = 1;
int one, two, three;
String inData1, inData2, inData3;
JButton[] button;
//constructs the combolock object
public ComboNumber()
{
//sets flowlayout
getContentPane().setLayout(new FlowLayout());
Container c = getContentPane();
//creates buttons
button = new JButton[10];
for(int i = 0; i < button.length; ++i) {
button[i] = new JButton("" + i);
//adds buttons to the frame
c.add(button[i]);
//registers listeners with buttons
button[i].addActionListener(this);
}
//sets commands for the buttons (useless)
//sets title for frame
setTitle("ComboLock");
}
//end combolock object
//listener object
public void actionPerformed(ActionEvent evt)
{
Object o = evt.getSource();
for(int i = 0; i < button.length; ++i) {
if(button[i] == o) {
// it is button[i] that was cliked
// act accordingly
return;
}
}
}
//end listener object
//main method
public static void main (String[] args)
{
//calls object to format window
ComboNumber frm = new ComboNumber();
//WindowQuitter class to listen for window closing
WindowQuitter wQuit = new WindowQuitter();
frm.addWindowListener(wQuit);
//sets window size and visibility
frm.setSize(500, 500);
frm.setVisible(true);
}
//end main method
}
//end main class
//window quitter class
class WindowQuitter extends WindowAdapter
{
//method to close the window
public void windowClosing(WindowEvent e)
{
//exits the program when the window is closed
System.exit(0);
}
//end method
}
//end class
The basic idea is simple.
You need two things.
What the combination actually is
What the user has guessed
So. You need to add two variables. One contains the combination/secret, the other contains the guesses.
private String secret = "123";
private String guess = "";
This allows you to make the combination as long as you like ;)
Then in your actionPerformed method, you need to add the most recent button click to the guess, check it against the secret and see if they've made a good guess. If the length of the guess passes the number of characters in the secret, you need to reset the guess.
public void actionPerformed(ActionEvent evt) {
Object o = evt.getSource();
if (o instanceof JButton) {
JButton btn = (JButton) o;
guess += btn.getText();
if (guess.equals(secret)) {
JOptionPane.showMessageDialog(this, "Welcome Overloard Master");
dispose();
} else if (guess.length() >= 3) {
JOptionPane.showMessageDialog(this, "WRONG", "Wrong", JOptionPane.ERROR_MESSAGE);
guess = "";
}
}
}