hi everybody, i am new at java, hope anybody can help
i need a java applet to show a message, like the alert in javascript, i don't know if i can do that, hope the answer is yes, thanks for your help
any advice would help
Yes, there are countless ways to displays messages in Java Applets.
1. Put a label on your applet and use the setText() to change a message for the label caption.
2. Use the showStatus() to put a string on the status bar of your applet.
3. Use JDialog (swings) or Dialog (awt) to interface with the user with messages or input, etc.
4. Create your own JFrame (swings) or Frame (awt) to give a message to the user.
5. My favorite, if using Swings, JOptionPane.showMessageDialog().
6. Use the drawString() method of the Graphics class to write text directly on your applet.
There are other ways to display messages. I would start with the JOptionPane, Dialog, or JDialog. These are all GUI type objects which work great for this.
thanks Brian, for your help but i don't know a thing about java can you help me again
for example try with dialog --> java.awt
give me an example code, please
public class DialogTest extends Applet implements ActionListener
{
public void init()
{
setLayout(null);
setSize(100,100);
Button b1 = new Button("Click!"
b1.setBounds(new Rectangle(10,10,50,20));
b1.addActionListener(this);
add(b1,null);
}
public void actionPerformed(ActionEvent e)
{
String s = e.getActionCommand();
if (s.equals("Click!")
JOptionPane.showMessageDialog(null,new String("Alert!!");
}
}
Regards,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.