Spread the word.

Share the link on social media.

Share
  • Facebook
Have an account? Sign In Now

Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

SIKSHAPATH

SIKSHAPATH Navigation

  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Shop
    • Internshala Answers
Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Shop
    • Internshala Answers
Home/ Questions/Q 7409
Next
In Process

SIKSHAPATH Latest Questions

Advance Learner
  • 0
  • 0
Advance Learner
Asked: November 21, 20212021-11-21T11:43:05+05:30 2021-11-21T11:43:05+05:30In: Programming Language

Write an AWT GUI application (called AWTCounter). Each time the “Count” button is clicked, the counter value shall increase by 1. …

  • 0
  • 0

Write an AWT GUI application (called AWTCounter).

Each time the “Count” button is clicked, the counter value shall increase by 1.

 

The program has three components:

1.     a java.awt.Label “Counter”;

2.     a non-editable java.awt.TextField to display the counter value; and

3.     a java.awt.Button “Count”.

  • 1 1 Answer
  • 2k Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Answer

    • Voted
    • Oldest
    • Recent
    1. I'M ADMIN
      I'M ADMIN
      2021-11-22T21:43:17+05:30Added an answer on November 22, 2021 at 9:43 pm
      package com.example;
      
      import java.awt.*;         // Using AWT's containers and components
      import java.awt.event.*;   // Using AWT's event classes and listener interfaces
      
      // An AWT GUI program inherits the top-level container java.awt.Frame
      public class AWTCounter extends Frame implements ActionListener {
          private Label lblCount;     // Declare component Label
          private TextField tfCount;  // Declare component TextField
          private Button btnCount;    // Declare component Button
          private int count = 0;      // counter's value
      
          // Constructor to setup UI components and event handlers
          public AWTCounter () {
              setLayout(new FlowLayout());
              // "super" Frame sets layout to FlowLayout, which arranges
              //  Components from left-to-right, then top-to-bottom.
      
              lblCount = new Label("Counter"); // Construct component Label
              add(lblCount);                   // "super" Frame adds Label
      
              tfCount = new TextField(count + "", 10); // Construct component TextField
              tfCount.setEditable(false);       // read-only
              add(tfCount);                     // "super" Frame adds TextField
      
              btnCount = new Button("Count");   // Construct component Button
              add(btnCount);                    // "super" Frame adds Button
              btnCount.addActionListener(this);
              // btnCount is the source object that fires ActionEvent when clicked.
              // The source add "this" instance as an ActionEvent listener, which provides
              //  an ActionEvent handler called actionPerformed().
              // Clicking btnCount invokes actionPerformed().
      
              setSize(250, 100);       // "super" Frame sets initial size
              setTitle("AWT Counter"); // "super" Frame sets title
              setVisible(true);        // show "super" Frame
          }
      
          // ActionEvent handler - Called back when the button is clicked.
          @Override
          public void actionPerformed(ActionEvent evt) {
              ++count;                     // Incrase the counter value
              tfCount.setText(count + ""); // Display on the TextField
              // setText() takes a String
          }
      
          // The entry main() method
          public static void main(String[] args) {
              // Invoke the constructor by allocating an anonymous instance
              new AWTCounter();
          }
      }
      Attachment

        • 1
      • Reply
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    Sidebar

    store ads

    Stats

    • Questions 1k
    • Answers 1k
    • Posts 150
    • Best Answers 89
    • Cloud Computing Notes 101: Learn Fundamentals, Service Models, and Virtualization!
    • This Free AI Tool Translates Entire Books in Minute !
    • AI News: 🎬 Hollywood’s AI Studios, 🎓 OpenAI’s Latest Gift to Educators, 🚚 Class8 Bags $22M, 🧠 Google Gemini’s Memory Upgrade
    • AI NEWS: Legal Action Against OpenAI, $16M Paid, & Elon Musk’s Praise from Investor 🤖💰📑 | AI Boosts Cloud Seeding for Water Security 🌱💧
    • AI News: 🎬AI Video Tool Scam Exposed🤯, 🛰️ AI-Powered Drones to Ukraine 😱, Google’s $20M AI Push, Sam Altman Joins SF’s Leadership Team

    Explore

    • Recent Questions
    • Questions For You
    • Answers With Time
    • Most Visited
    • New Questions
    • Recent Questions With Time

    Footer

    SIKSHAPATH

    Helpful Links

    • Contact
    • Disclaimer
    • Privacy Policy Notice
    • TERMS OF USE
    • FAQs
    • Refund/Cancellation Policy
    • Delivery Policy for Sikshapath

    Follow Us

    © 2021-24 Sikshapath. All Rights Reserved

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.