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

Java Applets

Status
Not open for further replies.

encin0man

Programmer
Nov 24, 2006
4
0
0
US
I haven't used Java in about 5 years but need to create some applets. Basically I need to make 3 text boxes and a button. When the button is pressed, it adds 2 of the numbers in the boxes and outputs the sum to the third. The thing is, I learned all this using "BreezySwing" and I just want to use Swing and Awt this time. I can't really find any good sites that explain this well from the beginning. Can anyone give me some code just to get me started. Its ok, I'm not in any real rush.

Thanks
 
import java.awt.*
import javax.swing.*;
import java.awt.event.*;

public class TheApplet extends JApplet implements ActionListener{
private JTextField tf1,tf2,tf3;
private JButton click;

public void init(){
// initialise the widgets
click.addActionListener(this);
}

public void actionPerformed(ActionEvent e){
if(e.getSource() == click){
int val1=Integer.parseInt(tf1.getText());
int val2=Integer.parseInt(tf2.getText());
int sum=val1 + val2;
tf3.setText("" + sum);
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top