Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Applets-working with buttons

  Asked By: Madeline    Date: Jun 29    Category: Java    Views: 780
  

This is a simple applet program in which I have added two buttons
and a text fiedls.
when i press enter button i want to display what's written in the
text field to be displayed
while clicking the cancel btton should close the applet.
I want to know how to display and close the applet
----------------------------
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*
<applet code ="ChatWindow" width =300 height =50>
</applet>
*/
public class ChatWindow extends Applet implements ActionListener
{
Button Enter,Cancel;
TextField name;
String msg =" ";
public void init()
{
Panel p = new Panel();
setFont(new Font("SansSerif",Font.BOLD,12));
Label login = new Label("LOGIN",Label.LEFT);
p.add(login);
name = new TextField(15);
p.add(name);
Enter = new Button("Enter");
p.add(Enter) ;
Cancel = new Button("Cancel");
p.add(Cancel) ;
add("Center",p);
Enter.addActionListener(this);
Cancel.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str = ae.getActionCommand();
if(str.equals("Enter"))
{

}
else
{

};
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg,50,20);
}
}



Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Applets-working with buttons Or get search suggestion and latest updates.




Tagged: