Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

i want a dialog box to pop out when user click the mouse

  Asked By: Everett    Date: Aug 18    Category: Java    Views: 1121

i have a problem here.i want
a dialog box to pop out when user click the mouse.how am i suppose to
do it?thanks alot for helping...
i try something like this but i face with error.(in this case i have
a dialog class and a jframe class)

here is the code:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class ScreenSaver extends JFrame implements MouseListener
int op;
public ScreenSaver()

// Create the frame
String title = "Screensaver";
JFrame frame = new JFrame(title);

//Get the window size

Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();

// Show the frame according to the user's window size
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
frame.setSize(screenWidth, screenHeight);

//Set background screen to black
Container screen = getContentPane();

//Set the frame visible

//Diable the resizeable button

// Set to ignore the cross button


public void mouseEntered(MouseEvent e){}

public void mouseExited(MouseEvent e){}

public void mouseClicked(MouseEvent e)
//this is dialog box from dialog class
DialogBox db = new DialogBox();

public void mousePressed(MouseEvent e){}

public void mouseReleased(MouseEvent e){}

public static void main(String[] args)

ScreenSaver screensaver = new ScreenSaver();


here is my error:
C:\WINDOWS\Desktop\project(latest)\ScreenSaver.java:73: cannot
resolve symbol
symbol : method setVisible (boolean)
location: class DialogBox
here is my dialog class..

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class DialogBox
private static Dialog d;

public static void main(String args[])
Frame window = new Frame();

// Create a modal dialog
d = new Dialog(window, "Unlock Screensaver", true);

// Use a flow layout
d.setLayout( new FlowLayout() );

// Create an OK button
Button ok = new Button ("OK");
ok.addActionListener(new ActionListener()
public void actionPerformed( ActionEvent e )
// Hide dialog

d.add( new Label ("Click OK to continue"));
d.add( ok );

// Show dialog



3 Answers Found

Answer #1    Answered By: Varick Fischer     Answered On: Aug 18

You are asking questions and making the mistakes of someone that has
little comprehension of programming. It is as if you are just trying
to get the answers to get you to pass without actually
--->I recommend this: either purchase or check your local library
for these books, and read them, in this order: Absolute Beginner's
Guide to Programming by Greg Perry, Sams Teach Yourself Java2 in 24
Hours, and finally Sams Teach Yourself Java 2 in 21 Days.
---> If you feel that you do not want/need a foundational
understanding of programming... then go to the library and check out
the Java 2 in 21 days and use the index to answer your questions.

Answer #2    Answered By: Haboos Kauser     Answered On: Aug 18

add :
import java.awt.event.* ;

Answer #3    Answered By: Bama Cohen     Answered On: Aug 18

i include this line,but i still have the same error...
what should i change or include?

Didn't find what you were looking for? Find more on i want a dialog box to pop out when user click the mouse Or get search suggestion and latest updates.