Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help

 
arun iyer
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i wrote the following applet. When i click on enter button, all the components are removed but the new textfields and buttons are not added. i would like to know how to remove the components and add new ones.
----------------
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;
public class admin extends Applet implements ActionListener
{
Font theFont = new Font("TimesRoman",Font.BOLD,14);
Label l0,l1,l2,l3,l5,l6,l7;
TextField t0,t1,t2,t3,t5,t6,t7;
String s0,s1,s2,s3,s5;
static String s6,s7;
Button b1,b2;
int i=0;
public void entry (){
System.out.println("Inside Entry");
setLayout(new GridLayout (11,2));
add(l0);
add(t0);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l5);
add(t5);
add(b1);
b1.addActionListener(this);
repaint();
}
public void init()
{
setBackground(Color.white);
l0 = new Label("Number of Rounds (1-10) :");
l1 = new Label("Questions per Round (1-36) :");
l2 = new Label("Time (In Minutes) :");
l3 = new Label("Review Allowed (True/False):");
l5 = new Label("Minimum Score required :");
l6 = new Label("Login");
l7 = new Label("Password");
t0 = new TextField(10);
t1 = new TextField(10);
t2 = new TextField(10);
t3 = new TextField("True",10);
t5 = new TextField(10);
t6 = new TextField(10);
t7 = new TextField(10);
b1 = new Button("Save");
b2 = new Button("Enter");

//setLayout(new GridLayout (3,2));
add(l6);
add(t6);
add(l7);
add(t7);
t7.setEchoChar('*');
add(b2);
b2.addActionListener(this);
}

public void actionPerformed(ActionEvent e) {
if (e.getSource() ==b2)
{
s6 = t6.getText();
s7 = t7.getText();
System.out.println("Hello");
if (s6.equals("admin") && s7.equals("webaccess"))
{
remove(l6);
remove(t6);
remove(l7);
remove(t7);
remove(b2);
entry();
}
}

if (e.getSource() ==b1)
{
s1 =t1.getText();
s2 =t2.getText();
s3 =t3.getText();
s5 =t5.getText();
s0 =t0.getText();
try{


FileWriter f0 = new FileWriter("c:\\jr\\numofround.txt", false);

f0.write(s0);
f0.close();
FileWriter f1 = new FileWriter("c:\\jr\\questround.txt", false);

f1.write(s1);
f1.close();

FileWriter f2 = new FileWriter("c:\\jr\\time.txt", false);

int num = Integer.parseInt(s2);
num=num-1;
f2.write(String.valueOf(num));
f2.close();

FileWriter f3 = new FileWriter("c:\\jr\\review.txt", false);
if (s3=="true" | | s3=="True")
{
f3.write("1");
f3.close();
}
else {
f3.write("2");
f3.close();
}

FileWriter f5 = new FileWriter("c:\\jr\\tscore.txt", false);

f5.write(s5);
f5.close();

remove(l0);
remove(t0);
remove(l1);
remove(t1);
remove(l2);
remove(t2);
remove(l3);
remove(t3);
remove(l5);
remove(t5);
remove(b1);
i=1;
repaint();
} catch (Exception e1) {}
}
}

public void paint(Graphics g) {
if (i==1)
{
g.setColor(Color.blue);
g.setFont(theFont);
g.drawString("Results Saved",20,20);
}

}
}
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After init you never added any components. In you actionPerformed method after you do all those removes, you have to declare and add the new stuff.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic