When "ENTER" button in value class clicked the show class wil be run. but nothing happend
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*<applet code ="value" width=200 height=200>
</applet>*/
public class value extends Applet {
private JLabel lab1;
private JButton btn1;
public void init () {
// Construct the TextFields
this.lab1 = new JLabel("Press the button");
this.btn1 = new JButton("ENTER");
// add the button to the layout
this.add(lab1);
this.add(btn1);
transfer tran=new transfer();
btn1.addActionListener(tran);
}
private class transfer implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
show sh = new show();
sh.setVisible(true);
}
}
}
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class show extends Applet {
private JLabel lab2;
private JButton btn2;
private JTextField txt2;
String s1,s2;
public void init () {
// Construct the TextFields
this.lab2 = new JLabel("Enter a number");
this.btn2 = new JButton("DOUBLE");
this.txt2 = new JTextField(20);
this.txt2.setEditable(true);
// add the button to the layout
this.add(lab2);
this.add(txt2);
this.add(btn2);
summation sa = new summation(txt2);
btn2.addActionListener(sa);
this.txt2.addActionListener(sa);
}
private int checkInput(String inString) {
StringBuffer tStringBuf;
int flag=0;
tStringBuf=new StringBuffer(inString);
//check each input character to see if it is a number
for(int index=0; index<tStringBuf.length(); index++){
char ch=tStringBuf.charAt(index);
if( (ch<'0' || ch>'9') && (ch !='.')){
flag=1;
break;
}
}
if(flag==1) return 0;
//not a number input
else return 1; //input is right
}
class summation implements ActionListener {
private JTextField txt3;
public summation(JTextField txt3)
{
this.txt3=txt3;
}
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==btn2)
{
s1=txt3.getText();
int i = Integer.parseInt(s1);
int result=i*2;
s2 = new Integer(result).toString();
txt3.setText(s2);
}
}
}
}