Applet Program Java

Share

Applet Program Java

program in Java using a creative and interactive approach:

java

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

public class InteractiveHelloWorld extends JFrame {
private JLabel messageLabel;

public InteractiveHelloWorld() {
// Set up the JFrame
setTitle(“Interactive Hello World!”);
setSize(300, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);

// Create a label with the initial message
messageLabel = new JLabel(“Click the button below!”);
messageLabel.setFont(new Font(“Arial”, Font.PLAIN, 18));
messageLabel.setHorizontalAlignment(JLabel.CENTER);
add(messageLabel, BorderLayout.CENTER);

// Create a button to change the message
JButton changeButton = new JButton(“Say Hello”);
changeButton.setFont(new Font(“Arial”, Font.PLAIN, 14));
add(changeButton, BorderLayout.SOUTH);

// Add action listener to the button
changeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
messageLabel.setText(“Hello, World!”);
}
});
}

 

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new InteractiveHelloWorld().setVisible(true);
}
});
}
}

In this unique version, instead of a traditional applet, we create an interactive JFrame (window) with a label displaying the message “Click the button below!” initially. There is also a button labeled “Say Hello.” When the button is clicked, the message on the label changes to “Hello, World!”

To run this program, you can directly execute the main() method. A window will pop up with the initial message and the button. When you click the button, the message will change to “Hello, World!”

Demo Day 1 Video:

 
You can find more information about Java in this Java Docs Link

 

Conclusion:

Unogeeks is the No.1 Training Institute for Java Training. Anyone Disagree? Please drop in a comment

You can check out our other latest blogs on Java Training here – Java Blogs

You can check out our Best in Class Java Training details here – Java Training

💬 Follow & Connect with us:

———————————-

For Training inquiries:

Call/Whatsapp: +91 73960 33555

Mail us at: info@unogeeks.com

Our Website ➜ https://unogeeks.com

Follow us:

Instagram: https://www.instagram.com/unogeeks

Facebook: https://www.facebook.com/UnogeeksSoftwareTrainingInstitute

Twitter: https://twitter.com/unogeeks


Share

Leave a Reply

Your email address will not be published. Required fields are marked *