help me create a java applet in netbeans that ask the user for their first and l
ID: 3834626 • Letter: H
Question
help me create a java applet in netbeans that ask the user for their first and last names and their birth year. After the user enters the requested data and clicks the View Greeting button, the form will change the greeting to show a personalized greeting and the user’s current age.
Class imports:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Calendar;
Form objects:
JLabel greeting
JLabel viewAge
JLabel firstLabel
JTextField txtfirstName
JLabel lastLabel
JTextField txtlastName
JLabel birthLabel
JTextField txtbirthYear
JButton viewGreeting
Form when first opened Applet Viewer: JGreet3 class Applet Greetings! Please enter your first name Please enter your last name: Please enter your four-digit Year of Birth (YYYY) View Greeting Applet started. Form after data entered and View Greeting button clicked Applet Viewer: JGreet .class Applet How are you, John Doe? Your age is 29 years Please enter your first name: John Please enter your last name: Doe Please enter your four-digit Year of Birth (YYYY) 1985 iew Greeting Applet started.Explanation / Answer
import java.applet.*;
import java.awt.Dimemsion;
import java.awt.Font;
import java.awt.event.*;
import java.util.Calendar;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Sample1 extends Applet implements ActionListener
{
Jlabel JTextField,viewAgec,firstLabel,lastLabel,birthLabel;
JTextField txtfirstName,txtlastName,txtbirthYear;
JButton viewGreeting;
piblic void init()
{
JTextField=new JLabel("Greeting");
JTextField.setFont(new Font("Serif",Font.PLAIN,32));
viewAgec=new JLabel(" ");
firstLabel=new JLabel("please enter your first name"):
txtfirstName=new JTextField(" ");
txtfirstName.setPrefferdSize(new Dimension(200,24));
lastLabel=new JLabel("please enter your last name");
txtlastName=new JTextField(" ");
txtlastName.setPrefferdSize(new Dimension(200,24));
birthLabel=new JLabel("please enetr your 4-birth year of birth(YYYY)");
txtbirthYear=new JTextFiled(" ");
txtbirthYear.setPrefferdSize(new Dimension(200,24));
viewGreeting=new JButton("View Greeting");
viewGreeting.addActionListener(this0;
add(JTextField);
add(viewAgec);
add(firstLabel);
add(txtfirstName);
add(lastLabel);
add(txtlatName);
add(birthLabel);
add(txtbirthYear);
add(viewGreeting);
}
public void actionPerformed(ActionEvent e)
{
String firstName=txtfirstName.getText();
String lastName=txtlastName.getText;
int txtbrtyear=Integer.parseInt(txtbirthYear.getText().trim());
JTextField.setText("How are you,"+firstName+""+lastName);
viewAgec.setText("your age is"+(Calendar.getInstance().get(Calendar.YEAR)-txtbrthyear)+"years.");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.