Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

applet problem

 
arun iyer
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i add a button b1 with action listener to my applet. in the action performed method, i remove the button b1 and add another button b2.
in applet viewer, on clicking the button b1, b1 gets removed and b2 appears. WHEREAS in broswer(i checked with IE 5.5) on clicking b1.. b1 gets removed but b2 does not get added.
pls help me on this topic regarding the execution of the same code in browser and the appletviewer.

arun iyer
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun,
Could you please post your code? It may have something to do with the way you do repainting, but I cannot be sure without reading your code... It also may be easier (if it is a browser problem and not just a repaint problem) to have one button and just change its label, or have two buttons that are always visible and just using setEnabled() on them when they should change states...
HTH,
-Nate
 
arun iyer
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
thanks for the reply......
expecting a reply soon.
code is as follows:
----------------------------------------------------
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");
Label l0 = new Label("Number of Rounds (1-10) :");
Label l1 = new Label("Questions per Round (1-36) :");
Label l2 = new Label("Time (In Minutes) :");
Label l3 = new Label("Review Allowed (True/False):");
Label l5 = new Label("Minimum Score required :");
TextField t0 = new TextField(10);
TextField t1 = new TextField(10);
TextField t2 = new TextField(10);
TextField t3 = new TextField("True",10);
TextField t5 = new TextField(10);
Button b1 = new Button("Save");
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);
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);
removeAll();
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.equals("true") | | s3.equals("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);
}

}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic