Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

java applet to show message 1

Status
Not open for further replies.

pichi

Programmer
Nov 12, 2000
156
0
0
EC
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

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

Good luck,
Brian
 
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

thanks

Juan Pablo
 
Hi,

Take a look at this code,

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

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 :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top