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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Applet ... NOT PRINTING

Status
Not open for further replies.

sap

Technical User
Aug 20, 2001
37
IN
I 'm beginner of java.I typed following program that uses applet and awt components.As the button is clicked ,what is typed in textfield should be painted over the applet window.
This only happens when i minimize the applet window and again maximize it.can't it paint the contents of textfield into the applet as soon as button is clicked?
Any chang incode is reqd?
thanks.


import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class ActionListener1 extends Applet implements ActionListener
{
Label l1;
Button b1;
TextField tf1;
String str;
public void init()
{
l1= new Label("Hello");
b1= new Button("Click");
tf1= new TextField(" ",20);

b1.addActionListener(this);
add(l1);
add(tf1);
add(b1);
}
public void actionPerformed(ActionEvent ae)
{
str=tf1.getText();
tf1.setText(" ");
}
public void paint(Graphics g)
{
g.drawString(str,200,200);
}
}


---sap
 
try this
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class ActionListener1 extends Applet implements ActionListener
{
Label l1;
Button b1;
TextField tf1;
String str;
public void init()
{
l1= new Label("Hello");
b1= new Button("Click");
tf1= new TextField(" ",20);

b1.addActionListener(this);
add(l1);
add(tf1);
add(b1);
}
public void actionPerformed(ActionEvent ae)
{
str=tf1.getText();
tf1.setText(" ");
repaint();
}
public void paint(Graphics g)
{
g.drawString(str,200,200);
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top