The MessageDialogBox won't appear.

can anybody help me figure what's wrong?

Page 1 of 1

1 Replies - 900 Views - Last Post: 13 July 2009 - 09:01 AM Rate Topic: -----

#1 Ricendithas   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 12-July 08

The MessageDialogBox won't appear.

Posted 13 July 2009 - 08:48 AM

Hi! Below is my code. What happens is that the MessageDialog won't appear. It will be stuck in the search for part, where the program asks for a user input. It won't end. So I was wondering, what's wrong with my code.

Thanks in advance. =)

import java.util.*;
import javax.swing.JOptionPane;

public class WorkingFiles {
	public static void main(String args[]) throws FileNotFoundException {
		// Local variable declarations.
		String file_name, search_text;
		String data_text = "the quick brown fox jumps over the lazy dog.";
		// Input instructions to the console.
		System.out.print("Enter filename: ");
		// Ask for the file name.
		Scanner s = new Scanner(;
		file_name =;
		// Create the text file with filename from the user.
		PrintWriter oFile = new PrintWriter(file_name + ".txt");
		// Input for search keyword.
		System.out.print("Search for: ");
		search_text =;
		if(data_text.indexOf(search_text) != -1)
			JOptionPane.showMessageDialog(null, "\"" + search_text + "\" found!", "Keyword Found", JOptionPane.INFORMATION_MESSAGE);
			JOptionPane.showMessageDialog(null, "\"" + search_text + "\" not found!", "Keyword Not Found", JOptionPane.ERROR_MESSAGE);
		// Close the file.

EDIT: Sorry about the initialization of the search_text. I just forgot to erase that. My teacher told me that even though the progam will stop, chances are there will be times that it won't. [That's what he meant.]

EDIT: Ok, so the code works. The dialog was just behind my IDE. LOL!

This post has been edited by Ricendithas: 13 July 2009 - 04:05 PM

Is This A Good Question/Topic? 0
  • +

Replies To: The MessageDialogBox won't appear.

#2 jpav   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 29
  • Joined: 08-July 09

Re: The MessageDialogBox won't appear.

Posted 13 July 2009 - 09:01 AM

Works for me! Are you sure your dialog isn't just behind something?

As a side, some of your program isn't used, such as the initial value of search_text or anything to do with the output file. Also, you don't need the System.exit(0) at the end of main; the program will stop anyway once it gets here.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1