Logo 
Search:

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: 1208
  

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();
screen.setBackground(Color.black);
frame.getContentPane().add(screen);

//Set the frame visible
frame.setVisible(true);

//Diable the resizeable button
frame.setResizable(false);


// Set to ignore the cross button
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);


}

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();
db.setVisible(true);
}

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
db.setVisible(true);
^
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
DialogBox.d.setVisible(false);
}
});

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

// Show dialog
d.pack();
d.setVisible(true);
System.exit(0);
}
}

Share: 

 

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
comprehending.
--->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.




Tagged: